pci_x86.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Low-Level PCI Access for i386 machines.
  4. *
  5. * (c) 1999 Martin Mares <[email protected]>
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/init.h>
  9. #include <linux/ioport.h>
  10. #include <linux/spinlock.h>
  11. #undef DEBUG
  12. #ifdef DEBUG
  13. #define DBG(fmt, ...) printk(fmt, ##__VA_ARGS__)
  14. #else
  15. #define DBG(fmt, ...) \
  16. do { \
  17. if (0) \
  18. printk(fmt, ##__VA_ARGS__); \
  19. } while (0)
  20. #endif
  21. #define PCI_PROBE_BIOS 0x0001
  22. #define PCI_PROBE_CONF1 0x0002
  23. #define PCI_PROBE_CONF2 0x0004
  24. #define PCI_PROBE_MMCONF 0x0008
  25. #define PCI_PROBE_MASK 0x000f
  26. #define PCI_PROBE_NOEARLY 0x0010
  27. #define PCI_NO_CHECKS 0x0400
  28. #define PCI_USE_PIRQ_MASK 0x0800
  29. #define PCI_ASSIGN_ROMS 0x1000
  30. #define PCI_BIOS_IRQ_SCAN 0x2000
  31. #define PCI_ASSIGN_ALL_BUSSES 0x4000
  32. #define PCI_CAN_SKIP_ISA_ALIGN 0x8000
  33. #define PCI_USE__CRS 0x10000
  34. #define PCI_CHECK_ENABLE_AMD_MMCONF 0x20000
  35. #define PCI_HAS_IO_ECS 0x40000
  36. #define PCI_NOASSIGN_ROMS 0x80000
  37. #define PCI_ROOT_NO_CRS 0x100000
  38. #define PCI_NOASSIGN_BARS 0x200000
  39. #define PCI_BIG_ROOT_WINDOW 0x400000
  40. #define PCI_USE_E820 0x800000
  41. #define PCI_NO_E820 0x1000000
  42. extern unsigned int pci_probe;
  43. extern unsigned long pirq_table_addr;
  44. enum pci_bf_sort_state {
  45. pci_bf_sort_default,
  46. pci_force_nobf,
  47. pci_force_bf,
  48. pci_dmi_bf,
  49. };
  50. /* pci-i386.c */
  51. void pcibios_resource_survey(void);
  52. void pcibios_set_cache_line_size(void);
  53. /* pci-pc.c */
  54. extern int pcibios_last_bus;
  55. extern struct pci_ops pci_root_ops;
  56. void pcibios_scan_specific_bus(int busn);
  57. /* pci-irq.c */
  58. struct pci_dev;
  59. struct irq_info {
  60. u8 bus, devfn; /* Bus, device and function */
  61. struct {
  62. u8 link; /* IRQ line ID, chipset dependent,
  63. 0 = not routed */
  64. u16 bitmap; /* Available IRQs */
  65. } __attribute__((packed)) irq[4];
  66. u8 slot; /* Slot number, 0=onboard */
  67. u8 rfu;
  68. } __attribute__((packed));
  69. struct irq_routing_table {
  70. u32 signature; /* PIRQ_SIGNATURE should be here */
  71. u16 version; /* PIRQ_VERSION */
  72. u16 size; /* Table size in bytes */
  73. u8 rtr_bus, rtr_devfn; /* Where the interrupt router lies */
  74. u16 exclusive_irqs; /* IRQs devoted exclusively to
  75. PCI usage */
  76. u16 rtr_vendor, rtr_device; /* Vendor and device ID of
  77. interrupt router */
  78. u32 miniport_data; /* Crap */
  79. u8 rfu[11];
  80. u8 checksum; /* Modulo 256 checksum must give 0 */
  81. struct irq_info slots[];
  82. } __attribute__((packed));
  83. struct irt_routing_table {
  84. u32 signature; /* IRT_SIGNATURE should be here */
  85. u8 size; /* Number of entries provided */
  86. u8 used; /* Number of entries actually used */
  87. u16 exclusive_irqs; /* IRQs devoted exclusively to
  88. PCI usage */
  89. struct irq_info slots[];
  90. } __attribute__((packed));
  91. extern unsigned int pcibios_irq_mask;
  92. extern raw_spinlock_t pci_config_lock;
  93. extern int (*pcibios_enable_irq)(struct pci_dev *dev);
  94. extern void (*pcibios_disable_irq)(struct pci_dev *dev);
  95. extern bool mp_should_keep_irq(struct device *dev);
  96. struct pci_raw_ops {
  97. int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
  98. int reg, int len, u32 *val);
  99. int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
  100. int reg, int len, u32 val);
  101. };
  102. extern const struct pci_raw_ops *raw_pci_ops;
  103. extern const struct pci_raw_ops *raw_pci_ext_ops;
  104. extern const struct pci_raw_ops pci_mmcfg;
  105. extern const struct pci_raw_ops pci_direct_conf1;
  106. extern bool port_cf9_safe;
  107. /* arch_initcall level */
  108. #ifdef CONFIG_PCI_DIRECT
  109. extern int pci_direct_probe(void);
  110. extern void pci_direct_init(int type);
  111. #else
  112. static inline int pci_direct_probe(void) { return -1; }
  113. static inline void pci_direct_init(int type) { }
  114. #endif
  115. #ifdef CONFIG_PCI_BIOS
  116. extern void pci_pcbios_init(void);
  117. #else
  118. static inline void pci_pcbios_init(void) { }
  119. #endif
  120. extern void __init dmi_check_pciprobe(void);
  121. extern void __init dmi_check_skip_isa_align(void);
  122. /* some common used subsys_initcalls */
  123. #ifdef CONFIG_PCI
  124. extern int __init pci_acpi_init(void);
  125. #else
  126. static inline int __init pci_acpi_init(void)
  127. {
  128. return -EINVAL;
  129. }
  130. #endif
  131. extern void __init pcibios_irq_init(void);
  132. extern int __init pcibios_init(void);
  133. extern int pci_legacy_init(void);
  134. extern void pcibios_fixup_irqs(void);
  135. /* pci-mmconfig.c */
  136. /* "PCI MMCONFIG %04x [bus %02x-%02x]" */
  137. #define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2)
  138. struct pci_mmcfg_region {
  139. struct list_head list;
  140. struct resource res;
  141. u64 address;
  142. char __iomem *virt;
  143. u16 segment;
  144. u8 start_bus;
  145. u8 end_bus;
  146. char name[PCI_MMCFG_RESOURCE_NAME_LEN];
  147. };
  148. extern int __init pci_mmcfg_arch_init(void);
  149. extern void __init pci_mmcfg_arch_free(void);
  150. extern int pci_mmcfg_arch_map(struct pci_mmcfg_region *cfg);
  151. extern void pci_mmcfg_arch_unmap(struct pci_mmcfg_region *cfg);
  152. extern int pci_mmconfig_insert(struct device *dev, u16 seg, u8 start, u8 end,
  153. phys_addr_t addr);
  154. extern int pci_mmconfig_delete(u16 seg, u8 start, u8 end);
  155. extern struct pci_mmcfg_region *pci_mmconfig_lookup(int segment, int bus);
  156. extern struct pci_mmcfg_region *__init pci_mmconfig_add(int segment, int start,
  157. int end, u64 addr);
  158. extern struct list_head pci_mmcfg_list;
  159. #define PCI_MMCFG_BUS_OFFSET(bus) ((bus) << 20)
  160. /*
  161. * On AMD Fam10h CPUs, all PCI MMIO configuration space accesses must use
  162. * %eax. No other source or target registers may be used. The following
  163. * mmio_config_* accessors enforce this. See "BIOS and Kernel Developer's
  164. * Guide (BKDG) For AMD Family 10h Processors", rev. 3.48, sec 2.11.1,
  165. * "MMIO Configuration Coding Requirements".
  166. */
  167. static inline unsigned char mmio_config_readb(void __iomem *pos)
  168. {
  169. u8 val;
  170. asm volatile("movb (%1),%%al" : "=a" (val) : "r" (pos));
  171. return val;
  172. }
  173. static inline unsigned short mmio_config_readw(void __iomem *pos)
  174. {
  175. u16 val;
  176. asm volatile("movw (%1),%%ax" : "=a" (val) : "r" (pos));
  177. return val;
  178. }
  179. static inline unsigned int mmio_config_readl(void __iomem *pos)
  180. {
  181. u32 val;
  182. asm volatile("movl (%1),%%eax" : "=a" (val) : "r" (pos));
  183. return val;
  184. }
  185. static inline void mmio_config_writeb(void __iomem *pos, u8 val)
  186. {
  187. asm volatile("movb %%al,(%1)" : : "a" (val), "r" (pos) : "memory");
  188. }
  189. static inline void mmio_config_writew(void __iomem *pos, u16 val)
  190. {
  191. asm volatile("movw %%ax,(%1)" : : "a" (val), "r" (pos) : "memory");
  192. }
  193. static inline void mmio_config_writel(void __iomem *pos, u32 val)
  194. {
  195. asm volatile("movl %%eax,(%1)" : : "a" (val), "r" (pos) : "memory");
  196. }
  197. #ifdef CONFIG_PCI
  198. # ifdef CONFIG_ACPI
  199. # define x86_default_pci_init pci_acpi_init
  200. # else
  201. # define x86_default_pci_init pci_legacy_init
  202. # endif
  203. # define x86_default_pci_init_irq pcibios_irq_init
  204. # define x86_default_pci_fixup_irqs pcibios_fixup_irqs
  205. #else
  206. # define x86_default_pci_init NULL
  207. # define x86_default_pci_init_irq NULL
  208. # define x86_default_pci_fixup_irqs NULL
  209. #endif
  210. #if defined(CONFIG_PCI) && defined(CONFIG_ACPI)
  211. extern bool pci_use_e820;
  212. #else
  213. #define pci_use_e820 false
  214. #endif