Lines Matching +full:root +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * AMD Node helper functions and common defines
12 #include <asm/amd/node.h>
18 * The nodes are software-visible through PCI config space. All nodes are enumerated
20 * nodes) with 0x18 corresponding to node 0, 0x19 to node 1, etc. Each node can be a
21 * multi-function device.
23 * On legacy systems, these node devices represent integrated Northbridge functionality.
24 * On Zen-based systems, these node devices represent Data Fabric functionality.
27 * "Processor x86 Core" -> "Configuration Space" section in PPRs.
29 struct pci_dev *amd_node_get_func(u16 node, u8 func) in amd_node_get_func() argument
31 if (node >= MAX_AMD_NUM_NODES) in amd_node_get_func()
34 return pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(AMD_NODE0_PCI_SLOT + node, func)); in amd_node_get_func()
54 * For SMN reads, the returned value may be zero if the register is Read-as-Zero.
58 * But the Read-as-Zero response cannot be verified here. A value of 0 may be
67 * 1) Bits that are "Write-1-to-Clear". In this case, the read value should
70 * 2) Bits that are "Read-as-Zero"/"Writes-Ignored". This information cannot be
86 static int __amd_smn_rw(u8 i_off, u8 d_off, u16 node, u32 address, u32 *value, bool write) in __amd_smn_rw() argument
88 struct pci_dev *root; in __amd_smn_rw() local
89 int err = -ENODEV; in __amd_smn_rw()
91 if (node >= amd_num_nodes()) in __amd_smn_rw()
94 root = amd_roots[node]; in __amd_smn_rw()
95 if (!root) in __amd_smn_rw()
103 err = pci_write_config_dword(root, i_off, address); in __amd_smn_rw()
109 err = (write ? pci_write_config_dword(root, d_off, *value) in __amd_smn_rw()
110 : pci_read_config_dword(root, d_off, value)); in __amd_smn_rw()
115 int __must_check amd_smn_read(u16 node, u32 address, u32 *value) in amd_smn_read() argument
117 int err = __amd_smn_rw(SMN_INDEX_OFFSET, SMN_DATA_OFFSET, node, address, value, false); in amd_smn_read()
120 err = -ENODEV; in amd_smn_read()
128 int __must_check amd_smn_write(u16 node, u32 address, u32 value) in amd_smn_write() argument
130 return __amd_smn_rw(SMN_INDEX_OFFSET, SMN_DATA_OFFSET, node, address, &value, true); in amd_smn_write()
134 int __must_check amd_smn_hsmp_rdwr(u16 node, u32 address, u32 *value, bool write) in amd_smn_hsmp_rdwr() argument
136 return __amd_smn_rw(HSMP_INDEX_OFFSET, HSMP_DATA_OFFSET, node, address, value, write); in amd_smn_hsmp_rdwr()
147 u16 node; in smn_node_write() local
150 ret = kstrtou16_from_user(userbuf, count, 0, &node); in smn_node_write()
154 if (node >= amd_num_nodes()) in smn_node_write()
155 return -ENODEV; in smn_node_write()
157 debug_node = node; in smn_node_write()
221 static struct pci_dev *get_next_root(struct pci_dev *root) in get_next_root() argument
223 while ((root = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, root))) { in get_next_root()
224 /* Root device is Device 0 Function 0. */ in get_next_root()
225 if (root->devfn) in get_next_root()
228 if (root->vendor != PCI_VENDOR_ID_AMD && in get_next_root()
229 root->vendor != PCI_VENDOR_ID_HYGON) in get_next_root()
235 return root; in get_next_root()
249 u16 count, num_roots, roots_per_node, node, num_nodes; in amd_smn_init() local
250 struct pci_dev *root; in amd_smn_init() local
261 root = NULL; in amd_smn_init()
262 while ((root = get_next_root(root))) { in amd_smn_init()
263 pci_dbg(root, "Reserving PCI config space\n"); in amd_smn_init()
271 if (!pci_request_config_region_exclusive(root, 0, PCI_CFG_SPACE_SIZE, NULL)) { in amd_smn_init()
272 pci_err(root, "Failed to reserve config space\n"); in amd_smn_init()
273 return -EEXIST; in amd_smn_init()
279 pr_debug("Found %d AMD root devices\n", num_roots); in amd_smn_init()
282 return -ENODEV; in amd_smn_init()
287 return -ENOMEM; in amd_smn_init()
292 node = 0; in amd_smn_init()
293 root = NULL; in amd_smn_init()
294 while (node < num_nodes && (root = get_next_root(root))) { in amd_smn_init()
295 /* Use one root for each node and skip the rest. */ in amd_smn_init()
299 pci_dbg(root, "is root for AMD node %u\n", node); in amd_smn_init()
300 amd_roots[node++] = root; in amd_smn_init()
306 debugfs_create_file("node", 0600, debugfs_dir, NULL, &smn_node_fops); in amd_smn_init()