pci.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  1. /*
  2. * Common prep/chrp pci routines. -- Cort
  3. */
  4. #include <linux/config.h>
  5. #include <linux/kernel.h>
  6. #include <linux/pci.h>
  7. #include <linux/delay.h>
  8. #include <linux/string.h>
  9. #include <linux/init.h>
  10. #include <linux/capability.h>
  11. #include <linux/sched.h>
  12. #include <linux/errno.h>
  13. #include <linux/bootmem.h>
  14. #include <asm/processor.h>
  15. #include <asm/io.h>
  16. #include <asm/prom.h>
  17. #include <asm/sections.h>
  18. #include <asm/pci-bridge.h>
  19. #include <asm/byteorder.h>
  20. #include <asm/irq.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/machdep.h>
  23. #undef DEBUG
  24. #ifdef DEBUG
  25. #define DBG(x...) printk(x)
  26. #else
  27. #define DBG(x...)
  28. #endif
  29. unsigned long isa_io_base = 0;
  30. unsigned long isa_mem_base = 0;
  31. unsigned long pci_dram_offset = 0;
  32. int pcibios_assign_bus_offset = 1;
  33. void pcibios_make_OF_bus_map(void);
  34. static int pci_relocate_bridge_resource(struct pci_bus *bus, int i);
  35. static int probe_resource(struct pci_bus *parent, struct resource *pr,
  36. struct resource *res, struct resource **conflict);
  37. static void update_bridge_base(struct pci_bus *bus, int i);
  38. static void pcibios_fixup_resources(struct pci_dev* dev);
  39. static void fixup_broken_pcnet32(struct pci_dev* dev);
  40. static int reparent_resources(struct resource *parent, struct resource *res);
  41. static void fixup_cpc710_pci64(struct pci_dev* dev);
  42. /* By default, we don't re-assign bus numbers.
  43. */
  44. int pci_assign_all_buses;
  45. struct pci_controller* hose_head;
  46. struct pci_controller** hose_tail = &hose_head;
  47. static int pci_bus_count;
  48. static void
  49. fixup_broken_pcnet32(struct pci_dev* dev)
  50. {
  51. if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
  52. dev->vendor = PCI_VENDOR_ID_AMD;
  53. pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
  54. }
  55. }
  56. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32);
  57. static void
  58. fixup_cpc710_pci64(struct pci_dev* dev)
  59. {
  60. /* Hide the PCI64 BARs from the kernel as their content doesn't
  61. * fit well in the resource management
  62. */
  63. dev->resource[0].start = dev->resource[0].end = 0;
  64. dev->resource[0].flags = 0;
  65. dev->resource[1].start = dev->resource[1].end = 0;
  66. dev->resource[1].flags = 0;
  67. }
  68. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64);
  69. static void
  70. pcibios_fixup_resources(struct pci_dev *dev)
  71. {
  72. struct pci_controller* hose = (struct pci_controller *)dev->sysdata;
  73. int i;
  74. unsigned long offset;
  75. if (!hose) {
  76. printk(KERN_ERR "No hose for PCI dev %s!\n", pci_name(dev));
  77. return;
  78. }
  79. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  80. struct resource *res = dev->resource + i;
  81. if (!res->flags)
  82. continue;
  83. if (res->end == 0xffffffff) {
  84. DBG("PCI:%s Resource %d [%016llx-%016llx] is unassigned\n",
  85. pci_name(dev), i,
  86. (unsigned long long)res->start,
  87. (unsigned long long)res->end);
  88. res->end -= res->start;
  89. res->start = 0;
  90. res->flags |= IORESOURCE_UNSET;
  91. continue;
  92. }
  93. offset = 0;
  94. if (res->flags & IORESOURCE_MEM) {
  95. offset = hose->pci_mem_offset;
  96. } else if (res->flags & IORESOURCE_IO) {
  97. offset = (unsigned long) hose->io_base_virt
  98. - isa_io_base;
  99. }
  100. if (offset != 0) {
  101. res->start += offset;
  102. res->end += offset;
  103. #ifdef DEBUG
  104. printk("Fixup res %d (%lx) of dev %s: %lx -> %lx\n",
  105. i, res->flags, pci_name(dev),
  106. res->start - offset, res->start);
  107. #endif
  108. }
  109. }
  110. /* Call machine specific resource fixup */
  111. if (ppc_md.pcibios_fixup_resources)
  112. ppc_md.pcibios_fixup_resources(dev);
  113. }
  114. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_resources);
  115. void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  116. struct resource *res)
  117. {
  118. unsigned long offset = 0;
  119. struct pci_controller *hose = dev->sysdata;
  120. if (hose && res->flags & IORESOURCE_IO)
  121. offset = (unsigned long)hose->io_base_virt - isa_io_base;
  122. else if (hose && res->flags & IORESOURCE_MEM)
  123. offset = hose->pci_mem_offset;
  124. region->start = res->start - offset;
  125. region->end = res->end - offset;
  126. }
  127. EXPORT_SYMBOL(pcibios_resource_to_bus);
  128. void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  129. struct pci_bus_region *region)
  130. {
  131. unsigned long offset = 0;
  132. struct pci_controller *hose = dev->sysdata;
  133. if (hose && res->flags & IORESOURCE_IO)
  134. offset = (unsigned long)hose->io_base_virt - isa_io_base;
  135. else if (hose && res->flags & IORESOURCE_MEM)
  136. offset = hose->pci_mem_offset;
  137. res->start = region->start + offset;
  138. res->end = region->end + offset;
  139. }
  140. EXPORT_SYMBOL(pcibios_bus_to_resource);
  141. /*
  142. * We need to avoid collisions with `mirrored' VGA ports
  143. * and other strange ISA hardware, so we always want the
  144. * addresses to be allocated in the 0x000-0x0ff region
  145. * modulo 0x400.
  146. *
  147. * Why? Because some silly external IO cards only decode
  148. * the low 10 bits of the IO address. The 0x00-0xff region
  149. * is reserved for motherboard devices that decode all 16
  150. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  151. * but we want to try to avoid allocating at 0x2900-0x2bff
  152. * which might have be mirrored at 0x0100-0x03ff..
  153. */
  154. void pcibios_align_resource(void *data, struct resource *res,
  155. resource_size_t size, resource_size_t align)
  156. {
  157. struct pci_dev *dev = data;
  158. if (res->flags & IORESOURCE_IO) {
  159. resource_size_t start = res->start;
  160. if (size > 0x100) {
  161. printk(KERN_ERR "PCI: I/O Region %s/%d too large"
  162. " (%lld bytes)\n", pci_name(dev),
  163. dev->resource - res, (unsigned long long)size);
  164. }
  165. if (start & 0x300) {
  166. start = (start + 0x3ff) & ~0x3ff;
  167. res->start = start;
  168. }
  169. }
  170. }
  171. EXPORT_SYMBOL(pcibios_align_resource);
  172. /*
  173. * Handle resources of PCI devices. If the world were perfect, we could
  174. * just allocate all the resource regions and do nothing more. It isn't.
  175. * On the other hand, we cannot just re-allocate all devices, as it would
  176. * require us to know lots of host bridge internals. So we attempt to
  177. * keep as much of the original configuration as possible, but tweak it
  178. * when it's found to be wrong.
  179. *
  180. * Known BIOS problems we have to work around:
  181. * - I/O or memory regions not configured
  182. * - regions configured, but not enabled in the command register
  183. * - bogus I/O addresses above 64K used
  184. * - expansion ROMs left enabled (this may sound harmless, but given
  185. * the fact the PCI specs explicitly allow address decoders to be
  186. * shared between expansion ROMs and other resource regions, it's
  187. * at least dangerous)
  188. *
  189. * Our solution:
  190. * (1) Allocate resources for all buses behind PCI-to-PCI bridges.
  191. * This gives us fixed barriers on where we can allocate.
  192. * (2) Allocate resources for all enabled devices. If there is
  193. * a collision, just mark the resource as unallocated. Also
  194. * disable expansion ROMs during this step.
  195. * (3) Try to allocate resources for disabled devices. If the
  196. * resources were assigned correctly, everything goes well,
  197. * if they weren't, they won't disturb allocation of other
  198. * resources.
  199. * (4) Assign new addresses to resources which were either
  200. * not configured at all or misconfigured. If explicitly
  201. * requested by the user, configure expansion ROM address
  202. * as well.
  203. */
  204. static void __init
  205. pcibios_allocate_bus_resources(struct list_head *bus_list)
  206. {
  207. struct pci_bus *bus;
  208. int i;
  209. struct resource *res, *pr;
  210. /* Depth-First Search on bus tree */
  211. list_for_each_entry(bus, bus_list, node) {
  212. for (i = 0; i < 4; ++i) {
  213. if ((res = bus->resource[i]) == NULL || !res->flags
  214. || res->start > res->end)
  215. continue;
  216. if (bus->parent == NULL)
  217. pr = (res->flags & IORESOURCE_IO)?
  218. &ioport_resource: &iomem_resource;
  219. else {
  220. pr = pci_find_parent_resource(bus->self, res);
  221. if (pr == res) {
  222. /* this happens when the generic PCI
  223. * code (wrongly) decides that this
  224. * bridge is transparent -- paulus
  225. */
  226. continue;
  227. }
  228. }
  229. DBG("PCI: bridge rsrc %llx..%llx (%lx), parent %p\n",
  230. (unsigned long long)res->start,
  231. (unsigned long long)res->end, res->flags, pr);
  232. if (pr) {
  233. if (request_resource(pr, res) == 0)
  234. continue;
  235. /*
  236. * Must be a conflict with an existing entry.
  237. * Move that entry (or entries) under the
  238. * bridge resource and try again.
  239. */
  240. if (reparent_resources(pr, res) == 0)
  241. continue;
  242. }
  243. printk(KERN_ERR "PCI: Cannot allocate resource region "
  244. "%d of PCI bridge %d\n", i, bus->number);
  245. if (pci_relocate_bridge_resource(bus, i))
  246. bus->resource[i] = NULL;
  247. }
  248. pcibios_allocate_bus_resources(&bus->children);
  249. }
  250. }
  251. /*
  252. * Reparent resource children of pr that conflict with res
  253. * under res, and make res replace those children.
  254. */
  255. static int __init
  256. reparent_resources(struct resource *parent, struct resource *res)
  257. {
  258. struct resource *p, **pp;
  259. struct resource **firstpp = NULL;
  260. for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {
  261. if (p->end < res->start)
  262. continue;
  263. if (res->end < p->start)
  264. break;
  265. if (p->start < res->start || p->end > res->end)
  266. return -1; /* not completely contained */
  267. if (firstpp == NULL)
  268. firstpp = pp;
  269. }
  270. if (firstpp == NULL)
  271. return -1; /* didn't find any conflicting entries? */
  272. res->parent = parent;
  273. res->child = *firstpp;
  274. res->sibling = *pp;
  275. *firstpp = res;
  276. *pp = NULL;
  277. for (p = res->child; p != NULL; p = p->sibling) {
  278. p->parent = res;
  279. DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n",
  280. p->name, (unsigned long long)p->start,
  281. (unsigned long long)p->end, res->name);
  282. }
  283. return 0;
  284. }
  285. /*
  286. * A bridge has been allocated a range which is outside the range
  287. * of its parent bridge, so it needs to be moved.
  288. */
  289. static int __init
  290. pci_relocate_bridge_resource(struct pci_bus *bus, int i)
  291. {
  292. struct resource *res, *pr, *conflict;
  293. unsigned long try, size;
  294. int j;
  295. struct pci_bus *parent = bus->parent;
  296. if (parent == NULL) {
  297. /* shouldn't ever happen */
  298. printk(KERN_ERR "PCI: can't move host bridge resource\n");
  299. return -1;
  300. }
  301. res = bus->resource[i];
  302. if (res == NULL)
  303. return -1;
  304. pr = NULL;
  305. for (j = 0; j < 4; j++) {
  306. struct resource *r = parent->resource[j];
  307. if (!r)
  308. continue;
  309. if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
  310. continue;
  311. if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) {
  312. pr = r;
  313. break;
  314. }
  315. if (res->flags & IORESOURCE_PREFETCH)
  316. pr = r;
  317. }
  318. if (pr == NULL)
  319. return -1;
  320. size = res->end - res->start;
  321. if (pr->start > pr->end || size > pr->end - pr->start)
  322. return -1;
  323. try = pr->end;
  324. for (;;) {
  325. res->start = try - size;
  326. res->end = try;
  327. if (probe_resource(bus->parent, pr, res, &conflict) == 0)
  328. break;
  329. if (conflict->start <= pr->start + size)
  330. return -1;
  331. try = conflict->start - 1;
  332. }
  333. if (request_resource(pr, res)) {
  334. DBG(KERN_ERR "PCI: huh? couldn't move to %llx..%llx\n",
  335. (unsigned long long)res->start,
  336. (unsigned long long)res->end);
  337. return -1; /* "can't happen" */
  338. }
  339. update_bridge_base(bus, i);
  340. printk(KERN_INFO "PCI: bridge %d resource %d moved to %llx..%llx\n",
  341. bus->number, i, (unsigned long long)res->start,
  342. (unsigned long long)res->end);
  343. return 0;
  344. }
  345. static int __init
  346. probe_resource(struct pci_bus *parent, struct resource *pr,
  347. struct resource *res, struct resource **conflict)
  348. {
  349. struct pci_bus *bus;
  350. struct pci_dev *dev;
  351. struct resource *r;
  352. int i;
  353. for (r = pr->child; r != NULL; r = r->sibling) {
  354. if (r->end >= res->start && res->end >= r->start) {
  355. *conflict = r;
  356. return 1;
  357. }
  358. }
  359. list_for_each_entry(bus, &parent->children, node) {
  360. for (i = 0; i < 4; ++i) {
  361. if ((r = bus->resource[i]) == NULL)
  362. continue;
  363. if (!r->flags || r->start > r->end || r == res)
  364. continue;
  365. if (pci_find_parent_resource(bus->self, r) != pr)
  366. continue;
  367. if (r->end >= res->start && res->end >= r->start) {
  368. *conflict = r;
  369. return 1;
  370. }
  371. }
  372. }
  373. list_for_each_entry(dev, &parent->devices, bus_list) {
  374. for (i = 0; i < 6; ++i) {
  375. r = &dev->resource[i];
  376. if (!r->flags || (r->flags & IORESOURCE_UNSET))
  377. continue;
  378. if (pci_find_parent_resource(dev, r) != pr)
  379. continue;
  380. if (r->end >= res->start && res->end >= r->start) {
  381. *conflict = r;
  382. return 1;
  383. }
  384. }
  385. }
  386. return 0;
  387. }
  388. static void __init
  389. update_bridge_base(struct pci_bus *bus, int i)
  390. {
  391. struct resource *res = bus->resource[i];
  392. u8 io_base_lo, io_limit_lo;
  393. u16 mem_base, mem_limit;
  394. u16 cmd;
  395. unsigned long start, end, off;
  396. struct pci_dev *dev = bus->self;
  397. struct pci_controller *hose = dev->sysdata;
  398. if (!hose) {
  399. printk("update_bridge_base: no hose?\n");
  400. return;
  401. }
  402. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  403. pci_write_config_word(dev, PCI_COMMAND,
  404. cmd & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
  405. if (res->flags & IORESOURCE_IO) {
  406. off = (unsigned long) hose->io_base_virt - isa_io_base;
  407. start = res->start - off;
  408. end = res->end - off;
  409. io_base_lo = (start >> 8) & PCI_IO_RANGE_MASK;
  410. io_limit_lo = (end >> 8) & PCI_IO_RANGE_MASK;
  411. if (end > 0xffff) {
  412. pci_write_config_word(dev, PCI_IO_BASE_UPPER16,
  413. start >> 16);
  414. pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16,
  415. end >> 16);
  416. io_base_lo |= PCI_IO_RANGE_TYPE_32;
  417. } else
  418. io_base_lo |= PCI_IO_RANGE_TYPE_16;
  419. pci_write_config_byte(dev, PCI_IO_BASE, io_base_lo);
  420. pci_write_config_byte(dev, PCI_IO_LIMIT, io_limit_lo);
  421. } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
  422. == IORESOURCE_MEM) {
  423. off = hose->pci_mem_offset;
  424. mem_base = ((res->start - off) >> 16) & PCI_MEMORY_RANGE_MASK;
  425. mem_limit = ((res->end - off) >> 16) & PCI_MEMORY_RANGE_MASK;
  426. pci_write_config_word(dev, PCI_MEMORY_BASE, mem_base);
  427. pci_write_config_word(dev, PCI_MEMORY_LIMIT, mem_limit);
  428. } else if ((res->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH))
  429. == (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
  430. off = hose->pci_mem_offset;
  431. mem_base = ((res->start - off) >> 16) & PCI_PREF_RANGE_MASK;
  432. mem_limit = ((res->end - off) >> 16) & PCI_PREF_RANGE_MASK;
  433. pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, mem_base);
  434. pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, mem_limit);
  435. } else {
  436. DBG(KERN_ERR "PCI: ugh, bridge %s res %d has flags=%lx\n",
  437. pci_name(dev), i, res->flags);
  438. }
  439. pci_write_config_word(dev, PCI_COMMAND, cmd);
  440. }
  441. static inline void alloc_resource(struct pci_dev *dev, int idx)
  442. {
  443. struct resource *pr, *r = &dev->resource[idx];
  444. DBG("PCI:%s: Resource %d: %016llx-%016llx (f=%lx)\n",
  445. pci_name(dev), idx, (unsigned long long)r->start,
  446. (unsigned long long)r->end, r->flags);
  447. pr = pci_find_parent_resource(dev, r);
  448. if (!pr || request_resource(pr, r) < 0) {
  449. printk(KERN_ERR "PCI: Cannot allocate resource region %d"
  450. " of device %s\n", idx, pci_name(dev));
  451. if (pr)
  452. DBG("PCI: parent is %p: %016llx-%016llx (f=%lx)\n",
  453. pr, (unsigned long long)pr->start,
  454. (unsigned long long)pr->end, pr->flags);
  455. /* We'll assign a new address later */
  456. r->flags |= IORESOURCE_UNSET;
  457. r->end -= r->start;
  458. r->start = 0;
  459. }
  460. }
  461. static void __init
  462. pcibios_allocate_resources(int pass)
  463. {
  464. struct pci_dev *dev = NULL;
  465. int idx, disabled;
  466. u16 command;
  467. struct resource *r;
  468. for_each_pci_dev(dev) {
  469. pci_read_config_word(dev, PCI_COMMAND, &command);
  470. for (idx = 0; idx < 6; idx++) {
  471. r = &dev->resource[idx];
  472. if (r->parent) /* Already allocated */
  473. continue;
  474. if (!r->flags || (r->flags & IORESOURCE_UNSET))
  475. continue; /* Not assigned at all */
  476. if (r->flags & IORESOURCE_IO)
  477. disabled = !(command & PCI_COMMAND_IO);
  478. else
  479. disabled = !(command & PCI_COMMAND_MEMORY);
  480. if (pass == disabled)
  481. alloc_resource(dev, idx);
  482. }
  483. if (pass)
  484. continue;
  485. r = &dev->resource[PCI_ROM_RESOURCE];
  486. if (r->flags & IORESOURCE_ROM_ENABLE) {
  487. /* Turn the ROM off, leave the resource region, but keep it unregistered. */
  488. u32 reg;
  489. DBG("PCI: Switching off ROM of %s\n", pci_name(dev));
  490. r->flags &= ~IORESOURCE_ROM_ENABLE;
  491. pci_read_config_dword(dev, dev->rom_base_reg, &reg);
  492. pci_write_config_dword(dev, dev->rom_base_reg,
  493. reg & ~PCI_ROM_ADDRESS_ENABLE);
  494. }
  495. }
  496. }
  497. static void __init
  498. pcibios_assign_resources(void)
  499. {
  500. struct pci_dev *dev = NULL;
  501. int idx;
  502. struct resource *r;
  503. for_each_pci_dev(dev) {
  504. int class = dev->class >> 8;
  505. /* Don't touch classless devices and host bridges */
  506. if (!class || class == PCI_CLASS_BRIDGE_HOST)
  507. continue;
  508. for (idx = 0; idx < 6; idx++) {
  509. r = &dev->resource[idx];
  510. /*
  511. * We shall assign a new address to this resource,
  512. * either because the BIOS (sic) forgot to do so
  513. * or because we have decided the old address was
  514. * unusable for some reason.
  515. */
  516. if ((r->flags & IORESOURCE_UNSET) && r->end &&
  517. (!ppc_md.pcibios_enable_device_hook ||
  518. !ppc_md.pcibios_enable_device_hook(dev, 1))) {
  519. r->flags &= ~IORESOURCE_UNSET;
  520. pci_assign_resource(dev, idx);
  521. }
  522. }
  523. #if 0 /* don't assign ROMs */
  524. r = &dev->resource[PCI_ROM_RESOURCE];
  525. r->end -= r->start;
  526. r->start = 0;
  527. if (r->end)
  528. pci_assign_resource(dev, PCI_ROM_RESOURCE);
  529. #endif
  530. }
  531. }
  532. int
  533. pcibios_enable_resources(struct pci_dev *dev, int mask)
  534. {
  535. u16 cmd, old_cmd;
  536. int idx;
  537. struct resource *r;
  538. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  539. old_cmd = cmd;
  540. for (idx=0; idx<6; idx++) {
  541. /* Only set up the requested stuff */
  542. if (!(mask & (1<<idx)))
  543. continue;
  544. r = &dev->resource[idx];
  545. if (r->flags & IORESOURCE_UNSET) {
  546. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  547. return -EINVAL;
  548. }
  549. if (r->flags & IORESOURCE_IO)
  550. cmd |= PCI_COMMAND_IO;
  551. if (r->flags & IORESOURCE_MEM)
  552. cmd |= PCI_COMMAND_MEMORY;
  553. }
  554. if (dev->resource[PCI_ROM_RESOURCE].start)
  555. cmd |= PCI_COMMAND_MEMORY;
  556. if (cmd != old_cmd) {
  557. printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
  558. pci_write_config_word(dev, PCI_COMMAND, cmd);
  559. }
  560. return 0;
  561. }
  562. static int next_controller_index;
  563. struct pci_controller * __init
  564. pcibios_alloc_controller(void)
  565. {
  566. struct pci_controller *hose;
  567. hose = (struct pci_controller *)alloc_bootmem(sizeof(*hose));
  568. memset(hose, 0, sizeof(struct pci_controller));
  569. *hose_tail = hose;
  570. hose_tail = &hose->next;
  571. hose->index = next_controller_index++;
  572. return hose;
  573. }
  574. void pcibios_make_OF_bus_map(void)
  575. {
  576. }
  577. /* Add sysfs properties */
  578. void pcibios_add_platform_entries(struct pci_dev *pdev)
  579. {
  580. }
  581. static int __init
  582. pcibios_init(void)
  583. {
  584. struct pci_controller *hose;
  585. struct pci_bus *bus;
  586. int next_busno;
  587. printk(KERN_INFO "PCI: Probing PCI hardware\n");
  588. /* Scan all of the recorded PCI controllers. */
  589. for (next_busno = 0, hose = hose_head; hose; hose = hose->next) {
  590. if (pci_assign_all_buses)
  591. hose->first_busno = next_busno;
  592. hose->last_busno = 0xff;
  593. bus = pci_scan_bus(hose->first_busno, hose->ops, hose);
  594. hose->last_busno = bus->subordinate;
  595. if (pci_assign_all_buses || next_busno <= hose->last_busno)
  596. next_busno = hose->last_busno + pcibios_assign_bus_offset;
  597. }
  598. pci_bus_count = next_busno;
  599. /* OpenFirmware based machines need a map of OF bus
  600. * numbers vs. kernel bus numbers since we may have to
  601. * remap them.
  602. */
  603. if (pci_assign_all_buses && have_of)
  604. pcibios_make_OF_bus_map();
  605. /* Do machine dependent PCI interrupt routing */
  606. if (ppc_md.pci_swizzle && ppc_md.pci_map_irq)
  607. pci_fixup_irqs(ppc_md.pci_swizzle, ppc_md.pci_map_irq);
  608. /* Call machine dependent fixup */
  609. if (ppc_md.pcibios_fixup)
  610. ppc_md.pcibios_fixup();
  611. /* Allocate and assign resources */
  612. pcibios_allocate_bus_resources(&pci_root_buses);
  613. pcibios_allocate_resources(0);
  614. pcibios_allocate_resources(1);
  615. pcibios_assign_resources();
  616. /* Call machine dependent post-init code */
  617. if (ppc_md.pcibios_after_init)
  618. ppc_md.pcibios_after_init();
  619. return 0;
  620. }
  621. subsys_initcall(pcibios_init);
  622. unsigned char __init
  623. common_swizzle(struct pci_dev *dev, unsigned char *pinp)
  624. {
  625. struct pci_controller *hose = dev->sysdata;
  626. if (dev->bus->number != hose->first_busno) {
  627. u8 pin = *pinp;
  628. do {
  629. pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
  630. /* Move up the chain of bridges. */
  631. dev = dev->bus->self;
  632. } while (dev->bus->self);
  633. *pinp = pin;
  634. /* The slot is the idsel of the last bridge. */
  635. }
  636. return PCI_SLOT(dev->devfn);
  637. }
  638. unsigned long resource_fixup(struct pci_dev * dev, struct resource * res,
  639. unsigned long start, unsigned long size)
  640. {
  641. return start;
  642. }
  643. void __init pcibios_fixup_bus(struct pci_bus *bus)
  644. {
  645. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  646. unsigned long io_offset;
  647. struct resource *res;
  648. int i;
  649. io_offset = (unsigned long)hose->io_base_virt - isa_io_base;
  650. if (bus->parent == NULL) {
  651. /* This is a host bridge - fill in its resources */
  652. hose->bus = bus;
  653. bus->resource[0] = res = &hose->io_resource;
  654. if (!res->flags) {
  655. if (io_offset)
  656. printk(KERN_ERR "I/O resource not set for host"
  657. " bridge %d\n", hose->index);
  658. res->start = 0;
  659. res->end = IO_SPACE_LIMIT;
  660. res->flags = IORESOURCE_IO;
  661. }
  662. res->start += io_offset;
  663. res->end += io_offset;
  664. for (i = 0; i < 3; ++i) {
  665. res = &hose->mem_resources[i];
  666. if (!res->flags) {
  667. if (i > 0)
  668. continue;
  669. printk(KERN_ERR "Memory resource not set for "
  670. "host bridge %d\n", hose->index);
  671. res->start = hose->pci_mem_offset;
  672. res->end = ~0U;
  673. res->flags = IORESOURCE_MEM;
  674. }
  675. bus->resource[i+1] = res;
  676. }
  677. } else {
  678. /* This is a subordinate bridge */
  679. pci_read_bridge_bases(bus);
  680. for (i = 0; i < 4; ++i) {
  681. if ((res = bus->resource[i]) == NULL)
  682. continue;
  683. if (!res->flags)
  684. continue;
  685. if (io_offset && (res->flags & IORESOURCE_IO)) {
  686. res->start += io_offset;
  687. res->end += io_offset;
  688. } else if (hose->pci_mem_offset
  689. && (res->flags & IORESOURCE_MEM)) {
  690. res->start += hose->pci_mem_offset;
  691. res->end += hose->pci_mem_offset;
  692. }
  693. }
  694. }
  695. if (ppc_md.pcibios_fixup_bus)
  696. ppc_md.pcibios_fixup_bus(bus);
  697. }
  698. char __init *pcibios_setup(char *str)
  699. {
  700. return str;
  701. }
  702. /* the next one is stolen from the alpha port... */
  703. void __init
  704. pcibios_update_irq(struct pci_dev *dev, int irq)
  705. {
  706. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  707. /* XXX FIXME - update OF device tree node interrupt property */
  708. }
  709. int pcibios_enable_device(struct pci_dev *dev, int mask)
  710. {
  711. u16 cmd, old_cmd;
  712. int idx;
  713. struct resource *r;
  714. if (ppc_md.pcibios_enable_device_hook)
  715. if (ppc_md.pcibios_enable_device_hook(dev, 0))
  716. return -EINVAL;
  717. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  718. old_cmd = cmd;
  719. for (idx=0; idx<6; idx++) {
  720. r = &dev->resource[idx];
  721. if (r->flags & IORESOURCE_UNSET) {
  722. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  723. return -EINVAL;
  724. }
  725. if (r->flags & IORESOURCE_IO)
  726. cmd |= PCI_COMMAND_IO;
  727. if (r->flags & IORESOURCE_MEM)
  728. cmd |= PCI_COMMAND_MEMORY;
  729. }
  730. if (cmd != old_cmd) {
  731. printk("PCI: Enabling device %s (%04x -> %04x)\n",
  732. pci_name(dev), old_cmd, cmd);
  733. pci_write_config_word(dev, PCI_COMMAND, cmd);
  734. }
  735. return 0;
  736. }
  737. struct pci_controller*
  738. pci_bus_to_hose(int bus)
  739. {
  740. struct pci_controller* hose = hose_head;
  741. for (; hose; hose = hose->next)
  742. if (bus >= hose->first_busno && bus <= hose->last_busno)
  743. return hose;
  744. return NULL;
  745. }
  746. void __iomem *
  747. pci_bus_io_base(unsigned int bus)
  748. {
  749. struct pci_controller *hose;
  750. hose = pci_bus_to_hose(bus);
  751. if (!hose)
  752. return NULL;
  753. return hose->io_base_virt;
  754. }
  755. unsigned long
  756. pci_bus_io_base_phys(unsigned int bus)
  757. {
  758. struct pci_controller *hose;
  759. hose = pci_bus_to_hose(bus);
  760. if (!hose)
  761. return 0;
  762. return hose->io_base_phys;
  763. }
  764. unsigned long
  765. pci_bus_mem_base_phys(unsigned int bus)
  766. {
  767. struct pci_controller *hose;
  768. hose = pci_bus_to_hose(bus);
  769. if (!hose)
  770. return 0;
  771. return hose->pci_mem_offset;
  772. }
  773. unsigned long
  774. pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
  775. {
  776. /* Hack alert again ! See comments in chrp_pci.c
  777. */
  778. struct pci_controller* hose =
  779. (struct pci_controller *)pdev->sysdata;
  780. if (hose && res->flags & IORESOURCE_MEM)
  781. return res->start - hose->pci_mem_offset;
  782. /* We may want to do something with IOs here... */
  783. return res->start;
  784. }
  785. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  786. unsigned long *offset,
  787. enum pci_mmap_state mmap_state)
  788. {
  789. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  790. unsigned long io_offset = 0;
  791. int i, res_bit;
  792. if (hose == 0)
  793. return NULL; /* should never happen */
  794. /* If memory, add on the PCI bridge address offset */
  795. if (mmap_state == pci_mmap_mem) {
  796. *offset += hose->pci_mem_offset;
  797. res_bit = IORESOURCE_MEM;
  798. } else {
  799. io_offset = hose->io_base_virt - ___IO_BASE;
  800. *offset += io_offset;
  801. res_bit = IORESOURCE_IO;
  802. }
  803. /*
  804. * Check that the offset requested corresponds to one of the
  805. * resources of the device.
  806. */
  807. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  808. struct resource *rp = &dev->resource[i];
  809. int flags = rp->flags;
  810. /* treat ROM as memory (should be already) */
  811. if (i == PCI_ROM_RESOURCE)
  812. flags |= IORESOURCE_MEM;
  813. /* Active and same type? */
  814. if ((flags & res_bit) == 0)
  815. continue;
  816. /* In the range of this resource? */
  817. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  818. continue;
  819. /* found it! construct the final physical address */
  820. if (mmap_state == pci_mmap_io)
  821. *offset += hose->io_base_phys - io_offset;
  822. return rp;
  823. }
  824. return NULL;
  825. }
  826. /*
  827. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  828. * device mapping.
  829. */
  830. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  831. pgprot_t protection,
  832. enum pci_mmap_state mmap_state,
  833. int write_combine)
  834. {
  835. unsigned long prot = pgprot_val(protection);
  836. /* Write combine is always 0 on non-memory space mappings. On
  837. * memory space, if the user didn't pass 1, we check for a
  838. * "prefetchable" resource. This is a bit hackish, but we use
  839. * this to workaround the inability of /sysfs to provide a write
  840. * combine bit
  841. */
  842. if (mmap_state != pci_mmap_mem)
  843. write_combine = 0;
  844. else if (write_combine == 0) {
  845. if (rp->flags & IORESOURCE_PREFETCH)
  846. write_combine = 1;
  847. }
  848. /* XXX would be nice to have a way to ask for write-through */
  849. prot |= _PAGE_NO_CACHE;
  850. if (write_combine)
  851. prot &= ~_PAGE_GUARDED;
  852. else
  853. prot |= _PAGE_GUARDED;
  854. printk("PCI map for %s:%llx, prot: %lx\n", pci_name(dev),
  855. (unsigned long long)rp->start, prot);
  856. return __pgprot(prot);
  857. }
  858. /*
  859. * This one is used by /dev/mem and fbdev who have no clue about the
  860. * PCI device, it tries to find the PCI device first and calls the
  861. * above routine
  862. */
  863. pgprot_t pci_phys_mem_access_prot(struct file *file,
  864. unsigned long pfn,
  865. unsigned long size,
  866. pgprot_t protection)
  867. {
  868. struct pci_dev *pdev = NULL;
  869. struct resource *found = NULL;
  870. unsigned long prot = pgprot_val(protection);
  871. unsigned long offset = pfn << PAGE_SHIFT;
  872. int i;
  873. if (page_is_ram(pfn))
  874. return prot;
  875. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  876. for_each_pci_dev(pdev) {
  877. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  878. struct resource *rp = &pdev->resource[i];
  879. int flags = rp->flags;
  880. /* Active and same type? */
  881. if ((flags & IORESOURCE_MEM) == 0)
  882. continue;
  883. /* In the range of this resource? */
  884. if (offset < (rp->start & PAGE_MASK) ||
  885. offset > rp->end)
  886. continue;
  887. found = rp;
  888. break;
  889. }
  890. if (found)
  891. break;
  892. }
  893. if (found) {
  894. if (found->flags & IORESOURCE_PREFETCH)
  895. prot &= ~_PAGE_GUARDED;
  896. pci_dev_put(pdev);
  897. }
  898. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  899. return __pgprot(prot);
  900. }
  901. /*
  902. * Perform the actual remap of the pages for a PCI device mapping, as
  903. * appropriate for this architecture. The region in the process to map
  904. * is described by vm_start and vm_end members of VMA, the base physical
  905. * address is found in vm_pgoff.
  906. * The pci device structure is provided so that architectures may make mapping
  907. * decisions on a per-device or per-bus basis.
  908. *
  909. * Returns a negative error code on failure, zero on success.
  910. */
  911. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  912. enum pci_mmap_state mmap_state,
  913. int write_combine)
  914. {
  915. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  916. struct resource *rp;
  917. int ret;
  918. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  919. if (rp == NULL)
  920. return -EINVAL;
  921. vma->vm_pgoff = offset >> PAGE_SHIFT;
  922. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  923. vma->vm_page_prot,
  924. mmap_state, write_combine);
  925. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  926. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  927. return ret;
  928. }
  929. /* Obsolete functions. Should be removed once the symbios driver
  930. * is fixed
  931. */
  932. unsigned long
  933. phys_to_bus(unsigned long pa)
  934. {
  935. struct pci_controller *hose;
  936. int i;
  937. for (hose = hose_head; hose; hose = hose->next) {
  938. for (i = 0; i < 3; ++i) {
  939. if (pa >= hose->mem_resources[i].start
  940. && pa <= hose->mem_resources[i].end) {
  941. /*
  942. * XXX the hose->pci_mem_offset really
  943. * only applies to mem_resources[0].
  944. * We need a way to store an offset for
  945. * the others. -- paulus
  946. */
  947. if (i == 0)
  948. pa -= hose->pci_mem_offset;
  949. return pa;
  950. }
  951. }
  952. }
  953. /* hmmm, didn't find it */
  954. return 0;
  955. }
  956. unsigned long
  957. pci_phys_to_bus(unsigned long pa, int busnr)
  958. {
  959. struct pci_controller* hose = pci_bus_to_hose(busnr);
  960. if (!hose)
  961. return pa;
  962. return pa - hose->pci_mem_offset;
  963. }
  964. unsigned long
  965. pci_bus_to_phys(unsigned int ba, int busnr)
  966. {
  967. struct pci_controller* hose = pci_bus_to_hose(busnr);
  968. if (!hose)
  969. return ba;
  970. return ba + hose->pci_mem_offset;
  971. }
  972. /* Provide information on locations of various I/O regions in physical
  973. * memory. Do this on a per-card basis so that we choose the right
  974. * root bridge.
  975. * Note that the returned IO or memory base is a physical address
  976. */
  977. long sys_pciconfig_iobase(long which, unsigned long bus, unsigned long devfn)
  978. {
  979. struct pci_controller* hose;
  980. long result = -EOPNOTSUPP;
  981. hose = pci_bus_to_hose(bus);
  982. if (!hose)
  983. return -ENODEV;
  984. switch (which) {
  985. case IOBASE_BRIDGE_NUMBER:
  986. return (long)hose->first_busno;
  987. case IOBASE_MEMORY:
  988. return (long)hose->pci_mem_offset;
  989. case IOBASE_IO:
  990. return (long)hose->io_base_phys;
  991. case IOBASE_ISA_IO:
  992. return (long)isa_io_base;
  993. case IOBASE_ISA_MEM:
  994. return (long)isa_mem_base;
  995. }
  996. return result;
  997. }
  998. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  999. const struct resource *rsrc,
  1000. resource_size_t *start, resource_size_t *end)
  1001. {
  1002. struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
  1003. unsigned long offset = 0;
  1004. if (hose == NULL)
  1005. return;
  1006. if (rsrc->flags & IORESOURCE_IO)
  1007. offset = ___IO_BASE - hose->io_base_virt + hose->io_base_phys;
  1008. *start = rsrc->start + offset;
  1009. *end = rsrc->end + offset;
  1010. }
  1011. void __init
  1012. pci_init_resource(struct resource *res, unsigned long start, unsigned long end,
  1013. int flags, char *name)
  1014. {
  1015. res->start = start;
  1016. res->end = end;
  1017. res->flags = flags;
  1018. res->name = name;
  1019. res->parent = NULL;
  1020. res->sibling = NULL;
  1021. res->child = NULL;
  1022. }
  1023. void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
  1024. {
  1025. unsigned long start = pci_resource_start(dev, bar);
  1026. unsigned long len = pci_resource_len(dev, bar);
  1027. unsigned long flags = pci_resource_flags(dev, bar);
  1028. if (!len)
  1029. return NULL;
  1030. if (max && len > max)
  1031. len = max;
  1032. if (flags & IORESOURCE_IO)
  1033. return ioport_map(start, len);
  1034. if (flags & IORESOURCE_MEM)
  1035. /* Not checking IORESOURCE_CACHEABLE because PPC does
  1036. * not currently distinguish between ioremap and
  1037. * ioremap_nocache.
  1038. */
  1039. return ioremap(start, len);
  1040. /* What? */
  1041. return NULL;
  1042. }
  1043. void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
  1044. {
  1045. /* Nothing to do */
  1046. }
  1047. EXPORT_SYMBOL(pci_iomap);
  1048. EXPORT_SYMBOL(pci_iounmap);
  1049. unsigned long pci_address_to_pio(phys_addr_t address)
  1050. {
  1051. struct pci_controller* hose = hose_head;
  1052. for (; hose; hose = hose->next) {
  1053. unsigned int size = hose->io_resource.end -
  1054. hose->io_resource.start + 1;
  1055. if (address >= hose->io_base_phys &&
  1056. address < (hose->io_base_phys + size)) {
  1057. unsigned long base =
  1058. (unsigned long)hose->io_base_virt - _IO_BASE;
  1059. return base + (address - hose->io_base_phys);
  1060. }
  1061. }
  1062. return (unsigned int)-1;
  1063. }
  1064. EXPORT_SYMBOL(pci_address_to_pio);
  1065. /*
  1066. * Null PCI config access functions, for the case when we can't
  1067. * find a hose.
  1068. */
  1069. #define NULL_PCI_OP(rw, size, type) \
  1070. static int \
  1071. null_##rw##_config_##size(struct pci_dev *dev, int offset, type val) \
  1072. { \
  1073. return PCIBIOS_DEVICE_NOT_FOUND; \
  1074. }
  1075. static int
  1076. null_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  1077. int len, u32 *val)
  1078. {
  1079. return PCIBIOS_DEVICE_NOT_FOUND;
  1080. }
  1081. static int
  1082. null_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  1083. int len, u32 val)
  1084. {
  1085. return PCIBIOS_DEVICE_NOT_FOUND;
  1086. }
  1087. static struct pci_ops null_pci_ops =
  1088. {
  1089. null_read_config,
  1090. null_write_config
  1091. };
  1092. /*
  1093. * These functions are used early on before PCI scanning is done
  1094. * and all of the pci_dev and pci_bus structures have been created.
  1095. */
  1096. static struct pci_bus *
  1097. fake_pci_bus(struct pci_controller *hose, int busnr)
  1098. {
  1099. static struct pci_bus bus;
  1100. if (hose == 0) {
  1101. hose = pci_bus_to_hose(busnr);
  1102. if (hose == 0)
  1103. printk(KERN_ERR "Can't find hose for PCI bus %d!\n", busnr);
  1104. }
  1105. bus.number = busnr;
  1106. bus.sysdata = hose;
  1107. bus.ops = hose? hose->ops: &null_pci_ops;
  1108. return &bus;
  1109. }
  1110. #define EARLY_PCI_OP(rw, size, type) \
  1111. int early_##rw##_config_##size(struct pci_controller *hose, int bus, \
  1112. int devfn, int offset, type value) \
  1113. { \
  1114. return pci_bus_##rw##_config_##size(fake_pci_bus(hose, bus), \
  1115. devfn, offset, value); \
  1116. }
  1117. EARLY_PCI_OP(read, byte, u8 *)
  1118. EARLY_PCI_OP(read, word, u16 *)
  1119. EARLY_PCI_OP(read, dword, u32 *)
  1120. EARLY_PCI_OP(write, byte, u8)
  1121. EARLY_PCI_OP(write, word, u16)
  1122. EARLY_PCI_OP(write, dword, u32)