pci.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /* pci.c: UltraSparc PCI controller support.
  2. *
  3. * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
  4. * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
  5. * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz)
  6. *
  7. * OF tree based PCI bus probing taken from the PowerPC port
  8. * with minor modifications, see there for credits.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/sched.h>
  14. #include <linux/capability.h>
  15. #include <linux/errno.h>
  16. #include <linux/pci.h>
  17. #include <linux/msi.h>
  18. #include <linux/irq.h>
  19. #include <linux/init.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/pgtable.h>
  22. #include <asm/irq.h>
  23. #include <asm/ebus.h>
  24. #include <asm/isa.h>
  25. #include <asm/prom.h>
  26. #include <asm/apb.h>
  27. #include "pci_impl.h"
  28. #ifndef CONFIG_PCI
  29. /* A "nop" PCI implementation. */
  30. asmlinkage int sys_pciconfig_read(unsigned long bus, unsigned long dfn,
  31. unsigned long off, unsigned long len,
  32. unsigned char *buf)
  33. {
  34. return 0;
  35. }
  36. asmlinkage int sys_pciconfig_write(unsigned long bus, unsigned long dfn,
  37. unsigned long off, unsigned long len,
  38. unsigned char *buf)
  39. {
  40. return 0;
  41. }
  42. #else
  43. /* List of all PCI controllers found in the system. */
  44. struct pci_pbm_info *pci_pbm_root = NULL;
  45. /* Each PBM found gets a unique index. */
  46. int pci_num_pbms = 0;
  47. volatile int pci_poke_in_progress;
  48. volatile int pci_poke_cpu = -1;
  49. volatile int pci_poke_faulted;
  50. static DEFINE_SPINLOCK(pci_poke_lock);
  51. void pci_config_read8(u8 *addr, u8 *ret)
  52. {
  53. unsigned long flags;
  54. u8 byte;
  55. spin_lock_irqsave(&pci_poke_lock, flags);
  56. pci_poke_cpu = smp_processor_id();
  57. pci_poke_in_progress = 1;
  58. pci_poke_faulted = 0;
  59. __asm__ __volatile__("membar #Sync\n\t"
  60. "lduba [%1] %2, %0\n\t"
  61. "membar #Sync"
  62. : "=r" (byte)
  63. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  64. : "memory");
  65. pci_poke_in_progress = 0;
  66. pci_poke_cpu = -1;
  67. if (!pci_poke_faulted)
  68. *ret = byte;
  69. spin_unlock_irqrestore(&pci_poke_lock, flags);
  70. }
  71. void pci_config_read16(u16 *addr, u16 *ret)
  72. {
  73. unsigned long flags;
  74. u16 word;
  75. spin_lock_irqsave(&pci_poke_lock, flags);
  76. pci_poke_cpu = smp_processor_id();
  77. pci_poke_in_progress = 1;
  78. pci_poke_faulted = 0;
  79. __asm__ __volatile__("membar #Sync\n\t"
  80. "lduha [%1] %2, %0\n\t"
  81. "membar #Sync"
  82. : "=r" (word)
  83. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  84. : "memory");
  85. pci_poke_in_progress = 0;
  86. pci_poke_cpu = -1;
  87. if (!pci_poke_faulted)
  88. *ret = word;
  89. spin_unlock_irqrestore(&pci_poke_lock, flags);
  90. }
  91. void pci_config_read32(u32 *addr, u32 *ret)
  92. {
  93. unsigned long flags;
  94. u32 dword;
  95. spin_lock_irqsave(&pci_poke_lock, flags);
  96. pci_poke_cpu = smp_processor_id();
  97. pci_poke_in_progress = 1;
  98. pci_poke_faulted = 0;
  99. __asm__ __volatile__("membar #Sync\n\t"
  100. "lduwa [%1] %2, %0\n\t"
  101. "membar #Sync"
  102. : "=r" (dword)
  103. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  104. : "memory");
  105. pci_poke_in_progress = 0;
  106. pci_poke_cpu = -1;
  107. if (!pci_poke_faulted)
  108. *ret = dword;
  109. spin_unlock_irqrestore(&pci_poke_lock, flags);
  110. }
  111. void pci_config_write8(u8 *addr, u8 val)
  112. {
  113. unsigned long flags;
  114. spin_lock_irqsave(&pci_poke_lock, flags);
  115. pci_poke_cpu = smp_processor_id();
  116. pci_poke_in_progress = 1;
  117. pci_poke_faulted = 0;
  118. __asm__ __volatile__("membar #Sync\n\t"
  119. "stba %0, [%1] %2\n\t"
  120. "membar #Sync"
  121. : /* no outputs */
  122. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  123. : "memory");
  124. pci_poke_in_progress = 0;
  125. pci_poke_cpu = -1;
  126. spin_unlock_irqrestore(&pci_poke_lock, flags);
  127. }
  128. void pci_config_write16(u16 *addr, u16 val)
  129. {
  130. unsigned long flags;
  131. spin_lock_irqsave(&pci_poke_lock, flags);
  132. pci_poke_cpu = smp_processor_id();
  133. pci_poke_in_progress = 1;
  134. pci_poke_faulted = 0;
  135. __asm__ __volatile__("membar #Sync\n\t"
  136. "stha %0, [%1] %2\n\t"
  137. "membar #Sync"
  138. : /* no outputs */
  139. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  140. : "memory");
  141. pci_poke_in_progress = 0;
  142. pci_poke_cpu = -1;
  143. spin_unlock_irqrestore(&pci_poke_lock, flags);
  144. }
  145. void pci_config_write32(u32 *addr, u32 val)
  146. {
  147. unsigned long flags;
  148. spin_lock_irqsave(&pci_poke_lock, flags);
  149. pci_poke_cpu = smp_processor_id();
  150. pci_poke_in_progress = 1;
  151. pci_poke_faulted = 0;
  152. __asm__ __volatile__("membar #Sync\n\t"
  153. "stwa %0, [%1] %2\n\t"
  154. "membar #Sync"
  155. : /* no outputs */
  156. : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  157. : "memory");
  158. pci_poke_in_progress = 0;
  159. pci_poke_cpu = -1;
  160. spin_unlock_irqrestore(&pci_poke_lock, flags);
  161. }
  162. /* Probe for all PCI controllers in the system. */
  163. extern void sabre_init(struct device_node *, const char *);
  164. extern void psycho_init(struct device_node *, const char *);
  165. extern void schizo_init(struct device_node *, const char *);
  166. extern void schizo_plus_init(struct device_node *, const char *);
  167. extern void tomatillo_init(struct device_node *, const char *);
  168. extern void sun4v_pci_init(struct device_node *, const char *);
  169. extern void fire_pci_init(struct device_node *, const char *);
  170. static struct {
  171. char *model_name;
  172. void (*init)(struct device_node *, const char *);
  173. } pci_controller_table[] __initdata = {
  174. { "SUNW,sabre", sabre_init },
  175. { "pci108e,a000", sabre_init },
  176. { "pci108e,a001", sabre_init },
  177. { "SUNW,psycho", psycho_init },
  178. { "pci108e,8000", psycho_init },
  179. { "SUNW,schizo", schizo_init },
  180. { "pci108e,8001", schizo_init },
  181. { "SUNW,schizo+", schizo_plus_init },
  182. { "pci108e,8002", schizo_plus_init },
  183. { "SUNW,tomatillo", tomatillo_init },
  184. { "pci108e,a801", tomatillo_init },
  185. { "SUNW,sun4v-pci", sun4v_pci_init },
  186. { "pciex108e,80f0", fire_pci_init },
  187. };
  188. #define PCI_NUM_CONTROLLER_TYPES ARRAY_SIZE(pci_controller_table)
  189. static int __init pci_controller_init(const char *model_name, int namelen, struct device_node *dp)
  190. {
  191. int i;
  192. for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
  193. if (!strncmp(model_name,
  194. pci_controller_table[i].model_name,
  195. namelen)) {
  196. pci_controller_table[i].init(dp, model_name);
  197. return 1;
  198. }
  199. }
  200. return 0;
  201. }
  202. static int __init pci_controller_scan(int (*handler)(const char *, int, struct device_node *))
  203. {
  204. struct device_node *dp;
  205. int count = 0;
  206. for_each_node_by_name(dp, "pci") {
  207. struct property *prop;
  208. int len;
  209. prop = of_find_property(dp, "model", &len);
  210. if (!prop)
  211. prop = of_find_property(dp, "compatible", &len);
  212. if (prop) {
  213. const char *model = prop->value;
  214. int item_len = 0;
  215. /* Our value may be a multi-valued string in the
  216. * case of some compatible properties. For sanity,
  217. * only try the first one.
  218. */
  219. while (model[item_len] && len) {
  220. len--;
  221. item_len++;
  222. }
  223. if (handler(model, item_len, dp))
  224. count++;
  225. }
  226. }
  227. return count;
  228. }
  229. /* Find each controller in the system, attach and initialize
  230. * software state structure for each and link into the
  231. * pci_pbm_root. Setup the controller enough such
  232. * that bus scanning can be done.
  233. */
  234. static void __init pci_controller_probe(void)
  235. {
  236. printk("PCI: Probing for controllers.\n");
  237. pci_controller_scan(pci_controller_init);
  238. }
  239. static int ofpci_verbose;
  240. static int __init ofpci_debug(char *str)
  241. {
  242. int val = 0;
  243. get_option(&str, &val);
  244. if (val)
  245. ofpci_verbose = 1;
  246. return 1;
  247. }
  248. __setup("ofpci_debug=", ofpci_debug);
  249. static unsigned long pci_parse_of_flags(u32 addr0)
  250. {
  251. unsigned long flags = 0;
  252. if (addr0 & 0x02000000) {
  253. flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY;
  254. flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64;
  255. flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M;
  256. if (addr0 & 0x40000000)
  257. flags |= IORESOURCE_PREFETCH
  258. | PCI_BASE_ADDRESS_MEM_PREFETCH;
  259. } else if (addr0 & 0x01000000)
  260. flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
  261. return flags;
  262. }
  263. /* The of_device layer has translated all of the assigned-address properties
  264. * into physical address resources, we only have to figure out the register
  265. * mapping.
  266. */
  267. static void pci_parse_of_addrs(struct of_device *op,
  268. struct device_node *node,
  269. struct pci_dev *dev)
  270. {
  271. struct resource *op_res;
  272. const u32 *addrs;
  273. int proplen;
  274. addrs = of_get_property(node, "assigned-addresses", &proplen);
  275. if (!addrs)
  276. return;
  277. if (ofpci_verbose)
  278. printk(" parse addresses (%d bytes) @ %p\n",
  279. proplen, addrs);
  280. op_res = &op->resource[0];
  281. for (; proplen >= 20; proplen -= 20, addrs += 5, op_res++) {
  282. struct resource *res;
  283. unsigned long flags;
  284. int i;
  285. flags = pci_parse_of_flags(addrs[0]);
  286. if (!flags)
  287. continue;
  288. i = addrs[0] & 0xff;
  289. if (ofpci_verbose)
  290. printk(" start: %lx, end: %lx, i: %x\n",
  291. op_res->start, op_res->end, i);
  292. if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
  293. res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
  294. } else if (i == dev->rom_base_reg) {
  295. res = &dev->resource[PCI_ROM_RESOURCE];
  296. flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
  297. } else {
  298. printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
  299. continue;
  300. }
  301. res->start = op_res->start;
  302. res->end = op_res->end;
  303. res->flags = flags;
  304. res->name = pci_name(dev);
  305. }
  306. }
  307. struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
  308. struct device_node *node,
  309. struct pci_bus *bus, int devfn,
  310. int host_controller)
  311. {
  312. struct dev_archdata *sd;
  313. struct pci_dev *dev;
  314. const char *type;
  315. u32 class;
  316. dev = alloc_pci_dev();
  317. if (!dev)
  318. return NULL;
  319. sd = &dev->dev.archdata;
  320. sd->iommu = pbm->iommu;
  321. sd->stc = &pbm->stc;
  322. sd->host_controller = pbm;
  323. sd->prom_node = node;
  324. sd->op = of_find_device_by_node(node);
  325. sd = &sd->op->dev.archdata;
  326. sd->iommu = pbm->iommu;
  327. sd->stc = &pbm->stc;
  328. type = of_get_property(node, "device_type", NULL);
  329. if (type == NULL)
  330. type = "";
  331. if (ofpci_verbose)
  332. printk(" create device, devfn: %x, type: %s\n",
  333. devfn, type);
  334. dev->bus = bus;
  335. dev->sysdata = node;
  336. dev->dev.parent = bus->bridge;
  337. dev->dev.bus = &pci_bus_type;
  338. dev->devfn = devfn;
  339. dev->multifunction = 0; /* maybe a lie? */
  340. if (host_controller) {
  341. if (tlb_type != hypervisor) {
  342. pci_read_config_word(dev, PCI_VENDOR_ID,
  343. &dev->vendor);
  344. pci_read_config_word(dev, PCI_DEVICE_ID,
  345. &dev->device);
  346. } else {
  347. dev->vendor = PCI_VENDOR_ID_SUN;
  348. dev->device = 0x80f0;
  349. }
  350. dev->cfg_size = 256;
  351. dev->class = PCI_CLASS_BRIDGE_HOST << 8;
  352. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  353. 0x00, PCI_SLOT(devfn), PCI_FUNC(devfn));
  354. } else {
  355. dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff);
  356. dev->device = of_getintprop_default(node, "device-id", 0xffff);
  357. dev->subsystem_vendor =
  358. of_getintprop_default(node, "subsystem-vendor-id", 0);
  359. dev->subsystem_device =
  360. of_getintprop_default(node, "subsystem-id", 0);
  361. dev->cfg_size = pci_cfg_space_size(dev);
  362. /* We can't actually use the firmware value, we have
  363. * to read what is in the register right now. One
  364. * reason is that in the case of IDE interfaces the
  365. * firmware can sample the value before the the IDE
  366. * interface is programmed into native mode.
  367. */
  368. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
  369. dev->class = class >> 8;
  370. dev->revision = class & 0xff;
  371. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  372. dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  373. }
  374. if (ofpci_verbose)
  375. printk(" class: 0x%x device name: %s\n",
  376. dev->class, pci_name(dev));
  377. /* I have seen IDE devices which will not respond to
  378. * the bmdma simplex check reads if bus mastering is
  379. * disabled.
  380. */
  381. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  382. pci_set_master(dev);
  383. dev->current_state = 4; /* unknown power state */
  384. dev->error_state = pci_channel_io_normal;
  385. if (host_controller) {
  386. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  387. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  388. dev->irq = PCI_IRQ_NONE;
  389. } else {
  390. if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
  391. /* a PCI-PCI bridge */
  392. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  393. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  394. } else if (!strcmp(type, "cardbus")) {
  395. dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
  396. } else {
  397. dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
  398. dev->rom_base_reg = PCI_ROM_ADDRESS;
  399. dev->irq = sd->op->irqs[0];
  400. if (dev->irq == 0xffffffff)
  401. dev->irq = PCI_IRQ_NONE;
  402. }
  403. }
  404. pci_parse_of_addrs(sd->op, node, dev);
  405. if (ofpci_verbose)
  406. printk(" adding to system ...\n");
  407. pci_device_add(dev, bus);
  408. return dev;
  409. }
  410. static void __devinit apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
  411. {
  412. u32 idx, first, last;
  413. first = 8;
  414. last = 0;
  415. for (idx = 0; idx < 8; idx++) {
  416. if ((map & (1 << idx)) != 0) {
  417. if (first > idx)
  418. first = idx;
  419. if (last < idx)
  420. last = idx;
  421. }
  422. }
  423. *first_p = first;
  424. *last_p = last;
  425. }
  426. static void pci_resource_adjust(struct resource *res,
  427. struct resource *root)
  428. {
  429. res->start += root->start;
  430. res->end += root->start;
  431. }
  432. /* For PCI bus devices which lack a 'ranges' property we interrogate
  433. * the config space values to set the resources, just like the generic
  434. * Linux PCI probing code does.
  435. */
  436. static void __devinit pci_cfg_fake_ranges(struct pci_dev *dev,
  437. struct pci_bus *bus,
  438. struct pci_pbm_info *pbm)
  439. {
  440. struct resource *res;
  441. u8 io_base_lo, io_limit_lo;
  442. u16 mem_base_lo, mem_limit_lo;
  443. unsigned long base, limit;
  444. pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo);
  445. pci_read_config_byte(dev, PCI_IO_LIMIT, &io_limit_lo);
  446. base = (io_base_lo & PCI_IO_RANGE_MASK) << 8;
  447. limit = (io_limit_lo & PCI_IO_RANGE_MASK) << 8;
  448. if ((io_base_lo & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) {
  449. u16 io_base_hi, io_limit_hi;
  450. pci_read_config_word(dev, PCI_IO_BASE_UPPER16, &io_base_hi);
  451. pci_read_config_word(dev, PCI_IO_LIMIT_UPPER16, &io_limit_hi);
  452. base |= (io_base_hi << 16);
  453. limit |= (io_limit_hi << 16);
  454. }
  455. res = bus->resource[0];
  456. if (base <= limit) {
  457. res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO;
  458. if (!res->start)
  459. res->start = base;
  460. if (!res->end)
  461. res->end = limit + 0xfff;
  462. pci_resource_adjust(res, &pbm->io_space);
  463. }
  464. pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo);
  465. pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo);
  466. base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16;
  467. limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16;
  468. res = bus->resource[1];
  469. if (base <= limit) {
  470. res->flags = ((mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) |
  471. IORESOURCE_MEM);
  472. res->start = base;
  473. res->end = limit + 0xfffff;
  474. pci_resource_adjust(res, &pbm->mem_space);
  475. }
  476. pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
  477. pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo);
  478. base = (mem_base_lo & PCI_PREF_RANGE_MASK) << 16;
  479. limit = (mem_limit_lo & PCI_PREF_RANGE_MASK) << 16;
  480. if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
  481. u32 mem_base_hi, mem_limit_hi;
  482. pci_read_config_dword(dev, PCI_PREF_BASE_UPPER32, &mem_base_hi);
  483. pci_read_config_dword(dev, PCI_PREF_LIMIT_UPPER32, &mem_limit_hi);
  484. /*
  485. * Some bridges set the base > limit by default, and some
  486. * (broken) BIOSes do not initialize them. If we find
  487. * this, just assume they are not being used.
  488. */
  489. if (mem_base_hi <= mem_limit_hi) {
  490. base |= ((long) mem_base_hi) << 32;
  491. limit |= ((long) mem_limit_hi) << 32;
  492. }
  493. }
  494. res = bus->resource[2];
  495. if (base <= limit) {
  496. res->flags = ((mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) |
  497. IORESOURCE_MEM | IORESOURCE_PREFETCH);
  498. res->start = base;
  499. res->end = limit + 0xfffff;
  500. pci_resource_adjust(res, &pbm->mem_space);
  501. }
  502. }
  503. /* Cook up fake bus resources for SUNW,simba PCI bridges which lack
  504. * a proper 'ranges' property.
  505. */
  506. static void __devinit apb_fake_ranges(struct pci_dev *dev,
  507. struct pci_bus *bus,
  508. struct pci_pbm_info *pbm)
  509. {
  510. struct resource *res;
  511. u32 first, last;
  512. u8 map;
  513. pci_read_config_byte(dev, APB_IO_ADDRESS_MAP, &map);
  514. apb_calc_first_last(map, &first, &last);
  515. res = bus->resource[0];
  516. res->start = (first << 21);
  517. res->end = (last << 21) + ((1 << 21) - 1);
  518. res->flags = IORESOURCE_IO;
  519. pci_resource_adjust(res, &pbm->io_space);
  520. pci_read_config_byte(dev, APB_MEM_ADDRESS_MAP, &map);
  521. apb_calc_first_last(map, &first, &last);
  522. res = bus->resource[1];
  523. res->start = (first << 21);
  524. res->end = (last << 21) + ((1 << 21) - 1);
  525. res->flags = IORESOURCE_MEM;
  526. pci_resource_adjust(res, &pbm->mem_space);
  527. }
  528. static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
  529. struct device_node *node,
  530. struct pci_bus *bus);
  531. #define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
  532. static void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
  533. struct device_node *node,
  534. struct pci_dev *dev)
  535. {
  536. struct pci_bus *bus;
  537. const u32 *busrange, *ranges;
  538. int len, i, simba;
  539. struct resource *res;
  540. unsigned int flags;
  541. u64 size;
  542. if (ofpci_verbose)
  543. printk("of_scan_pci_bridge(%s)\n", node->full_name);
  544. /* parse bus-range property */
  545. busrange = of_get_property(node, "bus-range", &len);
  546. if (busrange == NULL || len != 8) {
  547. printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %s\n",
  548. node->full_name);
  549. return;
  550. }
  551. ranges = of_get_property(node, "ranges", &len);
  552. simba = 0;
  553. if (ranges == NULL) {
  554. const char *model = of_get_property(node, "model", NULL);
  555. if (model && !strcmp(model, "SUNW,simba"))
  556. simba = 1;
  557. }
  558. bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
  559. if (!bus) {
  560. printk(KERN_ERR "Failed to create pci bus for %s\n",
  561. node->full_name);
  562. return;
  563. }
  564. bus->primary = dev->bus->number;
  565. bus->subordinate = busrange[1];
  566. bus->bridge_ctl = 0;
  567. /* parse ranges property, or cook one up by hand for Simba */
  568. /* PCI #address-cells == 3 and #size-cells == 2 always */
  569. res = &dev->resource[PCI_BRIDGE_RESOURCES];
  570. for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
  571. res->flags = 0;
  572. bus->resource[i] = res;
  573. ++res;
  574. }
  575. if (simba) {
  576. apb_fake_ranges(dev, bus, pbm);
  577. goto after_ranges;
  578. } else if (ranges == NULL) {
  579. pci_cfg_fake_ranges(dev, bus, pbm);
  580. goto after_ranges;
  581. }
  582. i = 1;
  583. for (; len >= 32; len -= 32, ranges += 8) {
  584. struct resource *root;
  585. flags = pci_parse_of_flags(ranges[0]);
  586. size = GET_64BIT(ranges, 6);
  587. if (flags == 0 || size == 0)
  588. continue;
  589. if (flags & IORESOURCE_IO) {
  590. res = bus->resource[0];
  591. if (res->flags) {
  592. printk(KERN_ERR "PCI: ignoring extra I/O range"
  593. " for bridge %s\n", node->full_name);
  594. continue;
  595. }
  596. root = &pbm->io_space;
  597. } else {
  598. if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
  599. printk(KERN_ERR "PCI: too many memory ranges"
  600. " for bridge %s\n", node->full_name);
  601. continue;
  602. }
  603. res = bus->resource[i];
  604. ++i;
  605. root = &pbm->mem_space;
  606. }
  607. res->start = GET_64BIT(ranges, 1);
  608. res->end = res->start + size - 1;
  609. res->flags = flags;
  610. /* Another way to implement this would be to add an of_device
  611. * layer routine that can calculate a resource for a given
  612. * range property value in a PCI device.
  613. */
  614. pci_resource_adjust(res, root);
  615. }
  616. after_ranges:
  617. sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
  618. bus->number);
  619. if (ofpci_verbose)
  620. printk(" bus name: %s\n", bus->name);
  621. pci_of_scan_bus(pbm, node, bus);
  622. }
  623. static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
  624. struct device_node *node,
  625. struct pci_bus *bus)
  626. {
  627. struct device_node *child;
  628. const u32 *reg;
  629. int reglen, devfn, prev_devfn;
  630. struct pci_dev *dev;
  631. if (ofpci_verbose)
  632. printk("PCI: scan_bus[%s] bus no %d\n",
  633. node->full_name, bus->number);
  634. child = NULL;
  635. prev_devfn = -1;
  636. while ((child = of_get_next_child(node, child)) != NULL) {
  637. if (ofpci_verbose)
  638. printk(" * %s\n", child->full_name);
  639. reg = of_get_property(child, "reg", &reglen);
  640. if (reg == NULL || reglen < 20)
  641. continue;
  642. devfn = (reg[0] >> 8) & 0xff;
  643. /* This is a workaround for some device trees
  644. * which list PCI devices twice. On the V100
  645. * for example, device number 3 is listed twice.
  646. * Once as "pm" and once again as "lomp".
  647. */
  648. if (devfn == prev_devfn)
  649. continue;
  650. prev_devfn = devfn;
  651. /* create a new pci_dev for this device */
  652. dev = of_create_pci_dev(pbm, child, bus, devfn, 0);
  653. if (!dev)
  654. continue;
  655. if (ofpci_verbose)
  656. printk("PCI: dev header type: %x\n",
  657. dev->hdr_type);
  658. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  659. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  660. of_scan_pci_bridge(pbm, child, dev);
  661. }
  662. }
  663. static ssize_t
  664. show_pciobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
  665. {
  666. struct pci_dev *pdev;
  667. struct device_node *dp;
  668. pdev = to_pci_dev(dev);
  669. dp = pdev->dev.archdata.prom_node;
  670. return snprintf (buf, PAGE_SIZE, "%s\n", dp->full_name);
  671. }
  672. static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_pciobppath_attr, NULL);
  673. static void __devinit pci_bus_register_of_sysfs(struct pci_bus *bus)
  674. {
  675. struct pci_dev *dev;
  676. struct pci_bus *child_bus;
  677. int err;
  678. list_for_each_entry(dev, &bus->devices, bus_list) {
  679. /* we don't really care if we can create this file or
  680. * not, but we need to assign the result of the call
  681. * or the world will fall under alien invasion and
  682. * everybody will be frozen on a spaceship ready to be
  683. * eaten on alpha centauri by some green and jelly
  684. * humanoid.
  685. */
  686. err = sysfs_create_file(&dev->dev.kobj, &dev_attr_obppath.attr);
  687. }
  688. list_for_each_entry(child_bus, &bus->children, node)
  689. pci_bus_register_of_sysfs(child_bus);
  690. }
  691. int pci_host_bridge_read_pci_cfg(struct pci_bus *bus_dev,
  692. unsigned int devfn,
  693. int where, int size,
  694. u32 *value)
  695. {
  696. static u8 fake_pci_config[] = {
  697. 0x8e, 0x10, /* Vendor: 0x108e (Sun) */
  698. 0xf0, 0x80, /* Device: 0x80f0 (Fire) */
  699. 0x46, 0x01, /* Command: 0x0146 (SERR, PARITY, MASTER, MEM) */
  700. 0xa0, 0x22, /* Status: 0x02a0 (DEVSEL_MED, FB2B, 66MHZ) */
  701. 0x00, 0x00, 0x00, 0x06, /* Class: 0x06000000 host bridge */
  702. 0x00, /* Cacheline: 0x00 */
  703. 0x40, /* Latency: 0x40 */
  704. 0x00, /* Header-Type: 0x00 normal */
  705. };
  706. *value = 0;
  707. if (where >= 0 && where < sizeof(fake_pci_config) &&
  708. (where + size) >= 0 &&
  709. (where + size) < sizeof(fake_pci_config) &&
  710. size <= sizeof(u32)) {
  711. while (size--) {
  712. *value <<= 8;
  713. *value |= fake_pci_config[where + size];
  714. }
  715. }
  716. return PCIBIOS_SUCCESSFUL;
  717. }
  718. int pci_host_bridge_write_pci_cfg(struct pci_bus *bus_dev,
  719. unsigned int devfn,
  720. int where, int size,
  721. u32 value)
  722. {
  723. return PCIBIOS_SUCCESSFUL;
  724. }
  725. struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm)
  726. {
  727. struct device_node *node = pbm->prom_node;
  728. struct pci_dev *host_pdev;
  729. struct pci_bus *bus;
  730. printk("PCI: Scanning PBM %s\n", node->full_name);
  731. /* XXX parent device? XXX */
  732. bus = pci_create_bus(NULL, pbm->pci_first_busno, pbm->pci_ops, pbm);
  733. if (!bus) {
  734. printk(KERN_ERR "Failed to create bus for %s\n",
  735. node->full_name);
  736. return NULL;
  737. }
  738. bus->secondary = pbm->pci_first_busno;
  739. bus->subordinate = pbm->pci_last_busno;
  740. bus->resource[0] = &pbm->io_space;
  741. bus->resource[1] = &pbm->mem_space;
  742. /* Create the dummy host bridge and link it in. */
  743. host_pdev = of_create_pci_dev(pbm, node, bus, 0x00, 1);
  744. bus->self = host_pdev;
  745. pci_of_scan_bus(pbm, node, bus);
  746. pci_bus_add_devices(bus);
  747. pci_bus_register_of_sysfs(bus);
  748. return bus;
  749. }
  750. static void __init pci_scan_each_controller_bus(void)
  751. {
  752. struct pci_pbm_info *pbm;
  753. for (pbm = pci_pbm_root; pbm; pbm = pbm->next)
  754. pbm->scan_bus(pbm);
  755. }
  756. extern void power_init(void);
  757. static int __init pcibios_init(void)
  758. {
  759. pci_controller_probe();
  760. if (pci_pbm_root == NULL)
  761. return 0;
  762. pci_scan_each_controller_bus();
  763. isa_init();
  764. ebus_init();
  765. power_init();
  766. return 0;
  767. }
  768. subsys_initcall(pcibios_init);
  769. void __devinit pcibios_fixup_bus(struct pci_bus *pbus)
  770. {
  771. struct pci_pbm_info *pbm = pbus->sysdata;
  772. /* Generic PCI bus probing sets these to point at
  773. * &io{port,mem}_resouce which is wrong for us.
  774. */
  775. pbus->resource[0] = &pbm->io_space;
  776. pbus->resource[1] = &pbm->mem_space;
  777. }
  778. struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r)
  779. {
  780. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  781. struct resource *root = NULL;
  782. if (r->flags & IORESOURCE_IO)
  783. root = &pbm->io_space;
  784. if (r->flags & IORESOURCE_MEM)
  785. root = &pbm->mem_space;
  786. return root;
  787. }
  788. void pcibios_update_irq(struct pci_dev *pdev, int irq)
  789. {
  790. }
  791. void pcibios_align_resource(void *data, struct resource *res,
  792. resource_size_t size, resource_size_t align)
  793. {
  794. }
  795. int pcibios_enable_device(struct pci_dev *dev, int mask)
  796. {
  797. u16 cmd, oldcmd;
  798. int i;
  799. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  800. oldcmd = cmd;
  801. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  802. struct resource *res = &dev->resource[i];
  803. /* Only set up the requested stuff */
  804. if (!(mask & (1<<i)))
  805. continue;
  806. if (res->flags & IORESOURCE_IO)
  807. cmd |= PCI_COMMAND_IO;
  808. if (res->flags & IORESOURCE_MEM)
  809. cmd |= PCI_COMMAND_MEMORY;
  810. }
  811. if (cmd != oldcmd) {
  812. printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
  813. pci_name(dev), cmd);
  814. /* Enable the appropriate bits in the PCI command register. */
  815. pci_write_config_word(dev, PCI_COMMAND, cmd);
  816. }
  817. return 0;
  818. }
  819. void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
  820. struct resource *res)
  821. {
  822. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  823. struct resource zero_res, *root;
  824. zero_res.start = 0;
  825. zero_res.end = 0;
  826. zero_res.flags = res->flags;
  827. if (res->flags & IORESOURCE_IO)
  828. root = &pbm->io_space;
  829. else
  830. root = &pbm->mem_space;
  831. pci_resource_adjust(&zero_res, root);
  832. region->start = res->start - zero_res.start;
  833. region->end = res->end - zero_res.start;
  834. }
  835. EXPORT_SYMBOL(pcibios_resource_to_bus);
  836. void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
  837. struct pci_bus_region *region)
  838. {
  839. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  840. struct resource *root;
  841. res->start = region->start;
  842. res->end = region->end;
  843. if (res->flags & IORESOURCE_IO)
  844. root = &pbm->io_space;
  845. else
  846. root = &pbm->mem_space;
  847. pci_resource_adjust(res, root);
  848. }
  849. EXPORT_SYMBOL(pcibios_bus_to_resource);
  850. char * __devinit pcibios_setup(char *str)
  851. {
  852. return str;
  853. }
  854. /* Platform support for /proc/bus/pci/X/Y mmap()s. */
  855. /* If the user uses a host-bridge as the PCI device, he may use
  856. * this to perform a raw mmap() of the I/O or MEM space behind
  857. * that controller.
  858. *
  859. * This can be useful for execution of x86 PCI bios initialization code
  860. * on a PCI card, like the xfree86 int10 stuff does.
  861. */
  862. static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma,
  863. enum pci_mmap_state mmap_state)
  864. {
  865. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  866. unsigned long space_size, user_offset, user_size;
  867. if (mmap_state == pci_mmap_io) {
  868. space_size = (pbm->io_space.end -
  869. pbm->io_space.start) + 1;
  870. } else {
  871. space_size = (pbm->mem_space.end -
  872. pbm->mem_space.start) + 1;
  873. }
  874. /* Make sure the request is in range. */
  875. user_offset = vma->vm_pgoff << PAGE_SHIFT;
  876. user_size = vma->vm_end - vma->vm_start;
  877. if (user_offset >= space_size ||
  878. (user_offset + user_size) > space_size)
  879. return -EINVAL;
  880. if (mmap_state == pci_mmap_io) {
  881. vma->vm_pgoff = (pbm->io_space.start +
  882. user_offset) >> PAGE_SHIFT;
  883. } else {
  884. vma->vm_pgoff = (pbm->mem_space.start +
  885. user_offset) >> PAGE_SHIFT;
  886. }
  887. return 0;
  888. }
  889. /* Adjust vm_pgoff of VMA such that it is the physical page offset
  890. * corresponding to the 32-bit pci bus offset for DEV requested by the user.
  891. *
  892. * Basically, the user finds the base address for his device which he wishes
  893. * to mmap. They read the 32-bit value from the config space base register,
  894. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  895. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  896. *
  897. * Returns negative error code on failure, zero on success.
  898. */
  899. static int __pci_mmap_make_offset(struct pci_dev *pdev,
  900. struct vm_area_struct *vma,
  901. enum pci_mmap_state mmap_state)
  902. {
  903. unsigned long user_paddr, user_size;
  904. int i, err;
  905. /* First compute the physical address in vma->vm_pgoff,
  906. * making sure the user offset is within range in the
  907. * appropriate PCI space.
  908. */
  909. err = __pci_mmap_make_offset_bus(pdev, vma, mmap_state);
  910. if (err)
  911. return err;
  912. /* If this is a mapping on a host bridge, any address
  913. * is OK.
  914. */
  915. if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
  916. return err;
  917. /* Otherwise make sure it's in the range for one of the
  918. * device's resources.
  919. */
  920. user_paddr = vma->vm_pgoff << PAGE_SHIFT;
  921. user_size = vma->vm_end - vma->vm_start;
  922. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  923. struct resource *rp = &pdev->resource[i];
  924. /* Active? */
  925. if (!rp->flags)
  926. continue;
  927. /* Same type? */
  928. if (i == PCI_ROM_RESOURCE) {
  929. if (mmap_state != pci_mmap_mem)
  930. continue;
  931. } else {
  932. if ((mmap_state == pci_mmap_io &&
  933. (rp->flags & IORESOURCE_IO) == 0) ||
  934. (mmap_state == pci_mmap_mem &&
  935. (rp->flags & IORESOURCE_MEM) == 0))
  936. continue;
  937. }
  938. if ((rp->start <= user_paddr) &&
  939. (user_paddr + user_size) <= (rp->end + 1UL))
  940. break;
  941. }
  942. if (i > PCI_ROM_RESOURCE)
  943. return -EINVAL;
  944. return 0;
  945. }
  946. /* Set vm_flags of VMA, as appropriate for this architecture, for a pci device
  947. * mapping.
  948. */
  949. static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
  950. enum pci_mmap_state mmap_state)
  951. {
  952. vma->vm_flags |= (VM_IO | VM_RESERVED);
  953. }
  954. /* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  955. * device mapping.
  956. */
  957. static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
  958. enum pci_mmap_state mmap_state)
  959. {
  960. /* Our io_remap_pfn_range takes care of this, do nothing. */
  961. }
  962. /* Perform the actual remap of the pages for a PCI device mapping, as appropriate
  963. * for this architecture. The region in the process to map is described by vm_start
  964. * and vm_end members of VMA, the base physical address is found in vm_pgoff.
  965. * The pci device structure is provided so that architectures may make mapping
  966. * decisions on a per-device or per-bus basis.
  967. *
  968. * Returns a negative error code on failure, zero on success.
  969. */
  970. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  971. enum pci_mmap_state mmap_state,
  972. int write_combine)
  973. {
  974. int ret;
  975. ret = __pci_mmap_make_offset(dev, vma, mmap_state);
  976. if (ret < 0)
  977. return ret;
  978. __pci_mmap_set_flags(dev, vma, mmap_state);
  979. __pci_mmap_set_pgprot(dev, vma, mmap_state);
  980. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  981. ret = io_remap_pfn_range(vma, vma->vm_start,
  982. vma->vm_pgoff,
  983. vma->vm_end - vma->vm_start,
  984. vma->vm_page_prot);
  985. if (ret)
  986. return ret;
  987. return 0;
  988. }
  989. /* Return the domain nuber for this pci bus */
  990. int pci_domain_nr(struct pci_bus *pbus)
  991. {
  992. struct pci_pbm_info *pbm = pbus->sysdata;
  993. int ret;
  994. if (pbm == NULL || pbm->parent == NULL) {
  995. ret = -ENXIO;
  996. } else {
  997. ret = pbm->index;
  998. }
  999. return ret;
  1000. }
  1001. EXPORT_SYMBOL(pci_domain_nr);
  1002. #ifdef CONFIG_PCI_MSI
  1003. int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
  1004. {
  1005. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  1006. int virt_irq;
  1007. if (!pbm->setup_msi_irq)
  1008. return -EINVAL;
  1009. return pbm->setup_msi_irq(&virt_irq, pdev, desc);
  1010. }
  1011. void arch_teardown_msi_irq(unsigned int virt_irq)
  1012. {
  1013. struct msi_desc *entry = get_irq_msi(virt_irq);
  1014. struct pci_dev *pdev = entry->dev;
  1015. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  1016. if (!pbm->teardown_msi_irq)
  1017. return;
  1018. return pbm->teardown_msi_irq(virt_irq, pdev);
  1019. }
  1020. #endif /* !(CONFIG_PCI_MSI) */
  1021. struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
  1022. {
  1023. return pdev->dev.archdata.prom_node;
  1024. }
  1025. EXPORT_SYMBOL(pci_device_to_OF_node);
  1026. static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit)
  1027. {
  1028. struct pci_dev *ali_isa_bridge;
  1029. u8 val;
  1030. /* ALI sound chips generate 31-bits of DMA, a special register
  1031. * determines what bit 31 is emitted as.
  1032. */
  1033. ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL,
  1034. PCI_DEVICE_ID_AL_M1533,
  1035. NULL);
  1036. pci_read_config_byte(ali_isa_bridge, 0x7e, &val);
  1037. if (set_bit)
  1038. val |= 0x01;
  1039. else
  1040. val &= ~0x01;
  1041. pci_write_config_byte(ali_isa_bridge, 0x7e, val);
  1042. pci_dev_put(ali_isa_bridge);
  1043. }
  1044. int pci_dma_supported(struct pci_dev *pdev, u64 device_mask)
  1045. {
  1046. u64 dma_addr_mask;
  1047. if (pdev == NULL) {
  1048. dma_addr_mask = 0xffffffff;
  1049. } else {
  1050. struct iommu *iommu = pdev->dev.archdata.iommu;
  1051. dma_addr_mask = iommu->dma_addr_mask;
  1052. if (pdev->vendor == PCI_VENDOR_ID_AL &&
  1053. pdev->device == PCI_DEVICE_ID_AL_M5451 &&
  1054. device_mask == 0x7fffffff) {
  1055. ali_sound_dma_hack(pdev,
  1056. (dma_addr_mask & 0x80000000) != 0);
  1057. return 1;
  1058. }
  1059. }
  1060. if (device_mask >= (1UL << 32UL))
  1061. return 0;
  1062. return (device_mask & dma_addr_mask) == dma_addr_mask;
  1063. }
  1064. void pci_resource_to_user(const struct pci_dev *pdev, int bar,
  1065. const struct resource *rp, resource_size_t *start,
  1066. resource_size_t *end)
  1067. {
  1068. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  1069. unsigned long offset;
  1070. if (rp->flags & IORESOURCE_IO)
  1071. offset = pbm->io_space.start;
  1072. else
  1073. offset = pbm->mem_space.start;
  1074. *start = rp->start - offset;
  1075. *end = rp->end - offset;
  1076. }
  1077. #endif /* !(CONFIG_PCI) */