Ignore:
Timestamp:
2024-02-23T17:57:23Z (11 months ago)
Author:
GitHub <noreply@…>
Children:
192019f
Parents:
86f862c (diff), 90ba06c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2024-02-23 17:57:23)
git-committer:
GitHub <noreply@…> (2024-02-23 17:57:23)
Message:

Merge branch 'HelenOS:master' into topic/packet-capture

File:
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/arch/mm/pat.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
     2 * Copyright (c) 2024 Jiří Zárevúcky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libcamd64
     29/** @addtogroup kernel_amd64_mm
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef _LIBC_STACKARG_H_
    36 #define _LIBC_STACKARG_H_
     35#ifndef KERN_amd64_MM_PAT_H_
     36#define KERN_amd64_MM_PAT_H_
     37
     38#include <arch/asm.h>
     39#include <arch/cpuid.h>
     40
     41#define MSR_IA32_PAT  0x00000277
     42
     43typedef enum {
     44        PAT_TYPE_UNCACHEABLE = 0,
     45        PAT_TYPE_WRITE_COMBINING = 1,
     46        PAT_TYPE_WRITE_THROUGH = 4,
     47        PAT_TYPE_WRITE_PROTECTED = 5,
     48        PAT_TYPE_WRITE_BACK = 6,
     49        PAT_TYPE_UNCACHED  = 7,
     50} pat_type_t;
     51
     52/**
     53 * Assign caching type for a particular combination of PAT,
     54 * PCD and PWT bits in PTE.
     55 */
     56static inline void pat_set_mapping(bool pat, bool pcd, bool pwt,
     57    pat_type_t type)
     58{
     59        int index = pat << 2 | pcd << 1 | pwt;
     60        int shift = index * 8;
     61
     62        uint64_t r = read_msr(MSR_IA32_PAT);
     63        r &= ~(0xffull << shift);
     64        r |= ((uint64_t) type) << shift;
     65        write_msr(MSR_IA32_PAT, r);
     66}
     67
     68static inline bool pat_supported(void)
     69{
     70        if (!has_cpuid())
     71                return false;
     72
     73        cpu_info_t info;
     74        cpuid(INTEL_CPUID_STANDARD, &info);
     75
     76        return (info.cpuid_edx & (1 << 16)) != 0;
     77}
    3778
    3879#endif
Note: See TracChangeset for help on using the changeset viewer.