amd_nb.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_AMD_NB_H
  3. #define _ASM_X86_AMD_NB_H
  4. #include <linux/ioport.h>
  5. #include <linux/pci.h>
  6. #include <linux/refcount.h>
  7. struct amd_nb_bus_dev_range {
  8. u8 bus;
  9. u8 dev_base;
  10. u8 dev_limit;
  11. };
  12. extern const struct amd_nb_bus_dev_range amd_nb_bus_dev_ranges[];
  13. extern bool early_is_amd_nb(u32 value);
  14. extern struct resource *amd_get_mmconfig_range(struct resource *res);
  15. extern void amd_flush_garts(void);
  16. extern int amd_numa_init(void);
  17. extern int amd_get_subcaches(int);
  18. extern int amd_set_subcaches(int, unsigned long);
  19. extern int amd_smn_read(u16 node, u32 address, u32 *value);
  20. extern int amd_smn_write(u16 node, u32 address, u32 value);
  21. struct amd_l3_cache {
  22. unsigned indices;
  23. u8 subcaches[4];
  24. };
  25. struct threshold_block {
  26. unsigned int block; /* Number within bank */
  27. unsigned int bank; /* MCA bank the block belongs to */
  28. unsigned int cpu; /* CPU which controls MCA bank */
  29. u32 address; /* MSR address for the block */
  30. u16 interrupt_enable; /* Enable/Disable APIC interrupt */
  31. bool interrupt_capable; /* Bank can generate an interrupt. */
  32. u16 threshold_limit; /*
  33. * Value upon which threshold
  34. * interrupt is generated.
  35. */
  36. struct kobject kobj; /* sysfs object */
  37. struct list_head miscj; /*
  38. * List of threshold blocks
  39. * within a bank.
  40. */
  41. };
  42. struct threshold_bank {
  43. struct kobject *kobj;
  44. struct threshold_block *blocks;
  45. /* initialized to the number of CPUs on the node sharing this bank */
  46. refcount_t cpus;
  47. unsigned int shared;
  48. };
  49. struct amd_northbridge {
  50. struct pci_dev *root;
  51. struct pci_dev *misc;
  52. struct pci_dev *link;
  53. struct amd_l3_cache l3_cache;
  54. struct threshold_bank *bank4;
  55. };
  56. struct amd_northbridge_info {
  57. u16 num;
  58. u64 flags;
  59. struct amd_northbridge *nb;
  60. };
  61. #define AMD_NB_GART BIT(0)
  62. #define AMD_NB_L3_INDEX_DISABLE BIT(1)
  63. #define AMD_NB_L3_PARTITIONING BIT(2)
  64. #ifdef CONFIG_AMD_NB
  65. u16 amd_nb_num(void);
  66. bool amd_nb_has_feature(unsigned int feature);
  67. struct amd_northbridge *node_to_amd_nb(int node);
  68. static inline u16 amd_pci_dev_to_node_id(struct pci_dev *pdev)
  69. {
  70. struct pci_dev *misc;
  71. int i;
  72. for (i = 0; i != amd_nb_num(); i++) {
  73. misc = node_to_amd_nb(i)->misc;
  74. if (pci_domain_nr(misc->bus) == pci_domain_nr(pdev->bus) &&
  75. PCI_SLOT(misc->devfn) == PCI_SLOT(pdev->devfn))
  76. return i;
  77. }
  78. WARN(1, "Unable to find AMD Northbridge id for %s\n", pci_name(pdev));
  79. return 0;
  80. }
  81. static inline bool amd_gart_present(void)
  82. {
  83. if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
  84. return false;
  85. /* GART present only on Fam15h, upto model 0fh */
  86. if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10 ||
  87. (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model < 0x10))
  88. return true;
  89. return false;
  90. }
  91. #else
  92. #define amd_nb_num(x) 0
  93. #define amd_nb_has_feature(x) false
  94. #define node_to_amd_nb(x) NULL
  95. #define amd_gart_present(x) false
  96. #endif
  97. #endif /* _ASM_X86_AMD_NB_H */