cpqphp_core.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541
  1. /*
  2. * Compaq Hot Plug Controller Driver
  3. *
  4. * Copyright (C) 1995,2001 Compaq Computer Corporation
  5. * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
  6. * Copyright (C) 2001 IBM Corp.
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  18. * NON INFRINGEMENT. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Send feedback to <greg@kroah.com>
  26. *
  27. * Jan 12, 2003 - Added 66/100/133MHz PCI-X support,
  28. * Torben Mathiasen <torben.mathiasen@hp.com>
  29. *
  30. */
  31. #include <linux/config.h>
  32. #include <linux/module.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/kernel.h>
  35. #include <linux/types.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/slab.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/pci.h>
  40. #include <linux/init.h>
  41. #include <linux/interrupt.h>
  42. #include <asm/uaccess.h>
  43. #include "cpqphp.h"
  44. #include "cpqphp_nvram.h"
  45. #include "../../../arch/i386/pci/pci.h" /* horrible hack showing how processor dependent we are... */
  46. /* Global variables */
  47. int cpqhp_debug;
  48. int cpqhp_legacy_mode;
  49. struct controller *cpqhp_ctrl_list; /* = NULL */
  50. struct pci_func *cpqhp_slot_list[256];
  51. /* local variables */
  52. static void __iomem *smbios_table;
  53. static void __iomem *smbios_start;
  54. static void __iomem *cpqhp_rom_start;
  55. static int power_mode;
  56. static int debug;
  57. static int initialized;
  58. #define DRIVER_VERSION "0.9.8"
  59. #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
  60. #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
  61. MODULE_AUTHOR(DRIVER_AUTHOR);
  62. MODULE_DESCRIPTION(DRIVER_DESC);
  63. MODULE_LICENSE("GPL");
  64. module_param(power_mode, bool, 0644);
  65. MODULE_PARM_DESC(power_mode, "Power mode enabled or not");
  66. module_param(debug, bool, 0644);
  67. MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
  68. #define CPQHPC_MODULE_MINOR 208
  69. static int one_time_init (void);
  70. static int set_attention_status (struct hotplug_slot *slot, u8 value);
  71. static int process_SI (struct hotplug_slot *slot);
  72. static int process_SS (struct hotplug_slot *slot);
  73. static int hardware_test (struct hotplug_slot *slot, u32 value);
  74. static int get_power_status (struct hotplug_slot *slot, u8 *value);
  75. static int get_attention_status (struct hotplug_slot *slot, u8 *value);
  76. static int get_latch_status (struct hotplug_slot *slot, u8 *value);
  77. static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
  78. static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
  79. static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
  80. static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
  81. .owner = THIS_MODULE,
  82. .set_attention_status = set_attention_status,
  83. .enable_slot = process_SI,
  84. .disable_slot = process_SS,
  85. .hardware_test = hardware_test,
  86. .get_power_status = get_power_status,
  87. .get_attention_status = get_attention_status,
  88. .get_latch_status = get_latch_status,
  89. .get_adapter_status = get_adapter_status,
  90. .get_max_bus_speed = get_max_bus_speed,
  91. .get_cur_bus_speed = get_cur_bus_speed,
  92. };
  93. static inline int is_slot64bit(struct slot *slot)
  94. {
  95. return (readb(slot->p_sm_slot + SMBIOS_SLOT_WIDTH) == 0x06) ? 1 : 0;
  96. }
  97. static inline int is_slot66mhz(struct slot *slot)
  98. {
  99. return (readb(slot->p_sm_slot + SMBIOS_SLOT_TYPE) == 0x0E) ? 1 : 0;
  100. }
  101. /**
  102. * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region.
  103. *
  104. * @begin: begin pointer for region to be scanned.
  105. * @end: end pointer for region to be scanned.
  106. *
  107. * Returns pointer to the head of the SMBIOS tables (or NULL)
  108. *
  109. */
  110. static void __iomem * detect_SMBIOS_pointer(void __iomem *begin, void __iomem *end)
  111. {
  112. void __iomem *fp;
  113. void __iomem *endp;
  114. u8 temp1, temp2, temp3, temp4;
  115. int status = 0;
  116. endp = (end - sizeof(u32) + 1);
  117. for (fp = begin; fp <= endp; fp += 16) {
  118. temp1 = readb(fp);
  119. temp2 = readb(fp+1);
  120. temp3 = readb(fp+2);
  121. temp4 = readb(fp+3);
  122. if (temp1 == '_' &&
  123. temp2 == 'S' &&
  124. temp3 == 'M' &&
  125. temp4 == '_') {
  126. status = 1;
  127. break;
  128. }
  129. }
  130. if (!status)
  131. fp = NULL;
  132. dbg("Discovered SMBIOS Entry point at %p\n", fp);
  133. return fp;
  134. }
  135. /**
  136. * init_SERR - Initializes the per slot SERR generation.
  137. *
  138. * For unexpected switch opens
  139. *
  140. */
  141. static int init_SERR(struct controller * ctrl)
  142. {
  143. u32 tempdword;
  144. u32 number_of_slots;
  145. u8 physical_slot;
  146. if (!ctrl)
  147. return 1;
  148. tempdword = ctrl->first_slot;
  149. number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  150. // Loop through slots
  151. while (number_of_slots) {
  152. physical_slot = tempdword;
  153. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  154. tempdword++;
  155. number_of_slots--;
  156. }
  157. return 0;
  158. }
  159. /* nice debugging output */
  160. static int pci_print_IRQ_route (void)
  161. {
  162. struct irq_routing_table *routing_table;
  163. int len;
  164. int loop;
  165. u8 tbus, tdevice, tslot;
  166. routing_table = pcibios_get_irq_routing_table();
  167. if (routing_table == NULL) {
  168. err("No BIOS Routing Table??? Not good\n");
  169. return -ENOMEM;
  170. }
  171. len = (routing_table->size - sizeof(struct irq_routing_table)) /
  172. sizeof(struct irq_info);
  173. // Make sure I got at least one entry
  174. if (len == 0) {
  175. kfree(routing_table);
  176. return -1;
  177. }
  178. dbg("bus dev func slot\n");
  179. for (loop = 0; loop < len; ++loop) {
  180. tbus = routing_table->slots[loop].bus;
  181. tdevice = routing_table->slots[loop].devfn;
  182. tslot = routing_table->slots[loop].slot;
  183. dbg("%d %d %d %d\n", tbus, tdevice >> 3, tdevice & 0x7, tslot);
  184. }
  185. kfree(routing_table);
  186. return 0;
  187. }
  188. /**
  189. * get_subsequent_smbios_entry: get the next entry from bios table.
  190. *
  191. * Gets the first entry if previous == NULL
  192. * Otherwise, returns the next entry
  193. * Uses global SMBIOS Table pointer
  194. *
  195. * @curr: %NULL or pointer to previously returned structure
  196. *
  197. * returns a pointer to an SMBIOS structure or NULL if none found
  198. */
  199. static void __iomem *get_subsequent_smbios_entry(void __iomem *smbios_start,
  200. void __iomem *smbios_table,
  201. void __iomem *curr)
  202. {
  203. u8 bail = 0;
  204. u8 previous_byte = 1;
  205. void __iomem *p_temp;
  206. void __iomem *p_max;
  207. if (!smbios_table || !curr)
  208. return(NULL);
  209. // set p_max to the end of the table
  210. p_max = smbios_start + readw(smbios_table + ST_LENGTH);
  211. p_temp = curr;
  212. p_temp += readb(curr + SMBIOS_GENERIC_LENGTH);
  213. while ((p_temp < p_max) && !bail) {
  214. /* Look for the double NULL terminator
  215. * The first condition is the previous byte
  216. * and the second is the curr */
  217. if (!previous_byte && !(readb(p_temp))) {
  218. bail = 1;
  219. }
  220. previous_byte = readb(p_temp);
  221. p_temp++;
  222. }
  223. if (p_temp < p_max) {
  224. return p_temp;
  225. } else {
  226. return NULL;
  227. }
  228. }
  229. /**
  230. * get_SMBIOS_entry
  231. *
  232. * @type:SMBIOS structure type to be returned
  233. * @previous: %NULL or pointer to previously returned structure
  234. *
  235. * Gets the first entry of the specified type if previous == NULL
  236. * Otherwise, returns the next entry of the given type.
  237. * Uses global SMBIOS Table pointer
  238. * Uses get_subsequent_smbios_entry
  239. *
  240. * returns a pointer to an SMBIOS structure or %NULL if none found
  241. */
  242. static void __iomem *get_SMBIOS_entry(void __iomem *smbios_start,
  243. void __iomem *smbios_table,
  244. u8 type,
  245. void __iomem *previous)
  246. {
  247. if (!smbios_table)
  248. return NULL;
  249. if (!previous) {
  250. previous = smbios_start;
  251. } else {
  252. previous = get_subsequent_smbios_entry(smbios_start,
  253. smbios_table, previous);
  254. }
  255. while (previous) {
  256. if (readb(previous + SMBIOS_GENERIC_TYPE) != type) {
  257. previous = get_subsequent_smbios_entry(smbios_start,
  258. smbios_table, previous);
  259. } else {
  260. break;
  261. }
  262. }
  263. return previous;
  264. }
  265. static void release_slot(struct hotplug_slot *hotplug_slot)
  266. {
  267. struct slot *slot = hotplug_slot->private;
  268. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  269. kfree(slot->hotplug_slot->info);
  270. kfree(slot->hotplug_slot->name);
  271. kfree(slot->hotplug_slot);
  272. kfree(slot);
  273. }
  274. static int ctrl_slot_setup(struct controller *ctrl,
  275. void __iomem *smbios_start,
  276. void __iomem *smbios_table)
  277. {
  278. struct slot *slot;
  279. struct hotplug_slot *hotplug_slot;
  280. struct hotplug_slot_info *hotplug_slot_info;
  281. u8 number_of_slots;
  282. u8 slot_device;
  283. u8 slot_number;
  284. u8 ctrl_slot;
  285. u32 tempdword;
  286. void __iomem *slot_entry= NULL;
  287. int result = -ENOMEM;
  288. dbg("%s\n", __FUNCTION__);
  289. tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  290. number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  291. slot_device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  292. slot_number = ctrl->first_slot;
  293. while (number_of_slots) {
  294. slot = kmalloc(sizeof(*slot), GFP_KERNEL);
  295. if (!slot)
  296. goto error;
  297. memset(slot, 0, sizeof(struct slot));
  298. slot->hotplug_slot = kmalloc(sizeof(*(slot->hotplug_slot)),
  299. GFP_KERNEL);
  300. if (!slot->hotplug_slot)
  301. goto error_slot;
  302. hotplug_slot = slot->hotplug_slot;
  303. memset(hotplug_slot, 0, sizeof(struct hotplug_slot));
  304. hotplug_slot->info =
  305. kmalloc(sizeof(*(hotplug_slot->info)),
  306. GFP_KERNEL);
  307. if (!hotplug_slot->info)
  308. goto error_hpslot;
  309. hotplug_slot_info = hotplug_slot->info;
  310. memset(hotplug_slot_info, 0,
  311. sizeof(struct hotplug_slot_info));
  312. hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
  313. if (!hotplug_slot->name)
  314. goto error_info;
  315. slot->ctrl = ctrl;
  316. slot->bus = ctrl->bus;
  317. slot->device = slot_device;
  318. slot->number = slot_number;
  319. dbg("slot->number = %d\n", slot->number);
  320. slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
  321. slot_entry);
  322. while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) !=
  323. slot->number)) {
  324. slot_entry = get_SMBIOS_entry(smbios_start,
  325. smbios_table, 9, slot_entry);
  326. }
  327. slot->p_sm_slot = slot_entry;
  328. init_timer(&slot->task_event);
  329. slot->task_event.expires = jiffies + 5 * HZ;
  330. slot->task_event.function = cpqhp_pushbutton_thread;
  331. //FIXME: these capabilities aren't used but if they are
  332. // they need to be correctly implemented
  333. slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
  334. slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
  335. if (is_slot64bit(slot))
  336. slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
  337. if (is_slot66mhz(slot))
  338. slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
  339. if (ctrl->speed == PCI_SPEED_66MHz)
  340. slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
  341. ctrl_slot =
  342. slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
  343. // Check presence
  344. slot->capabilities |=
  345. ((((~tempdword) >> 23) |
  346. ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
  347. // Check the switch state
  348. slot->capabilities |=
  349. ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
  350. // Check the slot enable
  351. slot->capabilities |=
  352. ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
  353. /* register this slot with the hotplug pci core */
  354. hotplug_slot->release = &release_slot;
  355. hotplug_slot->private = slot;
  356. make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot);
  357. hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
  358. hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
  359. hotplug_slot_info->attention_status =
  360. cpq_get_attention_status(ctrl, slot);
  361. hotplug_slot_info->latch_status =
  362. cpq_get_latch_status(ctrl, slot);
  363. hotplug_slot_info->adapter_status =
  364. get_presence_status(ctrl, slot);
  365. dbg("registering bus %d, dev %d, number %d, "
  366. "ctrl->slot_device_offset %d, slot %d\n",
  367. slot->bus, slot->device,
  368. slot->number, ctrl->slot_device_offset,
  369. slot_number);
  370. result = pci_hp_register(hotplug_slot);
  371. if (result) {
  372. err("pci_hp_register failed with error %d\n", result);
  373. goto error_name;
  374. }
  375. slot->next = ctrl->slot;
  376. ctrl->slot = slot;
  377. number_of_slots--;
  378. slot_device++;
  379. slot_number++;
  380. }
  381. return 0;
  382. error_name:
  383. kfree(hotplug_slot->name);
  384. error_info:
  385. kfree(hotplug_slot_info);
  386. error_hpslot:
  387. kfree(hotplug_slot);
  388. error_slot:
  389. kfree(slot);
  390. error:
  391. return result;
  392. }
  393. static int ctrl_slot_cleanup (struct controller * ctrl)
  394. {
  395. struct slot *old_slot, *next_slot;
  396. old_slot = ctrl->slot;
  397. ctrl->slot = NULL;
  398. while (old_slot) {
  399. /* memory will be freed by the release_slot callback */
  400. next_slot = old_slot->next;
  401. pci_hp_deregister (old_slot->hotplug_slot);
  402. old_slot = next_slot;
  403. }
  404. cpqhp_remove_debugfs_files(ctrl);
  405. //Free IRQ associated with hot plug device
  406. free_irq(ctrl->interrupt, ctrl);
  407. //Unmap the memory
  408. iounmap(ctrl->hpc_reg);
  409. //Finally reclaim PCI mem
  410. release_mem_region(pci_resource_start(ctrl->pci_dev, 0),
  411. pci_resource_len(ctrl->pci_dev, 0));
  412. return(0);
  413. }
  414. //============================================================================
  415. // function: get_slot_mapping
  416. //
  417. // Description: Attempts to determine a logical slot mapping for a PCI
  418. // device. Won't work for more than one PCI-PCI bridge
  419. // in a slot.
  420. //
  421. // Input: u8 bus_num - bus number of PCI device
  422. // u8 dev_num - device number of PCI device
  423. // u8 *slot - Pointer to u8 where slot number will
  424. // be returned
  425. //
  426. // Output: SUCCESS or FAILURE
  427. //=============================================================================
  428. static int
  429. get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
  430. {
  431. struct irq_routing_table *PCIIRQRoutingInfoLength;
  432. u32 work;
  433. long len;
  434. long loop;
  435. u8 tbus, tdevice, tslot, bridgeSlot;
  436. dbg("%s: %p, %d, %d, %p\n", __FUNCTION__, bus, bus_num, dev_num, slot);
  437. bridgeSlot = 0xFF;
  438. PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
  439. if (!PCIIRQRoutingInfoLength)
  440. return -1;
  441. len = (PCIIRQRoutingInfoLength->size -
  442. sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
  443. // Make sure I got at least one entry
  444. if (len == 0) {
  445. kfree(PCIIRQRoutingInfoLength);
  446. return -1;
  447. }
  448. for (loop = 0; loop < len; ++loop) {
  449. tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
  450. tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn >> 3;
  451. tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
  452. if ((tbus == bus_num) && (tdevice == dev_num)) {
  453. *slot = tslot;
  454. kfree(PCIIRQRoutingInfoLength);
  455. return 0;
  456. } else {
  457. /* Did not get a match on the target PCI device. Check
  458. * if the current IRQ table entry is a PCI-to-PCI bridge
  459. * device. If so, and it's secondary bus matches the
  460. * bus number for the target device, I need to save the
  461. * bridge's slot number. If I can not find an entry for
  462. * the target device, I will have to assume it's on the
  463. * other side of the bridge, and assign it the bridge's
  464. * slot. */
  465. bus->number = tbus;
  466. pci_bus_read_config_dword(bus, PCI_DEVFN(tdevice, 0),
  467. PCI_REVISION_ID, &work);
  468. if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
  469. pci_bus_read_config_dword(bus,
  470. PCI_DEVFN(tdevice, 0),
  471. PCI_PRIMARY_BUS, &work);
  472. // See if bridge's secondary bus matches target bus.
  473. if (((work >> 8) & 0x000000FF) == (long) bus_num) {
  474. bridgeSlot = tslot;
  475. }
  476. }
  477. }
  478. }
  479. // If we got here, we didn't find an entry in the IRQ mapping table
  480. // for the target PCI device. If we did determine that the target
  481. // device is on the other side of a PCI-to-PCI bridge, return the
  482. // slot number for the bridge.
  483. if (bridgeSlot != 0xFF) {
  484. *slot = bridgeSlot;
  485. kfree(PCIIRQRoutingInfoLength);
  486. return 0;
  487. }
  488. kfree(PCIIRQRoutingInfoLength);
  489. // Couldn't find an entry in the routing table for this PCI device
  490. return -1;
  491. }
  492. /**
  493. * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
  494. *
  495. */
  496. static int
  497. cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
  498. u32 status)
  499. {
  500. u8 hp_slot;
  501. if (func == NULL)
  502. return(1);
  503. hp_slot = func->device - ctrl->slot_device_offset;
  504. // Wait for exclusive access to hardware
  505. down(&ctrl->crit_sect);
  506. if (status == 1) {
  507. amber_LED_on (ctrl, hp_slot);
  508. } else if (status == 0) {
  509. amber_LED_off (ctrl, hp_slot);
  510. } else {
  511. // Done with exclusive hardware access
  512. up(&ctrl->crit_sect);
  513. return(1);
  514. }
  515. set_SOGO(ctrl);
  516. // Wait for SOBS to be unset
  517. wait_for_ctrl_irq (ctrl);
  518. // Done with exclusive hardware access
  519. up(&ctrl->crit_sect);
  520. return(0);
  521. }
  522. /**
  523. * set_attention_status - Turns the Amber LED for a slot on or off
  524. *
  525. */
  526. static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
  527. {
  528. struct pci_func *slot_func;
  529. struct slot *slot = hotplug_slot->private;
  530. struct controller *ctrl = slot->ctrl;
  531. u8 bus;
  532. u8 devfn;
  533. u8 device;
  534. u8 function;
  535. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  536. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  537. return -ENODEV;
  538. device = devfn >> 3;
  539. function = devfn & 0x7;
  540. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  541. slot_func = cpqhp_slot_find(bus, device, function);
  542. if (!slot_func)
  543. return -ENODEV;
  544. return cpqhp_set_attention_status(ctrl, slot_func, status);
  545. }
  546. static int process_SI(struct hotplug_slot *hotplug_slot)
  547. {
  548. struct pci_func *slot_func;
  549. struct slot *slot = hotplug_slot->private;
  550. struct controller *ctrl = slot->ctrl;
  551. u8 bus;
  552. u8 devfn;
  553. u8 device;
  554. u8 function;
  555. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  556. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  557. return -ENODEV;
  558. device = devfn >> 3;
  559. function = devfn & 0x7;
  560. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  561. slot_func = cpqhp_slot_find(bus, device, function);
  562. if (!slot_func)
  563. return -ENODEV;
  564. slot_func->bus = bus;
  565. slot_func->device = device;
  566. slot_func->function = function;
  567. slot_func->configured = 0;
  568. dbg("board_added(%p, %p)\n", slot_func, ctrl);
  569. return cpqhp_process_SI(ctrl, slot_func);
  570. }
  571. static int process_SS(struct hotplug_slot *hotplug_slot)
  572. {
  573. struct pci_func *slot_func;
  574. struct slot *slot = hotplug_slot->private;
  575. struct controller *ctrl = slot->ctrl;
  576. u8 bus;
  577. u8 devfn;
  578. u8 device;
  579. u8 function;
  580. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  581. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  582. return -ENODEV;
  583. device = devfn >> 3;
  584. function = devfn & 0x7;
  585. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  586. slot_func = cpqhp_slot_find(bus, device, function);
  587. if (!slot_func)
  588. return -ENODEV;
  589. dbg("In %s, slot_func = %p, ctrl = %p\n", __FUNCTION__, slot_func, ctrl);
  590. return cpqhp_process_SS(ctrl, slot_func);
  591. }
  592. static int hardware_test(struct hotplug_slot *hotplug_slot, u32 value)
  593. {
  594. struct slot *slot = hotplug_slot->private;
  595. struct controller *ctrl = slot->ctrl;
  596. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  597. return cpqhp_hardware_test(ctrl, value);
  598. }
  599. static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
  600. {
  601. struct slot *slot = hotplug_slot->private;
  602. struct controller *ctrl = slot->ctrl;
  603. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  604. *value = get_slot_enabled(ctrl, slot);
  605. return 0;
  606. }
  607. static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
  608. {
  609. struct slot *slot = hotplug_slot->private;
  610. struct controller *ctrl = slot->ctrl;
  611. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  612. *value = cpq_get_attention_status(ctrl, slot);
  613. return 0;
  614. }
  615. static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
  616. {
  617. struct slot *slot = hotplug_slot->private;
  618. struct controller *ctrl = slot->ctrl;
  619. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  620. *value = cpq_get_latch_status(ctrl, slot);
  621. return 0;
  622. }
  623. static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
  624. {
  625. struct slot *slot = hotplug_slot->private;
  626. struct controller *ctrl = slot->ctrl;
  627. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  628. *value = get_presence_status(ctrl, slot);
  629. return 0;
  630. }
  631. static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  632. {
  633. struct slot *slot = hotplug_slot->private;
  634. struct controller *ctrl = slot->ctrl;
  635. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  636. *value = ctrl->speed_capability;
  637. return 0;
  638. }
  639. static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  640. {
  641. struct slot *slot = hotplug_slot->private;
  642. struct controller *ctrl = slot->ctrl;
  643. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  644. *value = ctrl->speed;
  645. return 0;
  646. }
  647. static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  648. {
  649. u8 num_of_slots = 0;
  650. u8 hp_slot = 0;
  651. u8 device;
  652. u8 rev;
  653. u8 bus_cap;
  654. u16 temp_word;
  655. u16 vendor_id;
  656. u16 subsystem_vid;
  657. u16 subsystem_deviceid;
  658. u32 rc;
  659. struct controller *ctrl;
  660. struct pci_func *func;
  661. int err;
  662. err = pci_enable_device(pdev);
  663. if (err) {
  664. printk(KERN_ERR MY_NAME ": cannot enable PCI device %s (%d)\n",
  665. pci_name(pdev), err);
  666. return err;
  667. }
  668. // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery
  669. rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);
  670. if (rc || ((vendor_id != PCI_VENDOR_ID_COMPAQ) && (vendor_id != PCI_VENDOR_ID_INTEL))) {
  671. err(msg_HPC_non_compaq_or_intel);
  672. rc = -ENODEV;
  673. goto err_disable_device;
  674. }
  675. dbg("Vendor ID: %x\n", vendor_id);
  676. rc = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  677. dbg("revision: %d\n", rev);
  678. if (rc || ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!rev))) {
  679. err(msg_HPC_rev_error);
  680. rc = -ENODEV;
  681. goto err_disable_device;
  682. }
  683. /* Check for the proper subsytem ID's
  684. * Intel uses a different SSID programming model than Compaq.
  685. * For Intel, each SSID bit identifies a PHP capability.
  686. * Also Intel HPC's may have RID=0.
  687. */
  688. if ((rev > 2) || (vendor_id == PCI_VENDOR_ID_INTEL)) {
  689. // TODO: This code can be made to support non-Compaq or Intel subsystem IDs
  690. rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid);
  691. if (rc) {
  692. err("%s : pci_read_config_word failed\n", __FUNCTION__);
  693. goto err_disable_device;
  694. }
  695. dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
  696. if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
  697. err(msg_HPC_non_compaq_or_intel);
  698. rc = -ENODEV;
  699. goto err_disable_device;
  700. }
  701. ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
  702. if (!ctrl) {
  703. err("%s : out of memory\n", __FUNCTION__);
  704. rc = -ENOMEM;
  705. goto err_disable_device;
  706. }
  707. memset(ctrl, 0, sizeof(struct controller));
  708. rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
  709. if (rc) {
  710. err("%s : pci_read_config_word failed\n", __FUNCTION__);
  711. goto err_free_ctrl;
  712. }
  713. info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
  714. /* Set Vendor ID, so it can be accessed later from other functions */
  715. ctrl->vendor_id = vendor_id;
  716. switch (subsystem_vid) {
  717. case PCI_VENDOR_ID_COMPAQ:
  718. if (rev >= 0x13) { /* CIOBX */
  719. ctrl->push_flag = 1;
  720. ctrl->slot_switch_type = 1;
  721. ctrl->push_button = 1;
  722. ctrl->pci_config_space = 1;
  723. ctrl->defeature_PHP = 1;
  724. ctrl->pcix_support = 1;
  725. ctrl->pcix_speed_capability = 1;
  726. pci_read_config_byte(pdev, 0x41, &bus_cap);
  727. if (bus_cap & 0x80) {
  728. dbg("bus max supports 133MHz PCI-X\n");
  729. ctrl->speed_capability = PCI_SPEED_133MHz_PCIX;
  730. break;
  731. }
  732. if (bus_cap & 0x40) {
  733. dbg("bus max supports 100MHz PCI-X\n");
  734. ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
  735. break;
  736. }
  737. if (bus_cap & 20) {
  738. dbg("bus max supports 66MHz PCI-X\n");
  739. ctrl->speed_capability = PCI_SPEED_66MHz_PCIX;
  740. break;
  741. }
  742. if (bus_cap & 10) {
  743. dbg("bus max supports 66MHz PCI\n");
  744. ctrl->speed_capability = PCI_SPEED_66MHz;
  745. break;
  746. }
  747. break;
  748. }
  749. switch (subsystem_deviceid) {
  750. case PCI_SUB_HPC_ID:
  751. /* Original 6500/7000 implementation */
  752. ctrl->slot_switch_type = 1;
  753. ctrl->speed_capability = PCI_SPEED_33MHz;
  754. ctrl->push_button = 0;
  755. ctrl->pci_config_space = 1;
  756. ctrl->defeature_PHP = 1;
  757. ctrl->pcix_support = 0;
  758. ctrl->pcix_speed_capability = 0;
  759. break;
  760. case PCI_SUB_HPC_ID2:
  761. /* First Pushbutton implementation */
  762. ctrl->push_flag = 1;
  763. ctrl->slot_switch_type = 1;
  764. ctrl->speed_capability = PCI_SPEED_33MHz;
  765. ctrl->push_button = 1;
  766. ctrl->pci_config_space = 1;
  767. ctrl->defeature_PHP = 1;
  768. ctrl->pcix_support = 0;
  769. ctrl->pcix_speed_capability = 0;
  770. break;
  771. case PCI_SUB_HPC_ID_INTC:
  772. /* Third party (6500/7000) */
  773. ctrl->slot_switch_type = 1;
  774. ctrl->speed_capability = PCI_SPEED_33MHz;
  775. ctrl->push_button = 0;
  776. ctrl->pci_config_space = 1;
  777. ctrl->defeature_PHP = 1;
  778. ctrl->pcix_support = 0;
  779. ctrl->pcix_speed_capability = 0;
  780. break;
  781. case PCI_SUB_HPC_ID3:
  782. /* First 66 Mhz implementation */
  783. ctrl->push_flag = 1;
  784. ctrl->slot_switch_type = 1;
  785. ctrl->speed_capability = PCI_SPEED_66MHz;
  786. ctrl->push_button = 1;
  787. ctrl->pci_config_space = 1;
  788. ctrl->defeature_PHP = 1;
  789. ctrl->pcix_support = 0;
  790. ctrl->pcix_speed_capability = 0;
  791. break;
  792. case PCI_SUB_HPC_ID4:
  793. /* First PCI-X implementation, 100MHz */
  794. ctrl->push_flag = 1;
  795. ctrl->slot_switch_type = 1;
  796. ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
  797. ctrl->push_button = 1;
  798. ctrl->pci_config_space = 1;
  799. ctrl->defeature_PHP = 1;
  800. ctrl->pcix_support = 1;
  801. ctrl->pcix_speed_capability = 0;
  802. break;
  803. default:
  804. err(msg_HPC_not_supported);
  805. rc = -ENODEV;
  806. goto err_free_ctrl;
  807. }
  808. break;
  809. case PCI_VENDOR_ID_INTEL:
  810. /* Check for speed capability (0=33, 1=66) */
  811. if (subsystem_deviceid & 0x0001) {
  812. ctrl->speed_capability = PCI_SPEED_66MHz;
  813. } else {
  814. ctrl->speed_capability = PCI_SPEED_33MHz;
  815. }
  816. /* Check for push button */
  817. if (subsystem_deviceid & 0x0002) {
  818. /* no push button */
  819. ctrl->push_button = 0;
  820. } else {
  821. /* push button supported */
  822. ctrl->push_button = 1;
  823. }
  824. /* Check for slot switch type (0=mechanical, 1=not mechanical) */
  825. if (subsystem_deviceid & 0x0004) {
  826. /* no switch */
  827. ctrl->slot_switch_type = 0;
  828. } else {
  829. /* switch */
  830. ctrl->slot_switch_type = 1;
  831. }
  832. /* PHP Status (0=De-feature PHP, 1=Normal operation) */
  833. if (subsystem_deviceid & 0x0008) {
  834. ctrl->defeature_PHP = 1; // PHP supported
  835. } else {
  836. ctrl->defeature_PHP = 0; // PHP not supported
  837. }
  838. /* Alternate Base Address Register Interface (0=not supported, 1=supported) */
  839. if (subsystem_deviceid & 0x0010) {
  840. ctrl->alternate_base_address = 1; // supported
  841. } else {
  842. ctrl->alternate_base_address = 0; // not supported
  843. }
  844. /* PCI Config Space Index (0=not supported, 1=supported) */
  845. if (subsystem_deviceid & 0x0020) {
  846. ctrl->pci_config_space = 1; // supported
  847. } else {
  848. ctrl->pci_config_space = 0; // not supported
  849. }
  850. /* PCI-X support */
  851. if (subsystem_deviceid & 0x0080) {
  852. /* PCI-X capable */
  853. ctrl->pcix_support = 1;
  854. /* Frequency of operation in PCI-X mode */
  855. if (subsystem_deviceid & 0x0040) {
  856. /* 133MHz PCI-X if bit 7 is 1 */
  857. ctrl->pcix_speed_capability = 1;
  858. } else {
  859. /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
  860. /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
  861. ctrl->pcix_speed_capability = 0;
  862. }
  863. } else {
  864. /* Conventional PCI */
  865. ctrl->pcix_support = 0;
  866. ctrl->pcix_speed_capability = 0;
  867. }
  868. break;
  869. default:
  870. err(msg_HPC_not_supported);
  871. rc = -ENODEV;
  872. goto err_free_ctrl;
  873. }
  874. } else {
  875. err(msg_HPC_not_supported);
  876. return -ENODEV;
  877. }
  878. // Tell the user that we found one.
  879. info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
  880. pdev->bus->number);
  881. dbg("Hotplug controller capabilities:\n");
  882. dbg(" speed_capability %d\n", ctrl->speed_capability);
  883. dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ?
  884. "switch present" : "no switch");
  885. dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ?
  886. "PHP supported" : "PHP not supported");
  887. dbg(" alternate_base_address %s\n", ctrl->alternate_base_address ?
  888. "supported" : "not supported");
  889. dbg(" pci_config_space %s\n", ctrl->pci_config_space ?
  890. "supported" : "not supported");
  891. dbg(" pcix_speed_capability %s\n", ctrl->pcix_speed_capability ?
  892. "supported" : "not supported");
  893. dbg(" pcix_support %s\n", ctrl->pcix_support ?
  894. "supported" : "not supported");
  895. ctrl->pci_dev = pdev;
  896. pci_set_drvdata(pdev, ctrl);
  897. /* make our own copy of the pci bus structure,
  898. * as we like tweaking it a lot */
  899. ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL);
  900. if (!ctrl->pci_bus) {
  901. err("out of memory\n");
  902. rc = -ENOMEM;
  903. goto err_free_ctrl;
  904. }
  905. memcpy(ctrl->pci_bus, pdev->bus, sizeof(*ctrl->pci_bus));
  906. ctrl->bus = pdev->bus->number;
  907. ctrl->rev = rev;
  908. dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
  909. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
  910. init_MUTEX(&ctrl->crit_sect);
  911. init_waitqueue_head(&ctrl->queue);
  912. /* initialize our threads if they haven't already been started up */
  913. rc = one_time_init();
  914. if (rc) {
  915. goto err_free_bus;
  916. }
  917. dbg("pdev = %p\n", pdev);
  918. dbg("pci resource start %lx\n", pci_resource_start(pdev, 0));
  919. dbg("pci resource len %lx\n", pci_resource_len(pdev, 0));
  920. if (!request_mem_region(pci_resource_start(pdev, 0),
  921. pci_resource_len(pdev, 0), MY_NAME)) {
  922. err("cannot reserve MMIO region\n");
  923. rc = -ENOMEM;
  924. goto err_free_bus;
  925. }
  926. ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0),
  927. pci_resource_len(pdev, 0));
  928. if (!ctrl->hpc_reg) {
  929. err("cannot remap MMIO region %lx @ %lx\n",
  930. pci_resource_len(pdev, 0),
  931. pci_resource_start(pdev, 0));
  932. rc = -ENODEV;
  933. goto err_free_mem_region;
  934. }
  935. // Check for 66Mhz operation
  936. ctrl->speed = get_controller_speed(ctrl);
  937. /********************************************************
  938. *
  939. * Save configuration headers for this and
  940. * subordinate PCI buses
  941. *
  942. ********************************************************/
  943. // find the physical slot number of the first hot plug slot
  944. /* Get slot won't work for devices behind bridges, but
  945. * in this case it will always be called for the "base"
  946. * bus/dev/func of a slot.
  947. * CS: this is leveraging the PCIIRQ routing code from the kernel
  948. * (pci-pc.c: get_irq_routing_table) */
  949. rc = get_slot_mapping(ctrl->pci_bus, pdev->bus->number,
  950. (readb(ctrl->hpc_reg + SLOT_MASK) >> 4),
  951. &(ctrl->first_slot));
  952. dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
  953. ctrl->first_slot, rc);
  954. if (rc) {
  955. err(msg_initialization_err, rc);
  956. goto err_iounmap;
  957. }
  958. // Store PCI Config Space for all devices on this bus
  959. rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK));
  960. if (rc) {
  961. err("%s: unable to save PCI configuration data, error %d\n",
  962. __FUNCTION__, rc);
  963. goto err_iounmap;
  964. }
  965. /*
  966. * Get IO, memory, and IRQ resources for new devices
  967. */
  968. // The next line is required for cpqhp_find_available_resources
  969. ctrl->interrupt = pdev->irq;
  970. if (ctrl->interrupt < 0x10) {
  971. cpqhp_legacy_mode = 1;
  972. dbg("System seems to be configured for Full Table Mapped MPS mode\n");
  973. }
  974. ctrl->cfgspc_irq = 0;
  975. pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &ctrl->cfgspc_irq);
  976. rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start);
  977. ctrl->add_support = !rc;
  978. if (rc) {
  979. dbg("cpqhp_find_available_resources = 0x%x\n", rc);
  980. err("unable to locate PCI configuration resources for hot plug add.\n");
  981. goto err_iounmap;
  982. }
  983. /*
  984. * Finish setting up the hot plug ctrl device
  985. */
  986. ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  987. dbg("NumSlots %d \n", ctrl->slot_device_offset);
  988. ctrl->next_event = 0;
  989. /* Setup the slot information structures */
  990. rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table);
  991. if (rc) {
  992. err(msg_initialization_err, 6);
  993. err("%s: unable to save PCI configuration data, error %d\n",
  994. __FUNCTION__, rc);
  995. goto err_iounmap;
  996. }
  997. /* Mask all general input interrupts */
  998. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK);
  999. /* set up the interrupt */
  1000. dbg("HPC interrupt = %d \n", ctrl->interrupt);
  1001. if (request_irq(ctrl->interrupt, cpqhp_ctrl_intr,
  1002. SA_SHIRQ, MY_NAME, ctrl)) {
  1003. err("Can't get irq %d for the hotplug pci controller\n",
  1004. ctrl->interrupt);
  1005. rc = -ENODEV;
  1006. goto err_iounmap;
  1007. }
  1008. /* Enable Shift Out interrupt and clear it, also enable SERR on power fault */
  1009. temp_word = readw(ctrl->hpc_reg + MISC);
  1010. temp_word |= 0x4006;
  1011. writew(temp_word, ctrl->hpc_reg + MISC);
  1012. // Changed 05/05/97 to clear all interrupts at start
  1013. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR);
  1014. ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  1015. writel(0x0L, ctrl->hpc_reg + INT_MASK);
  1016. if (!cpqhp_ctrl_list) {
  1017. cpqhp_ctrl_list = ctrl;
  1018. ctrl->next = NULL;
  1019. } else {
  1020. ctrl->next = cpqhp_ctrl_list;
  1021. cpqhp_ctrl_list = ctrl;
  1022. }
  1023. // turn off empty slots here unless command line option "ON" set
  1024. // Wait for exclusive access to hardware
  1025. down(&ctrl->crit_sect);
  1026. num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  1027. // find first device number for the ctrl
  1028. device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  1029. while (num_of_slots) {
  1030. dbg("num_of_slots: %d\n", num_of_slots);
  1031. func = cpqhp_slot_find(ctrl->bus, device, 0);
  1032. if (!func)
  1033. break;
  1034. hp_slot = func->device - ctrl->slot_device_offset;
  1035. dbg("hp_slot: %d\n", hp_slot);
  1036. // We have to save the presence info for these slots
  1037. temp_word = ctrl->ctrl_int_comp >> 16;
  1038. func->presence_save = (temp_word >> hp_slot) & 0x01;
  1039. func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
  1040. if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
  1041. func->switch_save = 0;
  1042. } else {
  1043. func->switch_save = 0x10;
  1044. }
  1045. if (!power_mode) {
  1046. if (!func->is_a_board) {
  1047. green_LED_off(ctrl, hp_slot);
  1048. slot_disable(ctrl, hp_slot);
  1049. }
  1050. }
  1051. device++;
  1052. num_of_slots--;
  1053. }
  1054. if (!power_mode) {
  1055. set_SOGO(ctrl);
  1056. // Wait for SOBS to be unset
  1057. wait_for_ctrl_irq(ctrl);
  1058. }
  1059. rc = init_SERR(ctrl);
  1060. if (rc) {
  1061. err("init_SERR failed\n");
  1062. up(&ctrl->crit_sect);
  1063. goto err_free_irq;
  1064. }
  1065. // Done with exclusive hardware access
  1066. up(&ctrl->crit_sect);
  1067. cpqhp_create_debugfs_files(ctrl);
  1068. return 0;
  1069. err_free_irq:
  1070. free_irq(ctrl->interrupt, ctrl);
  1071. err_iounmap:
  1072. iounmap(ctrl->hpc_reg);
  1073. err_free_mem_region:
  1074. release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  1075. err_free_bus:
  1076. kfree(ctrl->pci_bus);
  1077. err_free_ctrl:
  1078. kfree(ctrl);
  1079. err_disable_device:
  1080. pci_disable_device(pdev);
  1081. return rc;
  1082. }
  1083. static int one_time_init(void)
  1084. {
  1085. int loop;
  1086. int retval = 0;
  1087. if (initialized)
  1088. return 0;
  1089. power_mode = 0;
  1090. retval = pci_print_IRQ_route();
  1091. if (retval)
  1092. goto error;
  1093. dbg("Initialize + Start the notification mechanism \n");
  1094. retval = cpqhp_event_start_thread();
  1095. if (retval)
  1096. goto error;
  1097. dbg("Initialize slot lists\n");
  1098. for (loop = 0; loop < 256; loop++) {
  1099. cpqhp_slot_list[loop] = NULL;
  1100. }
  1101. // FIXME: We also need to hook the NMI handler eventually.
  1102. // this also needs to be worked with Christoph
  1103. // register_NMI_handler();
  1104. // Map rom address
  1105. cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
  1106. if (!cpqhp_rom_start) {
  1107. err ("Could not ioremap memory region for ROM\n");
  1108. retval = -EIO;
  1109. goto error;
  1110. }
  1111. /* Now, map the int15 entry point if we are on compaq specific hardware */
  1112. compaq_nvram_init(cpqhp_rom_start);
  1113. /* Map smbios table entry point structure */
  1114. smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start,
  1115. cpqhp_rom_start + ROM_PHY_LEN);
  1116. if (!smbios_table) {
  1117. err ("Could not find the SMBIOS pointer in memory\n");
  1118. retval = -EIO;
  1119. goto error_rom_start;
  1120. }
  1121. smbios_start = ioremap(readl(smbios_table + ST_ADDRESS),
  1122. readw(smbios_table + ST_LENGTH));
  1123. if (!smbios_start) {
  1124. err ("Could not ioremap memory region taken from SMBIOS values\n");
  1125. retval = -EIO;
  1126. goto error_smbios_start;
  1127. }
  1128. initialized = 1;
  1129. return retval;
  1130. error_smbios_start:
  1131. iounmap(smbios_start);
  1132. error_rom_start:
  1133. iounmap(cpqhp_rom_start);
  1134. error:
  1135. return retval;
  1136. }
  1137. static void __exit unload_cpqphpd(void)
  1138. {
  1139. struct pci_func *next;
  1140. struct pci_func *TempSlot;
  1141. int loop;
  1142. u32 rc;
  1143. struct controller *ctrl;
  1144. struct controller *tctrl;
  1145. struct pci_resource *res;
  1146. struct pci_resource *tres;
  1147. rc = compaq_nvram_store(cpqhp_rom_start);
  1148. ctrl = cpqhp_ctrl_list;
  1149. while (ctrl) {
  1150. if (ctrl->hpc_reg) {
  1151. u16 misc;
  1152. rc = read_slot_enable (ctrl);
  1153. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  1154. writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK);
  1155. misc = readw(ctrl->hpc_reg + MISC);
  1156. misc &= 0xFFFD;
  1157. writew(misc, ctrl->hpc_reg + MISC);
  1158. }
  1159. ctrl_slot_cleanup(ctrl);
  1160. res = ctrl->io_head;
  1161. while (res) {
  1162. tres = res;
  1163. res = res->next;
  1164. kfree(tres);
  1165. }
  1166. res = ctrl->mem_head;
  1167. while (res) {
  1168. tres = res;
  1169. res = res->next;
  1170. kfree(tres);
  1171. }
  1172. res = ctrl->p_mem_head;
  1173. while (res) {
  1174. tres = res;
  1175. res = res->next;
  1176. kfree(tres);
  1177. }
  1178. res = ctrl->bus_head;
  1179. while (res) {
  1180. tres = res;
  1181. res = res->next;
  1182. kfree(tres);
  1183. }
  1184. kfree (ctrl->pci_bus);
  1185. tctrl = ctrl;
  1186. ctrl = ctrl->next;
  1187. kfree(tctrl);
  1188. }
  1189. for (loop = 0; loop < 256; loop++) {
  1190. next = cpqhp_slot_list[loop];
  1191. while (next != NULL) {
  1192. res = next->io_head;
  1193. while (res) {
  1194. tres = res;
  1195. res = res->next;
  1196. kfree(tres);
  1197. }
  1198. res = next->mem_head;
  1199. while (res) {
  1200. tres = res;
  1201. res = res->next;
  1202. kfree(tres);
  1203. }
  1204. res = next->p_mem_head;
  1205. while (res) {
  1206. tres = res;
  1207. res = res->next;
  1208. kfree(tres);
  1209. }
  1210. res = next->bus_head;
  1211. while (res) {
  1212. tres = res;
  1213. res = res->next;
  1214. kfree(tres);
  1215. }
  1216. TempSlot = next;
  1217. next = next->next;
  1218. kfree(TempSlot);
  1219. }
  1220. }
  1221. // Stop the notification mechanism
  1222. if (initialized)
  1223. cpqhp_event_stop_thread();
  1224. //unmap the rom address
  1225. if (cpqhp_rom_start)
  1226. iounmap(cpqhp_rom_start);
  1227. if (smbios_start)
  1228. iounmap(smbios_start);
  1229. }
  1230. static struct pci_device_id hpcd_pci_tbl[] = {
  1231. {
  1232. /* handle any PCI Hotplug controller */
  1233. .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
  1234. .class_mask = ~0,
  1235. /* no matter who makes it */
  1236. .vendor = PCI_ANY_ID,
  1237. .device = PCI_ANY_ID,
  1238. .subvendor = PCI_ANY_ID,
  1239. .subdevice = PCI_ANY_ID,
  1240. }, { /* end: all zeroes */ }
  1241. };
  1242. MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);
  1243. static struct pci_driver cpqhpc_driver = {
  1244. .name = "compaq_pci_hotplug",
  1245. .id_table = hpcd_pci_tbl,
  1246. .probe = cpqhpc_probe,
  1247. /* remove: cpqhpc_remove_one, */
  1248. };
  1249. static int __init cpqhpc_init(void)
  1250. {
  1251. int result;
  1252. cpqhp_debug = debug;
  1253. info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
  1254. cpqhp_initialize_debugfs();
  1255. result = pci_register_driver(&cpqhpc_driver);
  1256. dbg("pci_register_driver = %d\n", result);
  1257. return result;
  1258. }
  1259. static void __exit cpqhpc_cleanup(void)
  1260. {
  1261. dbg("unload_cpqphpd()\n");
  1262. unload_cpqphpd();
  1263. dbg("pci_unregister_driver\n");
  1264. pci_unregister_driver(&cpqhpc_driver);
  1265. cpqhp_shutdown_debugfs();
  1266. }
  1267. module_init(cpqhpc_init);
  1268. module_exit(cpqhpc_cleanup);