pci.c 35 KB

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