mpspec.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*
  2. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * Adapted from coreboot src/arch/x86/include/arch/smp/mpspec.h
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef __ASM_MPSPEC_H
  9. #define __ASM_MPSPEC_H
  10. /*
  11. * Structure definitions for SMP machines following the
  12. * Intel MultiProcessor Specification 1.4
  13. */
  14. #define MPSPEC_V14 4
  15. #define MPF_SIGNATURE "_MP_"
  16. struct mp_floating_table {
  17. char mpf_signature[4]; /* "_MP_" */
  18. u32 mpf_physptr; /* Configuration table address */
  19. u8 mpf_length; /* Our length (paragraphs) */
  20. u8 mpf_spec; /* Specification version */
  21. u8 mpf_checksum; /* Checksum (makes sum 0) */
  22. u8 mpf_feature1; /* Predefined or Unique configuration? */
  23. u8 mpf_feature2; /* Bit7 set for IMCR/PIC */
  24. u8 mpf_feature3; /* Unused (0) */
  25. u8 mpf_feature4; /* Unused (0) */
  26. u8 mpf_feature5; /* Unused (0) */
  27. };
  28. #define MPC_SIGNATURE "PCMP"
  29. struct mp_config_table {
  30. char mpc_signature[4]; /* "PCMP" */
  31. u16 mpc_length; /* Size of table */
  32. u8 mpc_spec; /* Specification version */
  33. u8 mpc_checksum; /* Checksum (makes sum 0) */
  34. char mpc_oem[8]; /* OEM ID */
  35. char mpc_product[12]; /* Product ID */
  36. u32 mpc_oemptr; /* OEM table address */
  37. u16 mpc_oemsize; /* OEM table size */
  38. u16 mpc_entry_count; /* Number of entries in the table */
  39. u32 mpc_lapic; /* Local APIC address */
  40. u16 mpe_length; /* Extended table size */
  41. u8 mpe_checksum; /* Extended table checksum */
  42. u8 reserved;
  43. };
  44. /* Base MP configuration table entry types */
  45. enum mp_base_config_entry_type {
  46. MP_PROCESSOR,
  47. MP_BUS,
  48. MP_IOAPIC,
  49. MP_INTSRC,
  50. MP_LINTSRC
  51. };
  52. #define MPC_CPU_EN (1 << 0)
  53. #define MPC_CPU_BP (1 << 1)
  54. struct mpc_config_processor {
  55. u8 mpc_type;
  56. u8 mpc_apicid;
  57. u8 mpc_apicver;
  58. u8 mpc_cpuflag;
  59. u32 mpc_cpusignature;
  60. u32 mpc_cpufeature;
  61. u32 mpc_reserved[2];
  62. };
  63. #define BUSTYPE_CBUS "CBUS "
  64. #define BUSTYPE_CBUSII "CBUSII"
  65. #define BUSTYPE_EISA "EISA "
  66. #define BUSTYPE_FUTURE "FUTURE"
  67. #define BUSTYPE_INTERN "INTERN"
  68. #define BUSTYPE_ISA "ISA "
  69. #define BUSTYPE_MBI "MBI "
  70. #define BUSTYPE_MBII "MBII "
  71. #define BUSTYPE_MCA "MCA "
  72. #define BUSTYPE_MPI "MPI "
  73. #define BUSTYPE_MPSA "MPSA "
  74. #define BUSTYPE_NUBUS "NUBUS "
  75. #define BUSTYPE_PCI "PCI "
  76. #define BUSTYPE_PCMCIA "PCMCIA"
  77. #define BUSTYPE_TC "TC "
  78. #define BUSTYPE_VL "VL "
  79. #define BUSTYPE_VME "VME "
  80. #define BUSTYPE_XPRESS "XPRESS"
  81. struct mpc_config_bus {
  82. u8 mpc_type;
  83. u8 mpc_busid;
  84. u8 mpc_bustype[6];
  85. };
  86. #define MPC_APIC_USABLE (1 << 0)
  87. struct mpc_config_ioapic {
  88. u8 mpc_type;
  89. u8 mpc_apicid;
  90. u8 mpc_apicver;
  91. u8 mpc_flags;
  92. u32 mpc_apicaddr;
  93. };
  94. enum mp_irq_source_types {
  95. MP_INT,
  96. MP_NMI,
  97. MP_SMI,
  98. MP_EXTINT
  99. };
  100. #define MP_IRQ_POLARITY_DEFAULT 0x0
  101. #define MP_IRQ_POLARITY_HIGH 0x1
  102. #define MP_IRQ_POLARITY_LOW 0x3
  103. #define MP_IRQ_POLARITY_MASK 0x3
  104. #define MP_IRQ_TRIGGER_DEFAULT 0x0
  105. #define MP_IRQ_TRIGGER_EDGE 0x4
  106. #define MP_IRQ_TRIGGER_LEVEL 0xc
  107. #define MP_IRQ_TRIGGER_MASK 0xc
  108. #define MP_APIC_ALL 0xff
  109. struct mpc_config_intsrc {
  110. u8 mpc_type;
  111. u8 mpc_irqtype;
  112. u16 mpc_irqflag;
  113. u8 mpc_srcbus;
  114. u8 mpc_srcbusirq;
  115. u8 mpc_dstapic;
  116. u8 mpc_dstirq;
  117. };
  118. struct mpc_config_lintsrc {
  119. u8 mpc_type;
  120. u8 mpc_irqtype;
  121. u16 mpc_irqflag;
  122. u8 mpc_srcbusid;
  123. u8 mpc_srcbusirq;
  124. u8 mpc_destapic;
  125. u8 mpc_destlint;
  126. };
  127. /* Extended MP configuration table entry types */
  128. enum mp_ext_config_entry_type {
  129. MPE_SYSTEM_ADDRESS_SPACE = 128,
  130. MPE_BUS_HIERARCHY,
  131. MPE_COMPAT_ADDRESS_SPACE
  132. };
  133. struct mp_ext_config {
  134. u8 mpe_type;
  135. u8 mpe_length;
  136. };
  137. #define ADDRESS_TYPE_IO 0
  138. #define ADDRESS_TYPE_MEM 1
  139. #define ADDRESS_TYPE_PREFETCH 2
  140. struct mp_ext_system_address_space {
  141. u8 mpe_type;
  142. u8 mpe_length;
  143. u8 mpe_busid;
  144. u8 mpe_addr_type;
  145. u32 mpe_addr_base_low;
  146. u32 mpe_addr_base_high;
  147. u32 mpe_addr_length_low;
  148. u32 mpe_addr_length_high;
  149. };
  150. #define BUS_SUBTRACTIVE_DECODE (1 << 0)
  151. struct mp_ext_bus_hierarchy {
  152. u8 mpe_type;
  153. u8 mpe_length;
  154. u8 mpe_busid;
  155. u8 mpe_bus_info;
  156. u8 mpe_parent_busid;
  157. u8 reserved[3];
  158. };
  159. #define ADDRESS_RANGE_ADD 0
  160. #define ADDRESS_RANGE_SUBTRACT 1
  161. /*
  162. * X100 - X3FF
  163. * X500 - X7FF
  164. * X900 - XBFF
  165. * XD00 - XFFF
  166. */
  167. #define RANGE_LIST_IO_ISA 0
  168. /*
  169. * X3B0 - X3BB
  170. * X3C0 - X3DF
  171. * X7B0 - X7BB
  172. * X7C0 - X7DF
  173. * XBB0 - XBBB
  174. * XBC0 - XBDF
  175. * XFB0 - XFBB
  176. * XFC0 - XCDF
  177. */
  178. #define RANGE_LIST_IO_VGA 1
  179. struct mp_ext_compat_address_space {
  180. u8 mpe_type;
  181. u8 mpe_length;
  182. u8 mpe_busid;
  183. u8 mpe_addr_modifier;
  184. u32 mpe_range_list;
  185. };
  186. /**
  187. * mp_next_mpc_entry() - Compute MP configuration table end to be used as
  188. * next base table entry start address
  189. *
  190. * This computes the end address of current MP configuration table, without
  191. * counting any extended configuration table entry.
  192. *
  193. * @mc: configuration table header address
  194. * @return: configuration table end address
  195. */
  196. static inline u32 mp_next_mpc_entry(struct mp_config_table *mc)
  197. {
  198. return (u32)mc + mc->mpc_length;
  199. }
  200. /**
  201. * mp_add_mpc_entry() - Add a base MP configuration table entry
  202. *
  203. * This adds the base MP configuration table entry size with
  204. * added base table entry length and increases entry count by 1.
  205. *
  206. * @mc: configuration table header address
  207. * @length: length of the added table entry
  208. */
  209. static inline void mp_add_mpc_entry(struct mp_config_table *mc, uint length)
  210. {
  211. mc->mpc_length += length;
  212. mc->mpc_entry_count++;
  213. }
  214. /**
  215. * mp_next_mpe_entry() - Compute MP configuration table end to be used as
  216. * next extended table entry start address
  217. *
  218. * This computes the end address of current MP configuration table,
  219. * including any extended configuration table entry.
  220. *
  221. * @mc: configuration table header address
  222. * @return: configuration table end address
  223. */
  224. static inline u32 mp_next_mpe_entry(struct mp_config_table *mc)
  225. {
  226. return (u32)mc + mc->mpc_length + mc->mpe_length;
  227. }
  228. /**
  229. * mp_add_mpe_entry() - Add an extended MP configuration table entry
  230. *
  231. * This adds the extended MP configuration table entry size with
  232. * added extended table entry length.
  233. *
  234. * @mc: configuration table header address
  235. * @mpe: extended table entry base address
  236. */
  237. static inline void mp_add_mpe_entry(struct mp_config_table *mc,
  238. struct mp_ext_config *mpe)
  239. {
  240. mc->mpe_length += mpe->mpe_length;
  241. }
  242. /**
  243. * mp_write_floating_table() - Write the MP floating table
  244. *
  245. * This writes the MP floating table, and points MP configuration table
  246. * to its end address so that MP configuration table follows immediately
  247. * after the floating table.
  248. *
  249. * @mf: MP floating table base address
  250. * @return: MP configuration table header address
  251. */
  252. struct mp_config_table *mp_write_floating_table(struct mp_floating_table *mf);
  253. /**
  254. * mp_config_table_init() - Initialize the MP configuration table header
  255. *
  256. * This populates the MP configuration table header with valid bits.
  257. *
  258. * @mc: MP configuration table header address
  259. */
  260. void mp_config_table_init(struct mp_config_table *mc);
  261. /**
  262. * mp_write_processor() - Write a processor entry
  263. *
  264. * This writes a processor entry to the configuration table.
  265. *
  266. * @mc: MP configuration table header address
  267. */
  268. void mp_write_processor(struct mp_config_table *mc);
  269. /**
  270. * mp_write_bus() - Write a bus entry
  271. *
  272. * This writes a bus entry to the configuration table.
  273. *
  274. * @mc: MP configuration table header address
  275. * @id: bus id
  276. * @bustype: bus type name
  277. */
  278. void mp_write_bus(struct mp_config_table *mc, int id, const char *bustype);
  279. /**
  280. * mp_write_ioapic() - Write an I/O APIC entry
  281. *
  282. * This writes an I/O APIC entry to the configuration table.
  283. *
  284. * @mc: MP configuration table header address
  285. * @id: I/O APIC id
  286. * @ver: I/O APIC version
  287. * @apicaddr: I/O APIC address
  288. */
  289. void mp_write_ioapic(struct mp_config_table *mc, int id, int ver, u32 apicaddr);
  290. /**
  291. * mp_write_intsrc() - Write an I/O interrupt assignment entry
  292. *
  293. * This writes an I/O interrupt assignment entry to the configuration table.
  294. *
  295. * @mc: MP configuration table header address
  296. * @irqtype: IRQ type (INT/NMI/SMI/ExtINT)
  297. * @irqflag: IRQ flag (level/trigger)
  298. * @srcbus: source bus id where the interrupt comes from
  299. * @srcbusirq: IRQ number mapped on the source bus
  300. * @dstapic: destination I/O APIC id where the interrupt goes to
  301. * @dstirq: destination I/O APIC pin where the interrupt goes to
  302. */
  303. void mp_write_intsrc(struct mp_config_table *mc, int irqtype, int irqflag,
  304. int srcbus, int srcbusirq, int dstapic, int dstirq);
  305. /**
  306. * mp_write_pci_intsrc() - Write a PCI interrupt assignment entry
  307. *
  308. * This writes a PCI interrupt assignment entry to the configuration table.
  309. *
  310. * @mc: MP configuration table header address
  311. * @irqtype: IRQ type (INT/NMI/SMI/ExtINT)
  312. * @srcbus: PCI bus number where the interrupt comes from
  313. * @dev: device number on the PCI bus
  314. * @pin: PCI interrupt pin (INT A/B/C/D)
  315. * @dstapic: destination I/O APIC id where the interrupt goes to
  316. * @dstirq: destination I/O APIC pin where the interrupt goes to
  317. */
  318. void mp_write_pci_intsrc(struct mp_config_table *mc, int irqtype,
  319. int srcbus, int dev, int pin, int dstapic, int dstirq);
  320. /**
  321. * mp_write_lintsrc() - Write a local interrupt assignment entry
  322. *
  323. * This writes a local interrupt assignment entry to the configuration table.
  324. *
  325. * @mc: MP configuration table header address
  326. * @irqtype: IRQ type (INT/NMI/SMI/ExtINT)
  327. * @irqflag: IRQ flag (level/trigger)
  328. * @srcbus: PCI bus number where the interrupt comes from
  329. * @srcbusirq: IRQ number mapped on the source bus
  330. * @dstapic: destination local APIC id where the interrupt goes to
  331. * @destlint: destination local APIC pin where the interrupt goes to
  332. */
  333. void mp_write_lintsrc(struct mp_config_table *mc, int irqtype, int irqflag,
  334. int srcbus, int srcbusirq, int destapic, int destlint);
  335. /**
  336. * mp_write_address_space() - Write a system address space entry
  337. *
  338. * This writes a system address space entry to the configuration table.
  339. *
  340. * @mc: MP configuration table header address
  341. * @busid: bus id for the bus where system address space is mapped
  342. * @addr_type: system address type
  343. * @addr_base_low: starting address low
  344. * @addr_base_high: starting address high
  345. * @addr_length_low: address length low
  346. * @addr_length_high: address length high
  347. */
  348. void mp_write_address_space(struct mp_config_table *mc,
  349. int busid, int addr_type,
  350. u32 addr_base_low, u32 addr_base_high,
  351. u32 addr_length_low, u32 addr_length_high);
  352. /**
  353. * mp_write_bus_hierarchy() - Write a bus hierarchy descriptor entry
  354. *
  355. * This writes a bus hierarchy descriptor entry to the configuration table.
  356. *
  357. * @mc: MP configuration table header address
  358. * @busid: bus id
  359. * @bus_info: bit0 indicates if the bus is a subtractive decode bus
  360. * @parent_busid: parent bus id
  361. */
  362. void mp_write_bus_hierarchy(struct mp_config_table *mc,
  363. int busid, int bus_info, int parent_busid);
  364. /**
  365. * mp_write_compat_address_space() - Write a compat bus address space entry
  366. *
  367. * This writes a compatibility bus address space modifier entry to the
  368. * configuration table.
  369. *
  370. * @mc: MP configuration table header address
  371. * @busid: bus id
  372. * @addr_modifier: add or subtract to predefined address range list
  373. * @range_list: list of predefined address space ranges
  374. */
  375. void mp_write_compat_address_space(struct mp_config_table *mc, int busid,
  376. int addr_modifier, u32 range_list);
  377. /**
  378. * mptable_finalize() - Finalize the MP table
  379. *
  380. * This finalizes the MP table by calculating required checksums.
  381. *
  382. * @mc: MP configuration table header address
  383. * @return: MP table end address
  384. */
  385. u32 mptable_finalize(struct mp_config_table *mc);
  386. /**
  387. * mp_determine_pci_dstirq() - Determine PCI device's int pin on the I/O APIC
  388. *
  389. * This determines a PCI device's interrupt pin number on the I/O APIC.
  390. *
  391. * This can be implemented by platform codes to handle specifal cases, which
  392. * do not conform to the normal chipset/board design where PIRQ[A-H] are mapped
  393. * directly to I/O APIC INTPIN#16-23.
  394. *
  395. * @bus: bus number of the pci device
  396. * @dev: device number of the pci device
  397. * @func: function number of the pci device
  398. * @pirq: PIRQ number the PCI device's interrupt pin is routed to
  399. * @return: interrupt pin number on the I/O APIC
  400. */
  401. int mp_determine_pci_dstirq(int bus, int dev, int func, int pirq);
  402. /**
  403. * write_mp_table() - Write MP table
  404. *
  405. * This writes MP table at a given address.
  406. *
  407. * @addr: start address to write MP table
  408. * @return: end address of MP table
  409. */
  410. u32 write_mp_table(u32 addr);
  411. #endif /* __ASM_MPSPEC_H */