mpspec.h 12 KB

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