1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* |
3 | * AMD Node helper functions and common defines |
4 | * |
5 | * Copyright (c) 2024, Advanced Micro Devices, Inc. |
6 | * All Rights Reserved. |
7 | * |
8 | * Author: Yazen Ghannam <Yazen.Ghannam@amd.com> |
9 | * |
10 | * Note: |
11 | * Items in this file may only be used in a single place. |
12 | * However, it's prudent to keep all AMD Node functionality |
13 | * in a unified place rather than spreading throughout the |
14 | * kernel. |
15 | */ |
16 | |
17 | #ifndef _ASM_X86_AMD_NODE_H_ |
18 | #define _ASM_X86_AMD_NODE_H_ |
19 | |
20 | #include <linux/pci.h> |
21 | |
22 | #define MAX_AMD_NUM_NODES 8 |
23 | #define AMD_NODE0_PCI_SLOT 0x18 |
24 | |
25 | struct pci_dev *amd_node_get_func(u16 node, u8 func); |
26 | struct pci_dev *amd_node_get_root(u16 node); |
27 | |
28 | static inline u16 amd_num_nodes(void) |
29 | { |
30 | return topology_amd_nodes_per_pkg() * topology_max_packages(); |
31 | } |
32 | |
33 | #ifdef CONFIG_AMD_NODE |
34 | int __must_check amd_smn_read(u16 node, u32 address, u32 *value); |
35 | int __must_check amd_smn_write(u16 node, u32 address, u32 value); |
36 | |
37 | /* Should only be used by the HSMP driver. */ |
38 | int __must_check amd_smn_hsmp_rdwr(u16 node, u32 address, u32 *value, bool write); |
39 | #else |
40 | static inline int __must_check amd_smn_read(u16 node, u32 address, u32 *value) { return -ENODEV; } |
41 | static inline int __must_check amd_smn_write(u16 node, u32 address, u32 value) { return -ENODEV; } |
42 | |
43 | static inline int __must_check amd_smn_hsmp_rdwr(u16 node, u32 address, u32 *value, bool write) |
44 | { |
45 | return -ENODEV; |
46 | } |
47 | #endif /* CONFIG_AMD_NODE */ |
48 | |
49 | /* helper for use with read_poll_timeout */ |
50 | static inline int smn_read_register(u32 reg) |
51 | { |
52 | int data, rc; |
53 | |
54 | rc = amd_smn_read(node: 0, address: reg, value: &data); |
55 | if (rc) |
56 | return rc; |
57 | |
58 | return data; |
59 | } |
60 | #endif /*_ASM_X86_AMD_NODE_H_*/ |
61 | |