pci.c 33 KB

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