pci.c 38 KB

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