Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 1 | #ifndef _ASM_X86_AMD_NB_H |
| 2 | #define _ASM_X86_AMD_NB_H |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 3 | |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 4 | #include <linux/ioport.h> |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 5 | #include <linux/pci.h> |
| 6 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 7 | struct amd_nb_bus_dev_range { |
| 8 | u8 bus; |
| 9 | u8 dev_base; |
| 10 | u8 dev_limit; |
| 11 | }; |
| 12 | |
Jan Beulich | 691269f | 2011-02-09 08:26:53 +0000 | [diff] [blame] | 13 | extern const struct pci_device_id amd_nb_misc_ids[]; |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 14 | extern const struct amd_nb_bus_dev_range amd_nb_bus_dev_ranges[]; |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 15 | |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 16 | extern bool early_is_amd_nb(u32 value); |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 17 | extern struct resource *amd_get_mmconfig_range(struct resource *res); |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 18 | extern int amd_cache_northbridges(void); |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 19 | extern void amd_flush_garts(void); |
Tejun Heo | 940fed2 | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 20 | extern int amd_numa_init(void); |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 21 | extern int amd_get_subcaches(int); |
Dan Carpenter | 2993ae3 | 2014-01-21 10:22:09 +0300 | [diff] [blame] | 22 | extern int amd_set_subcaches(int, unsigned long); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 23 | |
Thomas Gleixner | d294604 | 2011-07-24 09:46:09 +0000 | [diff] [blame] | 24 | struct amd_l3_cache { |
| 25 | unsigned indices; |
| 26 | u8 subcaches[4]; |
| 27 | }; |
| 28 | |
Borislav Petkov | 019f34f | 2012-05-02 17:16:59 +0200 | [diff] [blame] | 29 | struct threshold_block { |
Aravind Gopalakrishnan | ea2ca36 | 2016-03-07 14:02:21 +0100 | [diff] [blame] | 30 | unsigned int block; /* Number within bank */ |
| 31 | unsigned int bank; /* MCA bank the block belongs to */ |
| 32 | unsigned int cpu; /* CPU which controls MCA bank */ |
| 33 | u32 address; /* MSR address for the block */ |
| 34 | u16 interrupt_enable; /* Enable/Disable APIC interrupt */ |
| 35 | bool interrupt_capable; /* Bank can generate an interrupt. */ |
| 36 | |
| 37 | u16 threshold_limit; /* |
| 38 | * Value upon which threshold |
| 39 | * interrupt is generated. |
| 40 | */ |
| 41 | |
| 42 | struct kobject kobj; /* sysfs object */ |
| 43 | struct list_head miscj; /* |
| 44 | * List of threshold blocks |
| 45 | * within a bank. |
| 46 | */ |
Borislav Petkov | 019f34f | 2012-05-02 17:16:59 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | struct threshold_bank { |
| 50 | struct kobject *kobj; |
| 51 | struct threshold_block *blocks; |
| 52 | |
| 53 | /* initialized to the number of CPUs on the node sharing this bank */ |
| 54 | atomic_t cpus; |
| 55 | }; |
| 56 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 57 | struct amd_northbridge { |
| 58 | struct pci_dev *misc; |
Hans Rosenfeld | 41b2610 | 2011-01-24 16:05:42 +0100 | [diff] [blame] | 59 | struct pci_dev *link; |
Thomas Gleixner | d294604 | 2011-07-24 09:46:09 +0000 | [diff] [blame] | 60 | struct amd_l3_cache l3_cache; |
Borislav Petkov | 019f34f | 2012-05-02 17:16:59 +0200 | [diff] [blame] | 61 | struct threshold_bank *bank4; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 64 | struct amd_northbridge_info { |
Andreas Herrmann | 900f9ac | 2010-09-17 18:02:54 +0200 | [diff] [blame] | 65 | u16 num; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 66 | u64 flags; |
| 67 | struct amd_northbridge *nb; |
Andreas Herrmann | 900f9ac | 2010-09-17 18:02:54 +0200 | [diff] [blame] | 68 | }; |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 69 | extern struct amd_northbridge_info amd_northbridges; |
Andreas Herrmann | 900f9ac | 2010-09-17 18:02:54 +0200 | [diff] [blame] | 70 | |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 71 | #define AMD_NB_GART BIT(0) |
| 72 | #define AMD_NB_L3_INDEX_DISABLE BIT(1) |
| 73 | #define AMD_NB_L3_PARTITIONING BIT(2) |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 74 | |
Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_AMD_NB |
Borislav Petkov | ade029e | 2010-04-24 09:56:53 +0200 | [diff] [blame] | 76 | |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 77 | static inline u16 amd_nb_num(void) |
Jaswinder Singh Rajput | b206525 | 2009-04-14 23:04:37 +0530 | [diff] [blame] | 78 | { |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 79 | return amd_northbridges.num; |
| 80 | } |
| 81 | |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 82 | static inline bool amd_nb_has_feature(unsigned feature) |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 83 | { |
| 84 | return ((amd_northbridges.flags & feature) == feature); |
| 85 | } |
| 86 | |
| 87 | static inline struct amd_northbridge *node_to_amd_nb(int node) |
| 88 | { |
| 89 | return (node < amd_northbridges.num) ? &amd_northbridges.nb[node] : NULL; |
Jaswinder Singh Rajput | b206525 | 2009-04-14 23:04:37 +0530 | [diff] [blame] | 90 | } |
Borislav Petkov | ade029e | 2010-04-24 09:56:53 +0200 | [diff] [blame] | 91 | |
Aravind Gopalakrishnan | 1a6775c | 2015-10-19 11:17:42 +0200 | [diff] [blame] | 92 | static inline u16 amd_pci_dev_to_node_id(struct pci_dev *pdev) |
Daniel J Blueman | 772c3ff | 2012-11-27 14:32:09 +0800 | [diff] [blame] | 93 | { |
| 94 | struct pci_dev *misc; |
| 95 | int i; |
| 96 | |
| 97 | for (i = 0; i != amd_nb_num(); i++) { |
| 98 | misc = node_to_amd_nb(i)->misc; |
| 99 | |
| 100 | if (pci_domain_nr(misc->bus) == pci_domain_nr(pdev->bus) && |
| 101 | PCI_SLOT(misc->devfn) == PCI_SLOT(pdev->devfn)) |
| 102 | return i; |
| 103 | } |
| 104 | |
| 105 | WARN(1, "Unable to find AMD Northbridge id for %s\n", pci_name(pdev)); |
| 106 | return 0; |
| 107 | } |
| 108 | |
Aravind Gopalakrishnan | 1b45742 | 2015-04-07 16:46:37 -0500 | [diff] [blame] | 109 | static inline bool amd_gart_present(void) |
| 110 | { |
| 111 | /* GART present only on Fam15h, upto model 0fh */ |
| 112 | if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 || |
| 113 | (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10)) |
| 114 | return true; |
| 115 | |
| 116 | return false; |
| 117 | } |
| 118 | |
Andreas Herrmann | afd9fce | 2009-04-09 15:16:17 +0200 | [diff] [blame] | 119 | #else |
Borislav Petkov | ade029e | 2010-04-24 09:56:53 +0200 | [diff] [blame] | 120 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 121 | #define amd_nb_num(x) 0 |
| 122 | #define amd_nb_has_feature(x) false |
| 123 | #define node_to_amd_nb(x) NULL |
Aravind Gopalakrishnan | 1b45742 | 2015-04-07 16:46:37 -0500 | [diff] [blame] | 124 | #define amd_gart_present(x) false |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 125 | |
Andreas Herrmann | afd9fce | 2009-04-09 15:16:17 +0200 | [diff] [blame] | 126 | #endif |
| 127 | |
| 128 | |
Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 129 | #endif /* _ASM_X86_AMD_NB_H */ |