blob: 5e828da2e18f6e9b4ee05e0abab7997b2fe9c6d3 [file] [log] [blame]
Andreas Herrmann23ac4ae2010-09-17 18:03:43 +02001#ifndef _ASM_X86_AMD_NB_H
2#define _ASM_X86_AMD_NB_H
Andi Kleena32073b2006-06-26 13:56:40 +02003
Bjorn Helgaas24d25db2012-01-05 14:27:19 -07004#include <linux/ioport.h>
Andi Kleena32073b2006-06-26 13:56:40 +02005#include <linux/pci.h>
6
Jan Beulich24d9b702011-01-10 16:20:23 +00007struct amd_nb_bus_dev_range {
8 u8 bus;
9 u8 dev_base;
10 u8 dev_limit;
11};
12
Jan Beulich691269f2011-02-09 08:26:53 +000013extern const struct pci_device_id amd_nb_misc_ids[];
Jan Beulich24d9b702011-01-10 16:20:23 +000014extern const struct amd_nb_bus_dev_range amd_nb_bus_dev_ranges[];
Andi Kleena32073b2006-06-26 13:56:40 +020015
Borislav Petkov84fd1d32011-03-03 12:59:32 +010016extern bool early_is_amd_nb(u32 value);
Bjorn Helgaas24d25db2012-01-05 14:27:19 -070017extern struct resource *amd_get_mmconfig_range(struct resource *res);
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +020018extern int amd_cache_northbridges(void);
Hans Rosenfeldeec1d4f2010-10-29 17:14:30 +020019extern void amd_flush_garts(void);
Tejun Heo940fed22011-02-16 12:13:06 +010020extern int amd_numa_init(void);
Hans Rosenfeldcabb5bd2011-02-07 18:10:39 +010021extern int amd_get_subcaches(int);
Dan Carpenter2993ae32014-01-21 10:22:09 +030022extern int amd_set_subcaches(int, unsigned long);
Andi Kleena32073b2006-06-26 13:56:40 +020023
Thomas Gleixnerd2946042011-07-24 09:46:09 +000024struct amd_l3_cache {
25 unsigned indices;
26 u8 subcaches[4];
27};
28
Borislav Petkov019f34f2012-05-02 17:16:59 +020029struct threshold_block {
Aravind Gopalakrishnanea2ca362016-03-07 14:02:21 +010030 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 Petkov019f34f2012-05-02 17:16:59 +020047};
48
49struct 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 Rosenfeld9653a5c2010-10-29 17:14:31 +020057struct amd_northbridge {
58 struct pci_dev *misc;
Hans Rosenfeld41b26102011-01-24 16:05:42 +010059 struct pci_dev *link;
Thomas Gleixnerd2946042011-07-24 09:46:09 +000060 struct amd_l3_cache l3_cache;
Borislav Petkov019f34f2012-05-02 17:16:59 +020061 struct threshold_bank *bank4;
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +020062};
63
Hans Rosenfeldeec1d4f2010-10-29 17:14:30 +020064struct amd_northbridge_info {
Andreas Herrmann900f9ac2010-09-17 18:02:54 +020065 u16 num;
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +020066 u64 flags;
67 struct amd_northbridge *nb;
Andreas Herrmann900f9ac2010-09-17 18:02:54 +020068};
Hans Rosenfeldeec1d4f2010-10-29 17:14:30 +020069extern struct amd_northbridge_info amd_northbridges;
Andreas Herrmann900f9ac2010-09-17 18:02:54 +020070
Borislav Petkov84fd1d32011-03-03 12:59:32 +010071#define AMD_NB_GART BIT(0)
72#define AMD_NB_L3_INDEX_DISABLE BIT(1)
73#define AMD_NB_L3_PARTITIONING BIT(2)
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +020074
Andreas Herrmann23ac4ae2010-09-17 18:03:43 +020075#ifdef CONFIG_AMD_NB
Borislav Petkovade029e2010-04-24 09:56:53 +020076
Borislav Petkov84fd1d32011-03-03 12:59:32 +010077static inline u16 amd_nb_num(void)
Jaswinder Singh Rajputb2065252009-04-14 23:04:37 +053078{
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +020079 return amd_northbridges.num;
80}
81
Borislav Petkov84fd1d32011-03-03 12:59:32 +010082static inline bool amd_nb_has_feature(unsigned feature)
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +020083{
84 return ((amd_northbridges.flags & feature) == feature);
85}
86
87static inline struct amd_northbridge *node_to_amd_nb(int node)
88{
89 return (node < amd_northbridges.num) ? &amd_northbridges.nb[node] : NULL;
Jaswinder Singh Rajputb2065252009-04-14 23:04:37 +053090}
Borislav Petkovade029e2010-04-24 09:56:53 +020091
Aravind Gopalakrishnan1a6775c2015-10-19 11:17:42 +020092static inline u16 amd_pci_dev_to_node_id(struct pci_dev *pdev)
Daniel J Blueman772c3ff2012-11-27 14:32:09 +080093{
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 Gopalakrishnan1b457422015-04-07 16:46:37 -0500109static 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 Herrmannafd9fce2009-04-09 15:16:17 +0200119#else
Borislav Petkovade029e2010-04-24 09:56:53 +0200120
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +0200121#define amd_nb_num(x) 0
122#define amd_nb_has_feature(x) false
123#define node_to_amd_nb(x) NULL
Aravind Gopalakrishnan1b457422015-04-07 16:46:37 -0500124#define amd_gart_present(x) false
Hans Rosenfeld9653a5c2010-10-29 17:14:31 +0200125
Andreas Herrmannafd9fce2009-04-09 15:16:17 +0200126#endif
127
128
Andreas Herrmann23ac4ae2010-09-17 18:03:43 +0200129#endif /* _ASM_X86_AMD_NB_H */