arch/x86/kernel/cpu/amd_cache_disable.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/amd_cache_disable.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/amd_cache_disable.c- Extension
.c- Size
- 7071 bytes
- Lines
- 302
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cacheinfo.hlinux/capability.hlinux/pci.hlinux/sysfs.hasm/amd/nb.hcpu.h
Detected Declarations
function amd_calc_l3_indicesfunction amd_get_l3_disable_slotfunction show_cache_disablefunction amd_l3_disable_indexfunction amd_set_l3_disable_slotfunction store_cache_disablefunction subcaches_showfunction subcaches_storefunction cache_private_attrs_is_visiblefunction init_amd_l3_attrs
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* AMD L3 cache_disable_{0,1} sysfs handling
* Documentation/ABI/testing/sysfs-devices-system-cpu
*/
#include <linux/cacheinfo.h>
#include <linux/capability.h>
#include <linux/pci.h>
#include <linux/sysfs.h>
#include <asm/amd/nb.h>
#include "cpu.h"
/*
* L3 cache descriptors
*/
static void amd_calc_l3_indices(struct amd_northbridge *nb)
{
struct amd_l3_cache *l3 = &nb->l3_cache;
unsigned int sc0, sc1, sc2, sc3;
u32 val = 0;
pci_read_config_dword(nb->misc, 0x1C4, &val);
/* calculate subcache sizes */
l3->subcaches[0] = sc0 = !(val & BIT(0));
l3->subcaches[1] = sc1 = !(val & BIT(4));
if (boot_cpu_data.x86 == 0x15) {
l3->subcaches[0] = sc0 += !(val & BIT(1));
l3->subcaches[1] = sc1 += !(val & BIT(5));
}
l3->subcaches[2] = sc2 = !(val & BIT(8)) + !(val & BIT(9));
l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13));
l3->indices = (max(max3(sc0, sc1, sc2), sc3) << 10) - 1;
}
/*
* check whether a slot used for disabling an L3 index is occupied.
* @l3: L3 cache descriptor
* @slot: slot number (0..1)
*
* @returns: the disabled index if used or negative value if slot free.
*/
static int amd_get_l3_disable_slot(struct amd_northbridge *nb, unsigned int slot)
{
unsigned int reg = 0;
pci_read_config_dword(nb->misc, 0x1BC + slot * 4, ®);
/* check whether this slot is activated already */
if (reg & (3UL << 30))
return reg & 0xfff;
return -1;
}
static ssize_t show_cache_disable(struct cacheinfo *ci, char *buf, unsigned int slot)
{
int index;
struct amd_northbridge *nb = ci->priv;
index = amd_get_l3_disable_slot(nb, slot);
if (index >= 0)
return sysfs_emit(buf, "%d\n", index);
return sysfs_emit(buf, "FREE\n");
}
#define SHOW_CACHE_DISABLE(slot) \
static ssize_t \
cache_disable_##slot##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
struct cacheinfo *ci = dev_get_drvdata(dev); \
return show_cache_disable(ci, buf, slot); \
}
SHOW_CACHE_DISABLE(0)
SHOW_CACHE_DISABLE(1)
static void amd_l3_disable_index(struct amd_northbridge *nb, int cpu,
unsigned int slot, unsigned long idx)
{
int i;
Annotation
- Immediate include surface: `linux/cacheinfo.h`, `linux/capability.h`, `linux/pci.h`, `linux/sysfs.h`, `asm/amd/nb.h`, `cpu.h`.
- Detected declarations: `function amd_calc_l3_indices`, `function amd_get_l3_disable_slot`, `function show_cache_disable`, `function amd_l3_disable_index`, `function amd_set_l3_disable_slot`, `function store_cache_disable`, `function subcaches_show`, `function subcaches_store`, `function cache_private_attrs_is_visible`, `function init_amd_l3_attrs`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.