pci.c 35 KB

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