ibmphp.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef __IBMPHP_H
  3. #define __IBMPHP_H
  4. /*
  5. * IBM Hot Plug Controller Driver
  6. *
  7. * Written By: Jyoti Shah, Tong Yu, Irene Zubarev, IBM Corporation
  8. *
  9. * Copyright (C) 2001 Greg Kroah-Hartman ([email protected])
  10. * Copyright (C) 2001-2003 IBM Corp.
  11. *
  12. * All rights reserved.
  13. *
  14. * Send feedback to <[email protected]>
  15. *
  16. */
  17. #include <linux/pci_hotplug.h>
  18. extern int ibmphp_debug;
  19. #if !defined(MODULE)
  20. #define MY_NAME "ibmphpd"
  21. #else
  22. #define MY_NAME THIS_MODULE->name
  23. #endif
  24. #define debug(fmt, arg...) do { if (ibmphp_debug == 1) printk(KERN_DEBUG "%s: " fmt, MY_NAME, ## arg); } while (0)
  25. #define debug_pci(fmt, arg...) do { if (ibmphp_debug) printk(KERN_DEBUG "%s: " fmt, MY_NAME, ## arg); } while (0)
  26. #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME, ## arg)
  27. #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME, ## arg)
  28. #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME, ## arg)
  29. /* EBDA stuff */
  30. /***********************************************************
  31. * SLOT CAPABILITY *
  32. ***********************************************************/
  33. #define EBDA_SLOT_133_MAX 0x20
  34. #define EBDA_SLOT_100_MAX 0x10
  35. #define EBDA_SLOT_66_MAX 0x02
  36. #define EBDA_SLOT_PCIX_CAP 0x08
  37. /************************************************************
  38. * RESOURCE TYPE *
  39. ************************************************************/
  40. #define EBDA_RSRC_TYPE_MASK 0x03
  41. #define EBDA_IO_RSRC_TYPE 0x00
  42. #define EBDA_MEM_RSRC_TYPE 0x01
  43. #define EBDA_PFM_RSRC_TYPE 0x03
  44. #define EBDA_RES_RSRC_TYPE 0x02
  45. /*************************************************************
  46. * IO RESTRICTION TYPE *
  47. *************************************************************/
  48. #define EBDA_IO_RESTRI_MASK 0x0c
  49. #define EBDA_NO_RESTRI 0x00
  50. #define EBDA_AVO_VGA_ADDR 0x04
  51. #define EBDA_AVO_VGA_ADDR_AND_ALIA 0x08
  52. #define EBDA_AVO_ISA_ADDR 0x0c
  53. /**************************************************************
  54. * DEVICE TYPE DEF *
  55. **************************************************************/
  56. #define EBDA_DEV_TYPE_MASK 0x10
  57. #define EBDA_PCI_DEV 0x10
  58. #define EBDA_NON_PCI_DEV 0x00
  59. /***************************************************************
  60. * PRIMARY DEF DEFINITION *
  61. ***************************************************************/
  62. #define EBDA_PRI_DEF_MASK 0x20
  63. #define EBDA_PRI_PCI_BUS_INFO 0x20
  64. #define EBDA_NORM_DEV_RSRC_INFO 0x00
  65. //--------------------------------------------------------------
  66. // RIO TABLE DATA STRUCTURE
  67. //--------------------------------------------------------------
  68. struct rio_table_hdr {
  69. u8 ver_num;
  70. u8 scal_count;
  71. u8 riodev_count;
  72. u16 offset;
  73. };
  74. //-------------------------------------------------------------
  75. // SCALABILITY DETAIL
  76. //-------------------------------------------------------------
  77. struct scal_detail {
  78. u8 node_id;
  79. u32 cbar;
  80. u8 port0_node_connect;
  81. u8 port0_port_connect;
  82. u8 port1_node_connect;
  83. u8 port1_port_connect;
  84. u8 port2_node_connect;
  85. u8 port2_port_connect;
  86. u8 chassis_num;
  87. // struct list_head scal_detail_list;
  88. };
  89. //--------------------------------------------------------------
  90. // RIO DETAIL
  91. //--------------------------------------------------------------
  92. struct rio_detail {
  93. u8 rio_node_id;
  94. u32 bbar;
  95. u8 rio_type;
  96. u8 owner_id;
  97. u8 port0_node_connect;
  98. u8 port0_port_connect;
  99. u8 port1_node_connect;
  100. u8 port1_port_connect;
  101. u8 first_slot_num;
  102. u8 status;
  103. u8 wpindex;
  104. u8 chassis_num;
  105. struct list_head rio_detail_list;
  106. };
  107. struct opt_rio {
  108. u8 rio_type;
  109. u8 chassis_num;
  110. u8 first_slot_num;
  111. u8 middle_num;
  112. struct list_head opt_rio_list;
  113. };
  114. struct opt_rio_lo {
  115. u8 rio_type;
  116. u8 chassis_num;
  117. u8 first_slot_num;
  118. u8 middle_num;
  119. u8 pack_count;
  120. struct list_head opt_rio_lo_list;
  121. };
  122. /****************************************************************
  123. * HPC DESCRIPTOR NODE *
  124. ****************************************************************/
  125. struct ebda_hpc_list {
  126. u8 format;
  127. u16 num_ctlrs;
  128. short phys_addr;
  129. // struct list_head ebda_hpc_list;
  130. };
  131. /*****************************************************************
  132. * IN HPC DATA STRUCTURE, THE ASSOCIATED SLOT AND BUS *
  133. * STRUCTURE *
  134. *****************************************************************/
  135. struct ebda_hpc_slot {
  136. u8 slot_num;
  137. u32 slot_bus_num;
  138. u8 ctl_index;
  139. u8 slot_cap;
  140. };
  141. struct ebda_hpc_bus {
  142. u32 bus_num;
  143. u8 slots_at_33_conv;
  144. u8 slots_at_66_conv;
  145. u8 slots_at_66_pcix;
  146. u8 slots_at_100_pcix;
  147. u8 slots_at_133_pcix;
  148. };
  149. /********************************************************************
  150. * THREE TYPE OF HOT PLUG CONTROLLER *
  151. ********************************************************************/
  152. struct isa_ctlr_access {
  153. u16 io_start;
  154. u16 io_end;
  155. };
  156. struct pci_ctlr_access {
  157. u8 bus;
  158. u8 dev_fun;
  159. };
  160. struct wpeg_i2c_ctlr_access {
  161. ulong wpegbbar;
  162. u8 i2c_addr;
  163. };
  164. #define HPC_DEVICE_ID 0x0246
  165. #define HPC_SUBSYSTEM_ID 0x0247
  166. #define HPC_PCI_OFFSET 0x40
  167. /*************************************************************************
  168. * RSTC DESCRIPTOR NODE *
  169. *************************************************************************/
  170. struct ebda_rsrc_list {
  171. u8 format;
  172. u16 num_entries;
  173. u16 phys_addr;
  174. struct ebda_rsrc_list *next;
  175. };
  176. /***************************************************************************
  177. * PCI RSRC NODE *
  178. ***************************************************************************/
  179. struct ebda_pci_rsrc {
  180. u8 rsrc_type;
  181. u8 bus_num;
  182. u8 dev_fun;
  183. u32 start_addr;
  184. u32 end_addr;
  185. u8 marked; /* for NVRAM */
  186. struct list_head ebda_pci_rsrc_list;
  187. };
  188. /***********************************************************
  189. * BUS_INFO DATE STRUCTURE *
  190. ***********************************************************/
  191. struct bus_info {
  192. u8 slot_min;
  193. u8 slot_max;
  194. u8 slot_count;
  195. u8 busno;
  196. u8 controller_id;
  197. u8 current_speed;
  198. u8 current_bus_mode;
  199. u8 index;
  200. u8 slots_at_33_conv;
  201. u8 slots_at_66_conv;
  202. u8 slots_at_66_pcix;
  203. u8 slots_at_100_pcix;
  204. u8 slots_at_133_pcix;
  205. struct list_head bus_info_list;
  206. };
  207. /***********************************************************
  208. * GLOBAL VARIABLES *
  209. ***********************************************************/
  210. extern struct list_head ibmphp_ebda_pci_rsrc_head;
  211. extern struct list_head ibmphp_slot_head;
  212. /***********************************************************
  213. * FUNCTION PROTOTYPES *
  214. ***********************************************************/
  215. void ibmphp_free_ebda_hpc_queue(void);
  216. int ibmphp_access_ebda(void);
  217. struct slot *ibmphp_get_slot_from_physical_num(u8);
  218. int ibmphp_get_total_hp_slots(void);
  219. void ibmphp_free_ibm_slot(struct slot *);
  220. void ibmphp_free_bus_info_queue(void);
  221. void ibmphp_free_ebda_pci_rsrc_queue(void);
  222. struct bus_info *ibmphp_find_same_bus_num(u32);
  223. int ibmphp_get_bus_index(u8);
  224. u16 ibmphp_get_total_controllers(void);
  225. int ibmphp_register_pci(void);
  226. /* passed parameters */
  227. #define MEM 0
  228. #define IO 1
  229. #define PFMEM 2
  230. /* bit masks */
  231. #define RESTYPE 0x03
  232. #define IOMASK 0x00 /* will need to take its complement */
  233. #define MMASK 0x01
  234. #define PFMASK 0x03
  235. #define PCIDEVMASK 0x10 /* we should always have PCI devices */
  236. #define PRIMARYBUSMASK 0x20
  237. /* pci specific defines */
  238. #define PCI_VENDOR_ID_NOTVALID 0xFFFF
  239. #define PCI_HEADER_TYPE_MULTIDEVICE 0x80
  240. #define PCI_HEADER_TYPE_MULTIBRIDGE 0x81
  241. #define LATENCY 0x64
  242. #define CACHE 64
  243. #define DEVICEENABLE 0x015F /* CPQ has 0x0157 */
  244. #define IOBRIDGE 0x1000 /* 4k */
  245. #define MEMBRIDGE 0x100000 /* 1M */
  246. /* irqs */
  247. #define SCSI_IRQ 0x09
  248. #define LAN_IRQ 0x0A
  249. #define OTHER_IRQ 0x0B
  250. /* Data Structures */
  251. /* type is of the form x x xx xx
  252. * | | | |_ 00 - I/O, 01 - Memory, 11 - PFMemory
  253. * | | - 00 - No Restrictions, 01 - Avoid VGA, 10 - Avoid
  254. * | | VGA and their aliases, 11 - Avoid ISA
  255. * | - 1 - PCI device, 0 - non pci device
  256. * - 1 - Primary PCI Bus Information (0 if Normal device)
  257. * the IO restrictions [2:3] are only for primary buses
  258. */
  259. /* we need this struct because there could be several resource blocks
  260. * allocated per primary bus in the EBDA
  261. */
  262. struct range_node {
  263. int rangeno;
  264. u32 start;
  265. u32 end;
  266. struct range_node *next;
  267. };
  268. struct bus_node {
  269. u8 busno;
  270. int noIORanges;
  271. struct range_node *rangeIO;
  272. int noMemRanges;
  273. struct range_node *rangeMem;
  274. int noPFMemRanges;
  275. struct range_node *rangePFMem;
  276. int needIOUpdate;
  277. int needMemUpdate;
  278. int needPFMemUpdate;
  279. struct resource_node *firstIO; /* first IO resource on the Bus */
  280. struct resource_node *firstMem; /* first memory resource on the Bus */
  281. struct resource_node *firstPFMem; /* first prefetchable memory resource on the Bus */
  282. struct resource_node *firstPFMemFromMem; /* when run out of pfmem available, taking from Mem */
  283. struct list_head bus_list;
  284. };
  285. struct resource_node {
  286. int rangeno;
  287. u8 busno;
  288. u8 devfunc;
  289. u32 start;
  290. u32 end;
  291. u32 len;
  292. int type; /* MEM, IO, PFMEM */
  293. u8 fromMem; /* this is to indicate that the range is from
  294. * the Memory bucket rather than from PFMem */
  295. struct resource_node *next;
  296. struct resource_node *nextRange; /* for the other mem range on bus */
  297. };
  298. struct res_needed {
  299. u32 mem;
  300. u32 pfmem;
  301. u32 io;
  302. u8 not_correct; /* needed for return */
  303. int devices[32]; /* for device numbers behind this bridge */
  304. };
  305. /* functions */
  306. int ibmphp_rsrc_init(void);
  307. int ibmphp_add_resource(struct resource_node *);
  308. int ibmphp_remove_resource(struct resource_node *);
  309. int ibmphp_find_resource(struct bus_node *, u32, struct resource_node **, int);
  310. int ibmphp_check_resource(struct resource_node *, u8);
  311. int ibmphp_remove_bus(struct bus_node *, u8);
  312. void ibmphp_free_resources(void);
  313. int ibmphp_add_pfmem_from_mem(struct resource_node *);
  314. struct bus_node *ibmphp_find_res_bus(u8);
  315. void ibmphp_print_test(void); /* for debugging purposes */
  316. int ibmphp_hpc_readslot(struct slot *, u8, u8 *);
  317. int ibmphp_hpc_writeslot(struct slot *, u8);
  318. void ibmphp_lock_operations(void);
  319. void ibmphp_unlock_operations(void);
  320. int ibmphp_hpc_start_poll_thread(void);
  321. void ibmphp_hpc_stop_poll_thread(void);
  322. //----------------------------------------------------------------------------
  323. //----------------------------------------------------------------------------
  324. // HPC return codes
  325. //----------------------------------------------------------------------------
  326. #define HPC_ERROR 0xFF
  327. //-----------------------------------------------------------------------------
  328. // BUS INFO
  329. //-----------------------------------------------------------------------------
  330. #define BUS_SPEED 0x30
  331. #define BUS_MODE 0x40
  332. #define BUS_MODE_PCIX 0x01
  333. #define BUS_MODE_PCI 0x00
  334. #define BUS_SPEED_2 0x20
  335. #define BUS_SPEED_1 0x10
  336. #define BUS_SPEED_33 0x00
  337. #define BUS_SPEED_66 0x01
  338. #define BUS_SPEED_100 0x02
  339. #define BUS_SPEED_133 0x03
  340. #define BUS_SPEED_66PCIX 0x04
  341. #define BUS_SPEED_66UNKNOWN 0x05
  342. #define BUS_STATUS_AVAILABLE 0x01
  343. #define BUS_CONTROL_AVAILABLE 0x02
  344. #define SLOT_LATCH_REGS_SUPPORTED 0x10
  345. #define PRGM_MODEL_REV_LEVEL 0xF0
  346. #define MAX_ADAPTER_NONE 0x09
  347. //----------------------------------------------------------------------------
  348. // HPC 'write' operations/commands
  349. //----------------------------------------------------------------------------
  350. // Command Code State Write to reg
  351. // Machine at index
  352. //------------------------- ---- ------- ------------
  353. #define HPC_CTLR_ENABLEIRQ 0x00 // N 15
  354. #define HPC_CTLR_DISABLEIRQ 0x01 // N 15
  355. #define HPC_SLOT_OFF 0x02 // Y 0-14
  356. #define HPC_SLOT_ON 0x03 // Y 0-14
  357. #define HPC_SLOT_ATTNOFF 0x04 // N 0-14
  358. #define HPC_SLOT_ATTNON 0x05 // N 0-14
  359. #define HPC_CTLR_CLEARIRQ 0x06 // N 15
  360. #define HPC_CTLR_RESET 0x07 // Y 15
  361. #define HPC_CTLR_IRQSTEER 0x08 // N 15
  362. #define HPC_BUS_33CONVMODE 0x09 // Y 31-34
  363. #define HPC_BUS_66CONVMODE 0x0A // Y 31-34
  364. #define HPC_BUS_66PCIXMODE 0x0B // Y 31-34
  365. #define HPC_BUS_100PCIXMODE 0x0C // Y 31-34
  366. #define HPC_BUS_133PCIXMODE 0x0D // Y 31-34
  367. #define HPC_ALLSLOT_OFF 0x11 // Y 15
  368. #define HPC_ALLSLOT_ON 0x12 // Y 15
  369. #define HPC_SLOT_BLINKLED 0x13 // N 0-14
  370. //----------------------------------------------------------------------------
  371. // read commands
  372. //----------------------------------------------------------------------------
  373. #define READ_SLOTSTATUS 0x01
  374. #define READ_EXTSLOTSTATUS 0x02
  375. #define READ_BUSSTATUS 0x03
  376. #define READ_CTLRSTATUS 0x04
  377. #define READ_ALLSTAT 0x05
  378. #define READ_ALLSLOT 0x06
  379. #define READ_SLOTLATCHLOWREG 0x07
  380. #define READ_REVLEVEL 0x08
  381. #define READ_HPCOPTIONS 0x09
  382. //----------------------------------------------------------------------------
  383. // slot status
  384. //----------------------------------------------------------------------------
  385. #define HPC_SLOT_POWER 0x01
  386. #define HPC_SLOT_CONNECT 0x02
  387. #define HPC_SLOT_ATTN 0x04
  388. #define HPC_SLOT_PRSNT2 0x08
  389. #define HPC_SLOT_PRSNT1 0x10
  390. #define HPC_SLOT_PWRGD 0x20
  391. #define HPC_SLOT_BUS_SPEED 0x40
  392. #define HPC_SLOT_LATCH 0x80
  393. //----------------------------------------------------------------------------
  394. // HPC_SLOT_POWER status return codes
  395. //----------------------------------------------------------------------------
  396. #define HPC_SLOT_POWER_OFF 0x00
  397. #define HPC_SLOT_POWER_ON 0x01
  398. //----------------------------------------------------------------------------
  399. // HPC_SLOT_CONNECT status return codes
  400. //----------------------------------------------------------------------------
  401. #define HPC_SLOT_CONNECTED 0x00
  402. #define HPC_SLOT_DISCONNECTED 0x01
  403. //----------------------------------------------------------------------------
  404. // HPC_SLOT_ATTN status return codes
  405. //----------------------------------------------------------------------------
  406. #define HPC_SLOT_ATTN_OFF 0x00
  407. #define HPC_SLOT_ATTN_ON 0x01
  408. #define HPC_SLOT_ATTN_BLINK 0x02
  409. //----------------------------------------------------------------------------
  410. // HPC_SLOT_PRSNT status return codes
  411. //----------------------------------------------------------------------------
  412. #define HPC_SLOT_EMPTY 0x00
  413. #define HPC_SLOT_PRSNT_7 0x01
  414. #define HPC_SLOT_PRSNT_15 0x02
  415. #define HPC_SLOT_PRSNT_25 0x03
  416. //----------------------------------------------------------------------------
  417. // HPC_SLOT_PWRGD status return codes
  418. //----------------------------------------------------------------------------
  419. #define HPC_SLOT_PWRGD_FAULT_NONE 0x00
  420. #define HPC_SLOT_PWRGD_GOOD 0x01
  421. //----------------------------------------------------------------------------
  422. // HPC_SLOT_BUS_SPEED status return codes
  423. //----------------------------------------------------------------------------
  424. #define HPC_SLOT_BUS_SPEED_OK 0x00
  425. #define HPC_SLOT_BUS_SPEED_MISM 0x01
  426. //----------------------------------------------------------------------------
  427. // HPC_SLOT_LATCH status return codes
  428. //----------------------------------------------------------------------------
  429. #define HPC_SLOT_LATCH_OPEN 0x01 // NOTE : in PCI spec bit off = open
  430. #define HPC_SLOT_LATCH_CLOSED 0x00 // NOTE : in PCI spec bit on = closed
  431. //----------------------------------------------------------------------------
  432. // extended slot status
  433. //----------------------------------------------------------------------------
  434. #define HPC_SLOT_PCIX 0x01
  435. #define HPC_SLOT_SPEED1 0x02
  436. #define HPC_SLOT_SPEED2 0x04
  437. #define HPC_SLOT_BLINK_ATTN 0x08
  438. #define HPC_SLOT_RSRVD1 0x10
  439. #define HPC_SLOT_RSRVD2 0x20
  440. #define HPC_SLOT_BUS_MODE 0x40
  441. #define HPC_SLOT_RSRVD3 0x80
  442. //----------------------------------------------------------------------------
  443. // HPC_XSLOT_PCIX_CAP status return codes
  444. //----------------------------------------------------------------------------
  445. #define HPC_SLOT_PCIX_NO 0x00
  446. #define HPC_SLOT_PCIX_YES 0x01
  447. //----------------------------------------------------------------------------
  448. // HPC_XSLOT_SPEED status return codes
  449. //----------------------------------------------------------------------------
  450. #define HPC_SLOT_SPEED_33 0x00
  451. #define HPC_SLOT_SPEED_66 0x01
  452. #define HPC_SLOT_SPEED_133 0x02
  453. //----------------------------------------------------------------------------
  454. // HPC_XSLOT_ATTN_BLINK status return codes
  455. //----------------------------------------------------------------------------
  456. #define HPC_SLOT_ATTN_BLINK_OFF 0x00
  457. #define HPC_SLOT_ATTN_BLINK_ON 0x01
  458. //----------------------------------------------------------------------------
  459. // HPC_XSLOT_BUS_MODE status return codes
  460. //----------------------------------------------------------------------------
  461. #define HPC_SLOT_BUS_MODE_OK 0x00
  462. #define HPC_SLOT_BUS_MODE_MISM 0x01
  463. //----------------------------------------------------------------------------
  464. // Controller status
  465. //----------------------------------------------------------------------------
  466. #define HPC_CTLR_WORKING 0x01
  467. #define HPC_CTLR_FINISHED 0x02
  468. #define HPC_CTLR_RESULT0 0x04
  469. #define HPC_CTLR_RESULT1 0x08
  470. #define HPC_CTLR_RESULE2 0x10
  471. #define HPC_CTLR_RESULT3 0x20
  472. #define HPC_CTLR_IRQ_ROUTG 0x40
  473. #define HPC_CTLR_IRQ_PENDG 0x80
  474. //----------------------------------------------------------------------------
  475. // HPC_CTLR_WORKING status return codes
  476. //----------------------------------------------------------------------------
  477. #define HPC_CTLR_WORKING_NO 0x00
  478. #define HPC_CTLR_WORKING_YES 0x01
  479. //----------------------------------------------------------------------------
  480. // HPC_CTLR_FINISHED status return codes
  481. //----------------------------------------------------------------------------
  482. #define HPC_CTLR_FINISHED_NO 0x00
  483. #define HPC_CTLR_FINISHED_YES 0x01
  484. //----------------------------------------------------------------------------
  485. // HPC_CTLR_RESULT status return codes
  486. //----------------------------------------------------------------------------
  487. #define HPC_CTLR_RESULT_SUCCESS 0x00
  488. #define HPC_CTLR_RESULT_FAILED 0x01
  489. #define HPC_CTLR_RESULT_RSVD 0x02
  490. #define HPC_CTLR_RESULT_NORESP 0x03
  491. //----------------------------------------------------------------------------
  492. // macro for slot info
  493. //----------------------------------------------------------------------------
  494. #define SLOT_POWER(s) ((u8) ((s & HPC_SLOT_POWER) \
  495. ? HPC_SLOT_POWER_ON : HPC_SLOT_POWER_OFF))
  496. #define SLOT_CONNECT(s) ((u8) ((s & HPC_SLOT_CONNECT) \
  497. ? HPC_SLOT_DISCONNECTED : HPC_SLOT_CONNECTED))
  498. #define SLOT_ATTN(s, es) ((u8) ((es & HPC_SLOT_BLINK_ATTN) \
  499. ? HPC_SLOT_ATTN_BLINK \
  500. : ((s & HPC_SLOT_ATTN) ? HPC_SLOT_ATTN_ON : HPC_SLOT_ATTN_OFF)))
  501. #define SLOT_PRESENT(s) ((u8) ((s & HPC_SLOT_PRSNT1) \
  502. ? ((s & HPC_SLOT_PRSNT2) ? HPC_SLOT_EMPTY : HPC_SLOT_PRSNT_15) \
  503. : ((s & HPC_SLOT_PRSNT2) ? HPC_SLOT_PRSNT_25 : HPC_SLOT_PRSNT_7)))
  504. #define SLOT_PWRGD(s) ((u8) ((s & HPC_SLOT_PWRGD) \
  505. ? HPC_SLOT_PWRGD_GOOD : HPC_SLOT_PWRGD_FAULT_NONE))
  506. #define SLOT_BUS_SPEED(s) ((u8) ((s & HPC_SLOT_BUS_SPEED) \
  507. ? HPC_SLOT_BUS_SPEED_MISM : HPC_SLOT_BUS_SPEED_OK))
  508. #define SLOT_LATCH(s) ((u8) ((s & HPC_SLOT_LATCH) \
  509. ? HPC_SLOT_LATCH_CLOSED : HPC_SLOT_LATCH_OPEN))
  510. #define SLOT_PCIX(es) ((u8) ((es & HPC_SLOT_PCIX) \
  511. ? HPC_SLOT_PCIX_YES : HPC_SLOT_PCIX_NO))
  512. #define SLOT_SPEED(es) ((u8) ((es & HPC_SLOT_SPEED2) \
  513. ? ((es & HPC_SLOT_SPEED1) ? HPC_SLOT_SPEED_133 \
  514. : HPC_SLOT_SPEED_66) \
  515. : HPC_SLOT_SPEED_33))
  516. #define SLOT_BUS_MODE(es) ((u8) ((es & HPC_SLOT_BUS_MODE) \
  517. ? HPC_SLOT_BUS_MODE_MISM : HPC_SLOT_BUS_MODE_OK))
  518. //--------------------------------------------------------------------------
  519. // macro for bus info
  520. //---------------------------------------------------------------------------
  521. #define CURRENT_BUS_SPEED(s) ((u8) (s & BUS_SPEED_2) \
  522. ? ((s & BUS_SPEED_1) ? BUS_SPEED_133 : BUS_SPEED_100) \
  523. : ((s & BUS_SPEED_1) ? BUS_SPEED_66 : BUS_SPEED_33))
  524. #define CURRENT_BUS_MODE(s) ((u8) (s & BUS_MODE) ? BUS_MODE_PCIX : BUS_MODE_PCI)
  525. #define READ_BUS_STATUS(s) ((u8) (s->options & BUS_STATUS_AVAILABLE))
  526. #define READ_BUS_MODE(s) ((s->revision & PRGM_MODEL_REV_LEVEL) >= 0x20)
  527. #define SET_BUS_STATUS(s) ((u8) (s->options & BUS_CONTROL_AVAILABLE))
  528. #define READ_SLOT_LATCH(s) ((u8) (s->options & SLOT_LATCH_REGS_SUPPORTED))
  529. //----------------------------------------------------------------------------
  530. // macro for controller info
  531. //----------------------------------------------------------------------------
  532. #define CTLR_WORKING(c) ((u8) ((c & HPC_CTLR_WORKING) \
  533. ? HPC_CTLR_WORKING_YES : HPC_CTLR_WORKING_NO))
  534. #define CTLR_FINISHED(c) ((u8) ((c & HPC_CTLR_FINISHED) \
  535. ? HPC_CTLR_FINISHED_YES : HPC_CTLR_FINISHED_NO))
  536. #define CTLR_RESULT(c) ((u8) ((c & HPC_CTLR_RESULT1) \
  537. ? ((c & HPC_CTLR_RESULT0) ? HPC_CTLR_RESULT_NORESP \
  538. : HPC_CTLR_RESULT_RSVD) \
  539. : ((c & HPC_CTLR_RESULT0) ? HPC_CTLR_RESULT_FAILED \
  540. : HPC_CTLR_RESULT_SUCCESS)))
  541. // command that affect the state machine of HPC
  542. #define NEEDTOCHECK_CMDSTATUS(c) ((c == HPC_SLOT_OFF) || \
  543. (c == HPC_SLOT_ON) || \
  544. (c == HPC_CTLR_RESET) || \
  545. (c == HPC_BUS_33CONVMODE) || \
  546. (c == HPC_BUS_66CONVMODE) || \
  547. (c == HPC_BUS_66PCIXMODE) || \
  548. (c == HPC_BUS_100PCIXMODE) || \
  549. (c == HPC_BUS_133PCIXMODE) || \
  550. (c == HPC_ALLSLOT_OFF) || \
  551. (c == HPC_ALLSLOT_ON))
  552. /* Core part of the driver */
  553. #define ENABLE 1
  554. #define DISABLE 0
  555. #define CARD_INFO 0x07
  556. #define PCIX133 0x07
  557. #define PCIX66 0x05
  558. #define PCI66 0x04
  559. extern struct pci_bus *ibmphp_pci_bus;
  560. /* Variables */
  561. struct pci_func {
  562. struct pci_dev *dev; /* from the OS */
  563. u8 busno;
  564. u8 device;
  565. u8 function;
  566. struct resource_node *io[6];
  567. struct resource_node *mem[6];
  568. struct resource_node *pfmem[6];
  569. struct pci_func *next;
  570. int devices[32]; /* for bridge config */
  571. u8 irq[4]; /* for interrupt config */
  572. u8 bus; /* flag for unconfiguring, to say if PPB */
  573. };
  574. struct slot {
  575. u8 bus;
  576. u8 device;
  577. u8 number;
  578. u8 real_physical_slot_num;
  579. u32 capabilities;
  580. u8 supported_speed;
  581. u8 supported_bus_mode;
  582. u8 flag; /* this is for disable slot and polling */
  583. u8 ctlr_index;
  584. struct hotplug_slot hotplug_slot;
  585. struct controller *ctrl;
  586. struct pci_func *func;
  587. u8 irq[4];
  588. int bit_mode; /* 0 = 32, 1 = 64 */
  589. struct bus_info *bus_on;
  590. struct list_head ibm_slot_list;
  591. u8 status;
  592. u8 ext_status;
  593. u8 busstatus;
  594. };
  595. struct controller {
  596. struct ebda_hpc_slot *slots;
  597. struct ebda_hpc_bus *buses;
  598. struct pci_dev *ctrl_dev; /* in case where controller is PCI */
  599. u8 starting_slot_num; /* starting and ending slot #'s this ctrl controls*/
  600. u8 ending_slot_num;
  601. u8 revision;
  602. u8 options; /* which options HPC supports */
  603. u8 status;
  604. u8 ctlr_id;
  605. u8 slot_count;
  606. u8 bus_count;
  607. u8 ctlr_relative_id;
  608. u32 irq;
  609. union {
  610. struct isa_ctlr_access isa_ctlr;
  611. struct pci_ctlr_access pci_ctlr;
  612. struct wpeg_i2c_ctlr_access wpeg_ctlr;
  613. } u;
  614. u8 ctlr_type;
  615. struct list_head ebda_hpc_list;
  616. };
  617. /* Functions */
  618. int ibmphp_init_devno(struct slot **); /* This function is called from EBDA, so we need it not be static */
  619. int ibmphp_do_disable_slot(struct slot *slot_cur);
  620. int ibmphp_update_slot_info(struct slot *); /* This function is called from HPC, so we need it to not be static */
  621. int ibmphp_configure_card(struct pci_func *, u8);
  622. int ibmphp_unconfigure_card(struct slot **, int);
  623. extern const struct hotplug_slot_ops ibmphp_hotplug_slot_ops;
  624. static inline struct slot *to_slot(struct hotplug_slot *hotplug_slot)
  625. {
  626. return container_of(hotplug_slot, struct slot, hotplug_slot);
  627. }
  628. #endif //__IBMPHP_H