pci.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /*
  2. * Support for PCI bridges found on Power Macintoshes.
  3. *
  4. * Copyright (C) 2003-2005 Benjamin Herrenschmuidt (benh@kernel.crashing.org)
  5. * Copyright (C) 1997 Paul Mackerras (paulus@samba.org)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/pci.h>
  14. #include <linux/delay.h>
  15. #include <linux/string.h>
  16. #include <linux/init.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/irq.h>
  19. #include <asm/sections.h>
  20. #include <asm/io.h>
  21. #include <asm/prom.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/machdep.h>
  24. #include <asm/pmac_feature.h>
  25. #include <asm/grackle.h>
  26. #include <asm/ppc-pci.h>
  27. #undef DEBUG
  28. #ifdef DEBUG
  29. #define DBG(x...) printk(x)
  30. #else
  31. #define DBG(x...)
  32. #endif
  33. /* XXX Could be per-controller, but I don't think we risk anything by
  34. * assuming we won't have both UniNorth and Bandit */
  35. static int has_uninorth;
  36. #ifdef CONFIG_PPC64
  37. static struct pci_controller *u3_agp;
  38. static struct pci_controller *u4_pcie;
  39. static struct pci_controller *u3_ht;
  40. #else
  41. static int has_second_ohare;
  42. #endif /* CONFIG_PPC64 */
  43. extern int pcibios_assign_bus_offset;
  44. struct device_node *k2_skiplist[2];
  45. /*
  46. * Magic constants for enabling cache coherency in the bandit/PSX bridge.
  47. */
  48. #define BANDIT_DEVID_2 8
  49. #define BANDIT_REVID 3
  50. #define BANDIT_DEVNUM 11
  51. #define BANDIT_MAGIC 0x50
  52. #define BANDIT_COHERENT 0x40
  53. static int __init fixup_one_level_bus_range(struct device_node *node, int higher)
  54. {
  55. for (; node != 0;node = node->sibling) {
  56. const int * bus_range;
  57. const unsigned int *class_code;
  58. int len;
  59. /* For PCI<->PCI bridges or CardBus bridges, we go down */
  60. class_code = of_get_property(node, "class-code", NULL);
  61. if (!class_code || ((*class_code >> 8) != PCI_CLASS_BRIDGE_PCI &&
  62. (*class_code >> 8) != PCI_CLASS_BRIDGE_CARDBUS))
  63. continue;
  64. bus_range = of_get_property(node, "bus-range", &len);
  65. if (bus_range != NULL && len > 2 * sizeof(int)) {
  66. if (bus_range[1] > higher)
  67. higher = bus_range[1];
  68. }
  69. higher = fixup_one_level_bus_range(node->child, higher);
  70. }
  71. return higher;
  72. }
  73. /* This routine fixes the "bus-range" property of all bridges in the
  74. * system since they tend to have their "last" member wrong on macs
  75. *
  76. * Note that the bus numbers manipulated here are OF bus numbers, they
  77. * are not Linux bus numbers.
  78. */
  79. static void __init fixup_bus_range(struct device_node *bridge)
  80. {
  81. int *bus_range, len;
  82. struct property *prop;
  83. /* Lookup the "bus-range" property for the hose */
  84. prop = of_find_property(bridge, "bus-range", &len);
  85. if (prop == NULL || prop->length < 2 * sizeof(int))
  86. return;
  87. bus_range = prop->value;
  88. bus_range[1] = fixup_one_level_bus_range(bridge->child, bus_range[1]);
  89. }
  90. /*
  91. * Apple MacRISC (U3, UniNorth, Bandit, Chaos) PCI controllers.
  92. *
  93. * The "Bandit" version is present in all early PCI PowerMacs,
  94. * and up to the first ones using Grackle. Some machines may
  95. * have 2 bandit controllers (2 PCI busses).
  96. *
  97. * "Chaos" is used in some "Bandit"-type machines as a bridge
  98. * for the separate display bus. It is accessed the same
  99. * way as bandit, but cannot be probed for devices. It therefore
  100. * has its own config access functions.
  101. *
  102. * The "UniNorth" version is present in all Core99 machines
  103. * (iBook, G4, new IMacs, and all the recent Apple machines).
  104. * It contains 3 controllers in one ASIC.
  105. *
  106. * The U3 is the bridge used on G5 machines. It contains an
  107. * AGP bus which is dealt with the old UniNorth access routines
  108. * and a HyperTransport bus which uses its own set of access
  109. * functions.
  110. */
  111. #define MACRISC_CFA0(devfn, off) \
  112. ((1 << (unsigned int)PCI_SLOT(dev_fn)) \
  113. | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
  114. | (((unsigned int)(off)) & 0xFCUL))
  115. #define MACRISC_CFA1(bus, devfn, off) \
  116. ((((unsigned int)(bus)) << 16) \
  117. |(((unsigned int)(devfn)) << 8) \
  118. |(((unsigned int)(off)) & 0xFCUL) \
  119. |1UL)
  120. static volatile void __iomem *macrisc_cfg_access(struct pci_controller* hose,
  121. u8 bus, u8 dev_fn, u8 offset)
  122. {
  123. unsigned int caddr;
  124. if (bus == hose->first_busno) {
  125. if (dev_fn < (11 << 3))
  126. return NULL;
  127. caddr = MACRISC_CFA0(dev_fn, offset);
  128. } else
  129. caddr = MACRISC_CFA1(bus, dev_fn, offset);
  130. /* Uninorth will return garbage if we don't read back the value ! */
  131. do {
  132. out_le32(hose->cfg_addr, caddr);
  133. } while (in_le32(hose->cfg_addr) != caddr);
  134. offset &= has_uninorth ? 0x07 : 0x03;
  135. return hose->cfg_data + offset;
  136. }
  137. static int macrisc_read_config(struct pci_bus *bus, unsigned int devfn,
  138. int offset, int len, u32 *val)
  139. {
  140. struct pci_controller *hose;
  141. volatile void __iomem *addr;
  142. hose = pci_bus_to_host(bus);
  143. if (hose == NULL)
  144. return PCIBIOS_DEVICE_NOT_FOUND;
  145. if (offset >= 0x100)
  146. return PCIBIOS_BAD_REGISTER_NUMBER;
  147. addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
  148. if (!addr)
  149. return PCIBIOS_DEVICE_NOT_FOUND;
  150. /*
  151. * Note: the caller has already checked that offset is
  152. * suitably aligned and that len is 1, 2 or 4.
  153. */
  154. switch (len) {
  155. case 1:
  156. *val = in_8(addr);
  157. break;
  158. case 2:
  159. *val = in_le16(addr);
  160. break;
  161. default:
  162. *val = in_le32(addr);
  163. break;
  164. }
  165. return PCIBIOS_SUCCESSFUL;
  166. }
  167. static int macrisc_write_config(struct pci_bus *bus, unsigned int devfn,
  168. int offset, int len, u32 val)
  169. {
  170. struct pci_controller *hose;
  171. volatile void __iomem *addr;
  172. hose = pci_bus_to_host(bus);
  173. if (hose == NULL)
  174. return PCIBIOS_DEVICE_NOT_FOUND;
  175. if (offset >= 0x100)
  176. return PCIBIOS_BAD_REGISTER_NUMBER;
  177. addr = macrisc_cfg_access(hose, bus->number, devfn, offset);
  178. if (!addr)
  179. return PCIBIOS_DEVICE_NOT_FOUND;
  180. /*
  181. * Note: the caller has already checked that offset is
  182. * suitably aligned and that len is 1, 2 or 4.
  183. */
  184. switch (len) {
  185. case 1:
  186. out_8(addr, val);
  187. (void) in_8(addr);
  188. break;
  189. case 2:
  190. out_le16(addr, val);
  191. (void) in_le16(addr);
  192. break;
  193. default:
  194. out_le32(addr, val);
  195. (void) in_le32(addr);
  196. break;
  197. }
  198. return PCIBIOS_SUCCESSFUL;
  199. }
  200. static struct pci_ops macrisc_pci_ops =
  201. {
  202. macrisc_read_config,
  203. macrisc_write_config
  204. };
  205. #ifdef CONFIG_PPC32
  206. /*
  207. * Verify that a specific (bus, dev_fn) exists on chaos
  208. */
  209. static int chaos_validate_dev(struct pci_bus *bus, int devfn, int offset)
  210. {
  211. struct device_node *np;
  212. const u32 *vendor, *device;
  213. if (offset >= 0x100)
  214. return PCIBIOS_BAD_REGISTER_NUMBER;
  215. np = pci_busdev_to_OF_node(bus, devfn);
  216. if (np == NULL)
  217. return PCIBIOS_DEVICE_NOT_FOUND;
  218. vendor = of_get_property(np, "vendor-id", NULL);
  219. device = of_get_property(np, "device-id", NULL);
  220. if (vendor == NULL || device == NULL)
  221. return PCIBIOS_DEVICE_NOT_FOUND;
  222. if ((*vendor == 0x106b) && (*device == 3) && (offset >= 0x10)
  223. && (offset != 0x14) && (offset != 0x18) && (offset <= 0x24))
  224. return PCIBIOS_BAD_REGISTER_NUMBER;
  225. return PCIBIOS_SUCCESSFUL;
  226. }
  227. static int
  228. chaos_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  229. int len, u32 *val)
  230. {
  231. int result = chaos_validate_dev(bus, devfn, offset);
  232. if (result == PCIBIOS_BAD_REGISTER_NUMBER)
  233. *val = ~0U;
  234. if (result != PCIBIOS_SUCCESSFUL)
  235. return result;
  236. return macrisc_read_config(bus, devfn, offset, len, val);
  237. }
  238. static int
  239. chaos_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  240. int len, u32 val)
  241. {
  242. int result = chaos_validate_dev(bus, devfn, offset);
  243. if (result != PCIBIOS_SUCCESSFUL)
  244. return result;
  245. return macrisc_write_config(bus, devfn, offset, len, val);
  246. }
  247. static struct pci_ops chaos_pci_ops =
  248. {
  249. chaos_read_config,
  250. chaos_write_config
  251. };
  252. static void __init setup_chaos(struct pci_controller *hose,
  253. struct resource *addr)
  254. {
  255. /* assume a `chaos' bridge */
  256. hose->ops = &chaos_pci_ops;
  257. hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
  258. hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
  259. }
  260. #endif /* CONFIG_PPC32 */
  261. #ifdef CONFIG_PPC64
  262. /*
  263. * These versions of U3 HyperTransport config space access ops do not
  264. * implement self-view of the HT host yet
  265. */
  266. /*
  267. * This function deals with some "special cases" devices.
  268. *
  269. * 0 -> No special case
  270. * 1 -> Skip the device but act as if the access was successfull
  271. * (return 0xff's on reads, eventually, cache config space
  272. * accesses in a later version)
  273. * -1 -> Hide the device (unsuccessful acess)
  274. */
  275. static int u3_ht_skip_device(struct pci_controller *hose,
  276. struct pci_bus *bus, unsigned int devfn)
  277. {
  278. struct device_node *busdn, *dn;
  279. int i;
  280. /* We only allow config cycles to devices that are in OF device-tree
  281. * as we are apparently having some weird things going on with some
  282. * revs of K2 on recent G5s
  283. */
  284. if (bus->self)
  285. busdn = pci_device_to_OF_node(bus->self);
  286. else
  287. busdn = hose->arch_data;
  288. for (dn = busdn->child; dn; dn = dn->sibling)
  289. if (PCI_DN(dn) && PCI_DN(dn)->devfn == devfn)
  290. break;
  291. if (dn == NULL)
  292. return -1;
  293. /*
  294. * When a device in K2 is powered down, we die on config
  295. * cycle accesses. Fix that here.
  296. */
  297. for (i=0; i<2; i++)
  298. if (k2_skiplist[i] == dn)
  299. return 1;
  300. return 0;
  301. }
  302. #define U3_HT_CFA0(devfn, off) \
  303. ((((unsigned int)devfn) << 8) | offset)
  304. #define U3_HT_CFA1(bus, devfn, off) \
  305. (U3_HT_CFA0(devfn, off) \
  306. + (((unsigned int)bus) << 16) \
  307. + 0x01000000UL)
  308. static volatile void __iomem *u3_ht_cfg_access(struct pci_controller* hose,
  309. u8 bus, u8 devfn, u8 offset)
  310. {
  311. if (bus == hose->first_busno) {
  312. /* For now, we don't self probe U3 HT bridge */
  313. if (PCI_SLOT(devfn) == 0)
  314. return NULL;
  315. return hose->cfg_data + U3_HT_CFA0(devfn, offset);
  316. } else
  317. return hose->cfg_data + U3_HT_CFA1(bus, devfn, offset);
  318. }
  319. static int u3_ht_read_config(struct pci_bus *bus, unsigned int devfn,
  320. int offset, int len, u32 *val)
  321. {
  322. struct pci_controller *hose;
  323. volatile void __iomem *addr;
  324. hose = pci_bus_to_host(bus);
  325. if (hose == NULL)
  326. return PCIBIOS_DEVICE_NOT_FOUND;
  327. if (offset >= 0x100)
  328. return PCIBIOS_BAD_REGISTER_NUMBER;
  329. addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);
  330. if (!addr)
  331. return PCIBIOS_DEVICE_NOT_FOUND;
  332. switch (u3_ht_skip_device(hose, bus, devfn)) {
  333. case 0:
  334. break;
  335. case 1:
  336. switch (len) {
  337. case 1:
  338. *val = 0xff; break;
  339. case 2:
  340. *val = 0xffff; break;
  341. default:
  342. *val = 0xfffffffful; break;
  343. }
  344. return PCIBIOS_SUCCESSFUL;
  345. default:
  346. return PCIBIOS_DEVICE_NOT_FOUND;
  347. }
  348. /*
  349. * Note: the caller has already checked that offset is
  350. * suitably aligned and that len is 1, 2 or 4.
  351. */
  352. switch (len) {
  353. case 1:
  354. *val = in_8(addr);
  355. break;
  356. case 2:
  357. *val = in_le16(addr);
  358. break;
  359. default:
  360. *val = in_le32(addr);
  361. break;
  362. }
  363. return PCIBIOS_SUCCESSFUL;
  364. }
  365. static int u3_ht_write_config(struct pci_bus *bus, unsigned int devfn,
  366. int offset, int len, u32 val)
  367. {
  368. struct pci_controller *hose;
  369. volatile void __iomem *addr;
  370. hose = pci_bus_to_host(bus);
  371. if (hose == NULL)
  372. return PCIBIOS_DEVICE_NOT_FOUND;
  373. if (offset >= 0x100)
  374. return PCIBIOS_BAD_REGISTER_NUMBER;
  375. addr = u3_ht_cfg_access(hose, bus->number, devfn, offset);
  376. if (!addr)
  377. return PCIBIOS_DEVICE_NOT_FOUND;
  378. switch (u3_ht_skip_device(hose, bus, devfn)) {
  379. case 0:
  380. break;
  381. case 1:
  382. return PCIBIOS_SUCCESSFUL;
  383. default:
  384. return PCIBIOS_DEVICE_NOT_FOUND;
  385. }
  386. /*
  387. * Note: the caller has already checked that offset is
  388. * suitably aligned and that len is 1, 2 or 4.
  389. */
  390. switch (len) {
  391. case 1:
  392. out_8(addr, val);
  393. (void) in_8(addr);
  394. break;
  395. case 2:
  396. out_le16(addr, val);
  397. (void) in_le16(addr);
  398. break;
  399. default:
  400. out_le32((u32 __iomem *)addr, val);
  401. (void) in_le32(addr);
  402. break;
  403. }
  404. return PCIBIOS_SUCCESSFUL;
  405. }
  406. static struct pci_ops u3_ht_pci_ops =
  407. {
  408. u3_ht_read_config,
  409. u3_ht_write_config
  410. };
  411. #define U4_PCIE_CFA0(devfn, off) \
  412. ((1 << ((unsigned int)PCI_SLOT(dev_fn))) \
  413. | (((unsigned int)PCI_FUNC(dev_fn)) << 8) \
  414. | ((((unsigned int)(off)) >> 8) << 28) \
  415. | (((unsigned int)(off)) & 0xfcU))
  416. #define U4_PCIE_CFA1(bus, devfn, off) \
  417. ((((unsigned int)(bus)) << 16) \
  418. |(((unsigned int)(devfn)) << 8) \
  419. | ((((unsigned int)(off)) >> 8) << 28) \
  420. |(((unsigned int)(off)) & 0xfcU) \
  421. |1UL)
  422. static volatile void __iomem *u4_pcie_cfg_access(struct pci_controller* hose,
  423. u8 bus, u8 dev_fn, int offset)
  424. {
  425. unsigned int caddr;
  426. if (bus == hose->first_busno) {
  427. caddr = U4_PCIE_CFA0(dev_fn, offset);
  428. } else
  429. caddr = U4_PCIE_CFA1(bus, dev_fn, offset);
  430. /* Uninorth will return garbage if we don't read back the value ! */
  431. do {
  432. out_le32(hose->cfg_addr, caddr);
  433. } while (in_le32(hose->cfg_addr) != caddr);
  434. offset &= 0x03;
  435. return hose->cfg_data + offset;
  436. }
  437. static int u4_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
  438. int offset, int len, u32 *val)
  439. {
  440. struct pci_controller *hose;
  441. volatile void __iomem *addr;
  442. hose = pci_bus_to_host(bus);
  443. if (hose == NULL)
  444. return PCIBIOS_DEVICE_NOT_FOUND;
  445. if (offset >= 0x1000)
  446. return PCIBIOS_BAD_REGISTER_NUMBER;
  447. addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
  448. if (!addr)
  449. return PCIBIOS_DEVICE_NOT_FOUND;
  450. /*
  451. * Note: the caller has already checked that offset is
  452. * suitably aligned and that len is 1, 2 or 4.
  453. */
  454. switch (len) {
  455. case 1:
  456. *val = in_8(addr);
  457. break;
  458. case 2:
  459. *val = in_le16(addr);
  460. break;
  461. default:
  462. *val = in_le32(addr);
  463. break;
  464. }
  465. return PCIBIOS_SUCCESSFUL;
  466. }
  467. static int u4_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
  468. int offset, int len, u32 val)
  469. {
  470. struct pci_controller *hose;
  471. volatile void __iomem *addr;
  472. hose = pci_bus_to_host(bus);
  473. if (hose == NULL)
  474. return PCIBIOS_DEVICE_NOT_FOUND;
  475. if (offset >= 0x1000)
  476. return PCIBIOS_BAD_REGISTER_NUMBER;
  477. addr = u4_pcie_cfg_access(hose, bus->number, devfn, offset);
  478. if (!addr)
  479. return PCIBIOS_DEVICE_NOT_FOUND;
  480. /*
  481. * Note: the caller has already checked that offset is
  482. * suitably aligned and that len is 1, 2 or 4.
  483. */
  484. switch (len) {
  485. case 1:
  486. out_8(addr, val);
  487. (void) in_8(addr);
  488. break;
  489. case 2:
  490. out_le16(addr, val);
  491. (void) in_le16(addr);
  492. break;
  493. default:
  494. out_le32(addr, val);
  495. (void) in_le32(addr);
  496. break;
  497. }
  498. return PCIBIOS_SUCCESSFUL;
  499. }
  500. static struct pci_ops u4_pcie_pci_ops =
  501. {
  502. u4_pcie_read_config,
  503. u4_pcie_write_config
  504. };
  505. #endif /* CONFIG_PPC64 */
  506. #ifdef CONFIG_PPC32
  507. /*
  508. * For a bandit bridge, turn on cache coherency if necessary.
  509. * N.B. we could clean this up using the hose ops directly.
  510. */
  511. static void __init init_bandit(struct pci_controller *bp)
  512. {
  513. unsigned int vendev, magic;
  514. int rev;
  515. /* read the word at offset 0 in config space for device 11 */
  516. out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + PCI_VENDOR_ID);
  517. udelay(2);
  518. vendev = in_le32(bp->cfg_data);
  519. if (vendev == (PCI_DEVICE_ID_APPLE_BANDIT << 16) +
  520. PCI_VENDOR_ID_APPLE) {
  521. /* read the revision id */
  522. out_le32(bp->cfg_addr,
  523. (1UL << BANDIT_DEVNUM) + PCI_REVISION_ID);
  524. udelay(2);
  525. rev = in_8(bp->cfg_data);
  526. if (rev != BANDIT_REVID)
  527. printk(KERN_WARNING
  528. "Unknown revision %d for bandit\n", rev);
  529. } else if (vendev != (BANDIT_DEVID_2 << 16) + PCI_VENDOR_ID_APPLE) {
  530. printk(KERN_WARNING "bandit isn't? (%x)\n", vendev);
  531. return;
  532. }
  533. /* read the word at offset 0x50 */
  534. out_le32(bp->cfg_addr, (1UL << BANDIT_DEVNUM) + BANDIT_MAGIC);
  535. udelay(2);
  536. magic = in_le32(bp->cfg_data);
  537. if ((magic & BANDIT_COHERENT) != 0)
  538. return;
  539. magic |= BANDIT_COHERENT;
  540. udelay(2);
  541. out_le32(bp->cfg_data, magic);
  542. printk(KERN_INFO "Cache coherency enabled for bandit/PSX\n");
  543. }
  544. /*
  545. * Tweak the PCI-PCI bridge chip on the blue & white G3s.
  546. */
  547. static void __init init_p2pbridge(void)
  548. {
  549. struct device_node *p2pbridge;
  550. struct pci_controller* hose;
  551. u8 bus, devfn;
  552. u16 val;
  553. /* XXX it would be better here to identify the specific
  554. PCI-PCI bridge chip we have. */
  555. p2pbridge = of_find_node_by_name(NULL, "pci-bridge");
  556. if (p2pbridge == NULL
  557. || p2pbridge->parent == NULL
  558. || strcmp(p2pbridge->parent->name, "pci") != 0)
  559. goto done;
  560. if (pci_device_from_OF_node(p2pbridge, &bus, &devfn) < 0) {
  561. DBG("Can't find PCI infos for PCI<->PCI bridge\n");
  562. goto done;
  563. }
  564. /* Warning: At this point, we have not yet renumbered all busses.
  565. * So we must use OF walking to find out hose
  566. */
  567. hose = pci_find_hose_for_OF_device(p2pbridge);
  568. if (!hose) {
  569. DBG("Can't find hose for PCI<->PCI bridge\n");
  570. goto done;
  571. }
  572. if (early_read_config_word(hose, bus, devfn,
  573. PCI_BRIDGE_CONTROL, &val) < 0) {
  574. printk(KERN_ERR "init_p2pbridge: couldn't read bridge"
  575. " control\n");
  576. goto done;
  577. }
  578. val &= ~PCI_BRIDGE_CTL_MASTER_ABORT;
  579. early_write_config_word(hose, bus, devfn, PCI_BRIDGE_CONTROL, val);
  580. done:
  581. of_node_put(p2pbridge);
  582. }
  583. static void __init init_second_ohare(void)
  584. {
  585. struct device_node *np = of_find_node_by_name(NULL, "pci106b,7");
  586. unsigned char bus, devfn;
  587. unsigned short cmd;
  588. if (np == NULL)
  589. return;
  590. /* This must run before we initialize the PICs since the second
  591. * ohare hosts a PIC that will be accessed there.
  592. */
  593. if (pci_device_from_OF_node(np, &bus, &devfn) == 0) {
  594. struct pci_controller* hose =
  595. pci_find_hose_for_OF_device(np);
  596. if (!hose) {
  597. printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
  598. return;
  599. }
  600. early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
  601. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  602. cmd &= ~PCI_COMMAND_IO;
  603. early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
  604. }
  605. has_second_ohare = 1;
  606. }
  607. /*
  608. * Some Apple desktop machines have a NEC PD720100A USB2 controller
  609. * on the motherboard. Open Firmware, on these, will disable the
  610. * EHCI part of it so it behaves like a pair of OHCI's. This fixup
  611. * code re-enables it ;)
  612. */
  613. static void __init fixup_nec_usb2(void)
  614. {
  615. struct device_node *nec;
  616. for (nec = NULL; (nec = of_find_node_by_name(nec, "usb")) != NULL;) {
  617. struct pci_controller *hose;
  618. u32 data;
  619. const u32 *prop;
  620. u8 bus, devfn;
  621. prop = of_get_property(nec, "vendor-id", NULL);
  622. if (prop == NULL)
  623. continue;
  624. if (0x1033 != *prop)
  625. continue;
  626. prop = of_get_property(nec, "device-id", NULL);
  627. if (prop == NULL)
  628. continue;
  629. if (0x0035 != *prop)
  630. continue;
  631. prop = of_get_property(nec, "reg", NULL);
  632. if (prop == NULL)
  633. continue;
  634. devfn = (prop[0] >> 8) & 0xff;
  635. bus = (prop[0] >> 16) & 0xff;
  636. if (PCI_FUNC(devfn) != 0)
  637. continue;
  638. hose = pci_find_hose_for_OF_device(nec);
  639. if (!hose)
  640. continue;
  641. early_read_config_dword(hose, bus, devfn, 0xe4, &data);
  642. if (data & 1UL) {
  643. printk("Found NEC PD720100A USB2 chip with disabled"
  644. " EHCI, fixing up...\n");
  645. data &= ~1UL;
  646. early_write_config_dword(hose, bus, devfn, 0xe4, data);
  647. }
  648. }
  649. }
  650. static void __init setup_bandit(struct pci_controller *hose,
  651. struct resource *addr)
  652. {
  653. hose->ops = &macrisc_pci_ops;
  654. hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
  655. hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
  656. init_bandit(hose);
  657. }
  658. static int __init setup_uninorth(struct pci_controller *hose,
  659. struct resource *addr)
  660. {
  661. pci_assign_all_buses = 1;
  662. has_uninorth = 1;
  663. hose->ops = &macrisc_pci_ops;
  664. hose->cfg_addr = ioremap(addr->start + 0x800000, 0x1000);
  665. hose->cfg_data = ioremap(addr->start + 0xc00000, 0x1000);
  666. /* We "know" that the bridge at f2000000 has the PCI slots. */
  667. return addr->start == 0xf2000000;
  668. }
  669. #endif /* CONFIG_PPC32 */
  670. #ifdef CONFIG_PPC64
  671. static void __init setup_u3_agp(struct pci_controller* hose)
  672. {
  673. /* On G5, we move AGP up to high bus number so we don't need
  674. * to reassign bus numbers for HT. If we ever have P2P bridges
  675. * on AGP, we'll have to move pci_assign_all_busses to the
  676. * pci_controller structure so we enable it for AGP and not for
  677. * HT childs.
  678. * We hard code the address because of the different size of
  679. * the reg address cell, we shall fix that by killing struct
  680. * reg_property and using some accessor functions instead
  681. */
  682. hose->first_busno = 0xf0;
  683. hose->last_busno = 0xff;
  684. has_uninorth = 1;
  685. hose->ops = &macrisc_pci_ops;
  686. hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
  687. hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
  688. u3_agp = hose;
  689. }
  690. static void __init setup_u4_pcie(struct pci_controller* hose)
  691. {
  692. /* We currently only implement the "non-atomic" config space, to
  693. * be optimised later.
  694. */
  695. hose->ops = &u4_pcie_pci_ops;
  696. hose->cfg_addr = ioremap(0xf0000000 + 0x800000, 0x1000);
  697. hose->cfg_data = ioremap(0xf0000000 + 0xc00000, 0x1000);
  698. /* The bus contains a bridge from root -> device, we need to
  699. * make it visible on bus 0 so that we pick the right type
  700. * of config cycles. If we didn't, we would have to force all
  701. * config cycles to be type 1. So we override the "bus-range"
  702. * property here
  703. */
  704. hose->first_busno = 0x00;
  705. hose->last_busno = 0xff;
  706. u4_pcie = hose;
  707. }
  708. static void __init setup_u3_ht(struct pci_controller* hose)
  709. {
  710. struct device_node *np = (struct device_node *)hose->arch_data;
  711. struct pci_controller *other = NULL;
  712. int i, cur;
  713. hose->ops = &u3_ht_pci_ops;
  714. /* We hard code the address because of the different size of
  715. * the reg address cell, we shall fix that by killing struct
  716. * reg_property and using some accessor functions instead
  717. */
  718. hose->cfg_data = ioremap(0xf2000000, 0x02000000);
  719. /*
  720. * /ht node doesn't expose a "ranges" property, so we "remove"
  721. * regions that have been allocated to AGP. So far, this version of
  722. * the code doesn't assign any of the 0xfxxxxxxx "fine" memory regions
  723. * to /ht. We need to fix that sooner or later by either parsing all
  724. * child "ranges" properties or figuring out the U3 address space
  725. * decoding logic and then read its configuration register (if any).
  726. */
  727. hose->io_base_phys = 0xf4000000;
  728. hose->pci_io_size = 0x00400000;
  729. hose->io_resource.name = np->full_name;
  730. hose->io_resource.start = 0;
  731. hose->io_resource.end = 0x003fffff;
  732. hose->io_resource.flags = IORESOURCE_IO;
  733. hose->pci_mem_offset = 0;
  734. hose->first_busno = 0;
  735. hose->last_busno = 0xef;
  736. hose->mem_resources[0].name = np->full_name;
  737. hose->mem_resources[0].start = 0x80000000;
  738. hose->mem_resources[0].end = 0xefffffff;
  739. hose->mem_resources[0].flags = IORESOURCE_MEM;
  740. u3_ht = hose;
  741. if (u3_agp != NULL)
  742. other = u3_agp;
  743. else if (u4_pcie != NULL)
  744. other = u4_pcie;
  745. if (other == NULL) {
  746. DBG("U3/4 has no AGP/PCIE, using full resource range\n");
  747. return;
  748. }
  749. /* Fixup bus range vs. PCIE */
  750. if (u4_pcie)
  751. hose->last_busno = u4_pcie->first_busno - 1;
  752. /* We "remove" the AGP resources from the resources allocated to HT,
  753. * that is we create "holes". However, that code does assumptions
  754. * that so far happen to be true (cross fingers...), typically that
  755. * resources in the AGP node are properly ordered
  756. */
  757. cur = 0;
  758. for (i=0; i<3; i++) {
  759. struct resource *res = &other->mem_resources[i];
  760. if (res->flags != IORESOURCE_MEM)
  761. continue;
  762. /* We don't care about "fine" resources */
  763. if (res->start >= 0xf0000000)
  764. continue;
  765. /* Check if it's just a matter of "shrinking" us in one
  766. * direction
  767. */
  768. if (hose->mem_resources[cur].start == res->start) {
  769. DBG("U3/HT: shrink start of %d, %08lx -> %08lx\n",
  770. cur, hose->mem_resources[cur].start,
  771. res->end + 1);
  772. hose->mem_resources[cur].start = res->end + 1;
  773. continue;
  774. }
  775. if (hose->mem_resources[cur].end == res->end) {
  776. DBG("U3/HT: shrink end of %d, %08lx -> %08lx\n",
  777. cur, hose->mem_resources[cur].end,
  778. res->start - 1);
  779. hose->mem_resources[cur].end = res->start - 1;
  780. continue;
  781. }
  782. /* No, it's not the case, we need a hole */
  783. if (cur == 2) {
  784. /* not enough resources for a hole, we drop part
  785. * of the range
  786. */
  787. printk(KERN_WARNING "Running out of resources"
  788. " for /ht host !\n");
  789. hose->mem_resources[cur].end = res->start - 1;
  790. continue;
  791. }
  792. cur++;
  793. DBG("U3/HT: hole, %d end at %08lx, %d start at %08lx\n",
  794. cur-1, res->start - 1, cur, res->end + 1);
  795. hose->mem_resources[cur].name = np->full_name;
  796. hose->mem_resources[cur].flags = IORESOURCE_MEM;
  797. hose->mem_resources[cur].start = res->end + 1;
  798. hose->mem_resources[cur].end = hose->mem_resources[cur-1].end;
  799. hose->mem_resources[cur-1].end = res->start - 1;
  800. }
  801. }
  802. #endif /* CONFIG_PPC64 */
  803. /*
  804. * We assume that if we have a G3 powermac, we have one bridge called
  805. * "pci" (a MPC106) and no bandit or chaos bridges, and contrariwise,
  806. * if we have one or more bandit or chaos bridges, we don't have a MPC106.
  807. */
  808. static int __init pmac_add_bridge(struct device_node *dev)
  809. {
  810. int len;
  811. struct pci_controller *hose;
  812. struct resource rsrc;
  813. char *disp_name;
  814. const int *bus_range;
  815. int primary = 1, has_address = 0;
  816. DBG("Adding PCI host bridge %s\n", dev->full_name);
  817. /* Fetch host bridge registers address */
  818. has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
  819. /* Get bus range if any */
  820. bus_range = of_get_property(dev, "bus-range", &len);
  821. if (bus_range == NULL || len < 2 * sizeof(int)) {
  822. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  823. " bus 0\n", dev->full_name);
  824. }
  825. hose = pcibios_alloc_controller(dev);
  826. if (!hose)
  827. return -ENOMEM;
  828. hose->first_busno = bus_range ? bus_range[0] : 0;
  829. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  830. disp_name = NULL;
  831. /* 64 bits only bridges */
  832. #ifdef CONFIG_PPC64
  833. if (of_device_is_compatible(dev, "u3-agp")) {
  834. setup_u3_agp(hose);
  835. disp_name = "U3-AGP";
  836. primary = 0;
  837. } else if (of_device_is_compatible(dev, "u3-ht")) {
  838. setup_u3_ht(hose);
  839. disp_name = "U3-HT";
  840. primary = 1;
  841. } else if (of_device_is_compatible(dev, "u4-pcie")) {
  842. setup_u4_pcie(hose);
  843. disp_name = "U4-PCIE";
  844. primary = 0;
  845. }
  846. printk(KERN_INFO "Found %s PCI host bridge. Firmware bus number:"
  847. " %d->%d\n", disp_name, hose->first_busno, hose->last_busno);
  848. #endif /* CONFIG_PPC64 */
  849. /* 32 bits only bridges */
  850. #ifdef CONFIG_PPC32
  851. if (of_device_is_compatible(dev, "uni-north")) {
  852. primary = setup_uninorth(hose, &rsrc);
  853. disp_name = "UniNorth";
  854. } else if (strcmp(dev->name, "pci") == 0) {
  855. /* XXX assume this is a mpc106 (grackle) */
  856. setup_grackle(hose);
  857. disp_name = "Grackle (MPC106)";
  858. } else if (strcmp(dev->name, "bandit") == 0) {
  859. setup_bandit(hose, &rsrc);
  860. disp_name = "Bandit";
  861. } else if (strcmp(dev->name, "chaos") == 0) {
  862. setup_chaos(hose, &rsrc);
  863. disp_name = "Chaos";
  864. primary = 0;
  865. }
  866. printk(KERN_INFO "Found %s PCI host bridge at 0x%016llx. "
  867. "Firmware bus number: %d->%d\n",
  868. disp_name, (unsigned long long)rsrc.start, hose->first_busno,
  869. hose->last_busno);
  870. #endif /* CONFIG_PPC32 */
  871. DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  872. hose, hose->cfg_addr, hose->cfg_data);
  873. /* Interpret the "ranges" property */
  874. /* This also maps the I/O region and sets isa_io/mem_base */
  875. pci_process_bridge_OF_ranges(hose, dev, primary);
  876. /* Fixup "bus-range" OF property */
  877. fixup_bus_range(dev);
  878. return 0;
  879. }
  880. void __devinit pmac_pci_irq_fixup(struct pci_dev *dev)
  881. {
  882. #ifdef CONFIG_PPC32
  883. /* Fixup interrupt for the modem/ethernet combo controller.
  884. * on machines with a second ohare chip.
  885. * The number in the device tree (27) is bogus (correct for
  886. * the ethernet-only board but not the combo ethernet/modem
  887. * board). The real interrupt is 28 on the second controller
  888. * -> 28+32 = 60.
  889. */
  890. if (has_second_ohare &&
  891. dev->vendor == PCI_VENDOR_ID_DEC &&
  892. dev->device == PCI_DEVICE_ID_DEC_TULIP_PLUS) {
  893. dev->irq = irq_create_mapping(NULL, 60);
  894. set_irq_type(dev->irq, IRQ_TYPE_LEVEL_LOW);
  895. }
  896. #endif /* CONFIG_PPC32 */
  897. }
  898. void __init pmac_pci_init(void)
  899. {
  900. struct device_node *np, *root;
  901. struct device_node *ht = NULL;
  902. root = of_find_node_by_path("/");
  903. if (root == NULL) {
  904. printk(KERN_CRIT "pmac_pci_init: can't find root "
  905. "of device tree\n");
  906. return;
  907. }
  908. for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
  909. if (np->name == NULL)
  910. continue;
  911. if (strcmp(np->name, "bandit") == 0
  912. || strcmp(np->name, "chaos") == 0
  913. || strcmp(np->name, "pci") == 0) {
  914. if (pmac_add_bridge(np) == 0)
  915. of_node_get(np);
  916. }
  917. if (strcmp(np->name, "ht") == 0) {
  918. of_node_get(np);
  919. ht = np;
  920. }
  921. }
  922. of_node_put(root);
  923. #ifdef CONFIG_PPC64
  924. /* Probe HT last as it relies on the agp resources to be already
  925. * setup
  926. */
  927. if (ht && pmac_add_bridge(ht) != 0)
  928. of_node_put(ht);
  929. /* Setup the linkage between OF nodes and PHBs */
  930. pci_devs_phb_init();
  931. /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We
  932. * assume there is no P2P bridge on the AGP bus, which should be a
  933. * safe assumptions for now. We should do something better in the
  934. * future though
  935. */
  936. if (u3_agp) {
  937. struct device_node *np = u3_agp->arch_data;
  938. PCI_DN(np)->busno = 0xf0;
  939. for (np = np->child; np; np = np->sibling)
  940. PCI_DN(np)->busno = 0xf0;
  941. }
  942. /* pmac_check_ht_link(); */
  943. /* Tell pci.c to not use the common resource allocation mechanism */
  944. pci_probe_only = 1;
  945. #else /* CONFIG_PPC64 */
  946. init_p2pbridge();
  947. init_second_ohare();
  948. fixup_nec_usb2();
  949. /* We are still having some issues with the Xserve G4, enabling
  950. * some offset between bus number and domains for now when we
  951. * assign all busses should help for now
  952. */
  953. if (pci_assign_all_buses)
  954. pcibios_assign_bus_offset = 0x10;
  955. #endif
  956. }
  957. int
  958. pmac_pci_enable_device_hook(struct pci_dev *dev, int initial)
  959. {
  960. struct device_node* node;
  961. int updatecfg = 0;
  962. int uninorth_child;
  963. node = pci_device_to_OF_node(dev);
  964. /* We don't want to enable USB controllers absent from the OF tree
  965. * (iBook second controller)
  966. */
  967. if (dev->vendor == PCI_VENDOR_ID_APPLE
  968. && dev->class == PCI_CLASS_SERIAL_USB_OHCI
  969. && !node) {
  970. printk(KERN_INFO "Apple USB OHCI %s disabled by firmware\n",
  971. pci_name(dev));
  972. return -EINVAL;
  973. }
  974. if (!node)
  975. return 0;
  976. uninorth_child = node->parent &&
  977. of_device_is_compatible(node->parent, "uni-north");
  978. /* Firewire & GMAC were disabled after PCI probe, the driver is
  979. * claiming them, we must re-enable them now.
  980. */
  981. if (uninorth_child && !strcmp(node->name, "firewire") &&
  982. (of_device_is_compatible(node, "pci106b,18") ||
  983. of_device_is_compatible(node, "pci106b,30") ||
  984. of_device_is_compatible(node, "pci11c1,5811"))) {
  985. pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, node, 0, 1);
  986. pmac_call_feature(PMAC_FTR_1394_ENABLE, node, 0, 1);
  987. updatecfg = 1;
  988. }
  989. if (uninorth_child && !strcmp(node->name, "ethernet") &&
  990. of_device_is_compatible(node, "gmac")) {
  991. pmac_call_feature(PMAC_FTR_GMAC_ENABLE, node, 0, 1);
  992. updatecfg = 1;
  993. }
  994. if (updatecfg) {
  995. u16 cmd;
  996. /*
  997. * Make sure PCI is correctly configured
  998. *
  999. * We use old pci_bios versions of the function since, by
  1000. * default, gmac is not powered up, and so will be absent
  1001. * from the kernel initial PCI lookup.
  1002. *
  1003. * Should be replaced by 2.4 new PCI mechanisms and really
  1004. * register the device.
  1005. */
  1006. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1007. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  1008. | PCI_COMMAND_INVALIDATE;
  1009. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1010. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 16);
  1011. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
  1012. L1_CACHE_BYTES >> 2);
  1013. }
  1014. return 0;
  1015. }
  1016. /* We power down some devices after they have been probed. They'll
  1017. * be powered back on later on
  1018. */
  1019. void __init pmac_pcibios_after_init(void)
  1020. {
  1021. struct device_node* nd;
  1022. #ifdef CONFIG_BLK_DEV_IDE
  1023. struct pci_dev *dev = NULL;
  1024. /* OF fails to initialize IDE controllers on macs
  1025. * (and maybe other machines)
  1026. *
  1027. * Ideally, this should be moved to the IDE layer, but we need
  1028. * to check specifically with Andre Hedrick how to do it cleanly
  1029. * since the common IDE code seem to care about the fact that the
  1030. * BIOS may have disabled a controller.
  1031. *
  1032. * -- BenH
  1033. */
  1034. for_each_pci_dev(dev) {
  1035. if ((dev->class >> 16) != PCI_BASE_CLASS_STORAGE)
  1036. continue;
  1037. if (pci_enable_device(dev))
  1038. printk(KERN_WARNING
  1039. "pci: Failed to enable %s\n", pci_name(dev));
  1040. }
  1041. #endif /* CONFIG_BLK_DEV_IDE */
  1042. for_each_node_by_name(nd, "firewire") {
  1043. if (nd->parent && (of_device_is_compatible(nd, "pci106b,18") ||
  1044. of_device_is_compatible(nd, "pci106b,30") ||
  1045. of_device_is_compatible(nd, "pci11c1,5811"))
  1046. && of_device_is_compatible(nd->parent, "uni-north")) {
  1047. pmac_call_feature(PMAC_FTR_1394_ENABLE, nd, 0, 0);
  1048. pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, nd, 0, 0);
  1049. }
  1050. }
  1051. of_node_put(nd);
  1052. for_each_node_by_name(nd, "ethernet") {
  1053. if (nd->parent && of_device_is_compatible(nd, "gmac")
  1054. && of_device_is_compatible(nd->parent, "uni-north"))
  1055. pmac_call_feature(PMAC_FTR_GMAC_ENABLE, nd, 0, 0);
  1056. }
  1057. of_node_put(nd);
  1058. }
  1059. #ifdef CONFIG_PPC32
  1060. void pmac_pci_fixup_cardbus(struct pci_dev* dev)
  1061. {
  1062. if (!machine_is(powermac))
  1063. return;
  1064. /*
  1065. * Fix the interrupt routing on the various cardbus bridges
  1066. * used on powerbooks
  1067. */
  1068. if (dev->vendor != PCI_VENDOR_ID_TI)
  1069. return;
  1070. if (dev->device == PCI_DEVICE_ID_TI_1130 ||
  1071. dev->device == PCI_DEVICE_ID_TI_1131) {
  1072. u8 val;
  1073. /* Enable PCI interrupt */
  1074. if (pci_read_config_byte(dev, 0x91, &val) == 0)
  1075. pci_write_config_byte(dev, 0x91, val | 0x30);
  1076. /* Disable ISA interrupt mode */
  1077. if (pci_read_config_byte(dev, 0x92, &val) == 0)
  1078. pci_write_config_byte(dev, 0x92, val & ~0x06);
  1079. }
  1080. if (dev->device == PCI_DEVICE_ID_TI_1210 ||
  1081. dev->device == PCI_DEVICE_ID_TI_1211 ||
  1082. dev->device == PCI_DEVICE_ID_TI_1410 ||
  1083. dev->device == PCI_DEVICE_ID_TI_1510) {
  1084. u8 val;
  1085. /* 0x8c == TI122X_IRQMUX, 2 says to route the INTA
  1086. signal out the MFUNC0 pin */
  1087. if (pci_read_config_byte(dev, 0x8c, &val) == 0)
  1088. pci_write_config_byte(dev, 0x8c, (val & ~0x0f) | 2);
  1089. /* Disable ISA interrupt mode */
  1090. if (pci_read_config_byte(dev, 0x92, &val) == 0)
  1091. pci_write_config_byte(dev, 0x92, val & ~0x06);
  1092. }
  1093. }
  1094. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_ANY_ID, pmac_pci_fixup_cardbus);
  1095. void pmac_pci_fixup_pciata(struct pci_dev* dev)
  1096. {
  1097. u8 progif = 0;
  1098. /*
  1099. * On PowerMacs, we try to switch any PCI ATA controller to
  1100. * fully native mode
  1101. */
  1102. if (!machine_is(powermac))
  1103. return;
  1104. /* Some controllers don't have the class IDE */
  1105. if (dev->vendor == PCI_VENDOR_ID_PROMISE)
  1106. switch(dev->device) {
  1107. case PCI_DEVICE_ID_PROMISE_20246:
  1108. case PCI_DEVICE_ID_PROMISE_20262:
  1109. case PCI_DEVICE_ID_PROMISE_20263:
  1110. case PCI_DEVICE_ID_PROMISE_20265:
  1111. case PCI_DEVICE_ID_PROMISE_20267:
  1112. case PCI_DEVICE_ID_PROMISE_20268:
  1113. case PCI_DEVICE_ID_PROMISE_20269:
  1114. case PCI_DEVICE_ID_PROMISE_20270:
  1115. case PCI_DEVICE_ID_PROMISE_20271:
  1116. case PCI_DEVICE_ID_PROMISE_20275:
  1117. case PCI_DEVICE_ID_PROMISE_20276:
  1118. case PCI_DEVICE_ID_PROMISE_20277:
  1119. goto good;
  1120. }
  1121. /* Others, check PCI class */
  1122. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
  1123. return;
  1124. good:
  1125. pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
  1126. if ((progif & 5) != 5) {
  1127. printk(KERN_INFO "Forcing PCI IDE into native mode: %s\n",
  1128. pci_name(dev));
  1129. (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5);
  1130. if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) ||
  1131. (progif & 5) != 5)
  1132. printk(KERN_ERR "Rewrite of PROGIF failed !\n");
  1133. }
  1134. }
  1135. DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pmac_pci_fixup_pciata);
  1136. #endif
  1137. /*
  1138. * Disable second function on K2-SATA, it's broken
  1139. * and disable IO BARs on first one
  1140. */
  1141. static void fixup_k2_sata(struct pci_dev* dev)
  1142. {
  1143. int i;
  1144. u16 cmd;
  1145. if (PCI_FUNC(dev->devfn) > 0) {
  1146. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1147. cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  1148. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1149. for (i = 0; i < 6; i++) {
  1150. dev->resource[i].start = dev->resource[i].end = 0;
  1151. dev->resource[i].flags = 0;
  1152. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
  1153. 0);
  1154. }
  1155. } else {
  1156. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  1157. cmd &= ~PCI_COMMAND_IO;
  1158. pci_write_config_word(dev, PCI_COMMAND, cmd);
  1159. for (i = 0; i < 5; i++) {
  1160. dev->resource[i].start = dev->resource[i].end = 0;
  1161. dev->resource[i].flags = 0;
  1162. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i,
  1163. 0);
  1164. }
  1165. }
  1166. }
  1167. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS, 0x0240, fixup_k2_sata);