pci.c 36 KB

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