pci.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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->numa_node = pbm->numa_node;
  326. sd = &sd->op->dev.archdata;
  327. sd->iommu = pbm->iommu;
  328. sd->stc = &pbm->stc;
  329. sd->numa_node = pbm->numa_node;
  330. type = of_get_property(node, "device_type", NULL);
  331. if (type == NULL)
  332. type = "";
  333. if (ofpci_verbose)
  334. printk(" create device, devfn: %x, type: %s\n",
  335. devfn, type);
  336. dev->bus = bus;
  337. dev->sysdata = node;
  338. dev->dev.parent = bus->bridge;
  339. dev->dev.bus = &pci_bus_type;
  340. dev->devfn = devfn;
  341. dev->multifunction = 0; /* maybe a lie? */
  342. if (host_controller) {
  343. if (tlb_type != hypervisor) {
  344. pci_read_config_word(dev, PCI_VENDOR_ID,
  345. &dev->vendor);
  346. pci_read_config_word(dev, PCI_DEVICE_ID,
  347. &dev->device);
  348. } else {
  349. dev->vendor = PCI_VENDOR_ID_SUN;
  350. dev->device = 0x80f0;
  351. }
  352. dev->cfg_size = 256;
  353. dev->class = PCI_CLASS_BRIDGE_HOST << 8;
  354. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  355. 0x00, PCI_SLOT(devfn), PCI_FUNC(devfn));
  356. } else {
  357. dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff);
  358. dev->device = of_getintprop_default(node, "device-id", 0xffff);
  359. dev->subsystem_vendor =
  360. of_getintprop_default(node, "subsystem-vendor-id", 0);
  361. dev->subsystem_device =
  362. of_getintprop_default(node, "subsystem-id", 0);
  363. dev->cfg_size = pci_cfg_space_size(dev);
  364. /* We can't actually use the firmware value, we have
  365. * to read what is in the register right now. One
  366. * reason is that in the case of IDE interfaces the
  367. * firmware can sample the value before the the IDE
  368. * interface is programmed into native mode.
  369. */
  370. pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
  371. dev->class = class >> 8;
  372. dev->revision = class & 0xff;
  373. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  374. dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  375. }
  376. if (ofpci_verbose)
  377. printk(" class: 0x%x device name: %s\n",
  378. dev->class, pci_name(dev));
  379. /* I have seen IDE devices which will not respond to
  380. * the bmdma simplex check reads if bus mastering is
  381. * disabled.
  382. */
  383. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  384. pci_set_master(dev);
  385. dev->current_state = 4; /* unknown power state */
  386. dev->error_state = pci_channel_io_normal;
  387. if (host_controller) {
  388. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  389. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  390. dev->irq = PCI_IRQ_NONE;
  391. } else {
  392. if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
  393. /* a PCI-PCI bridge */
  394. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  395. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  396. } else if (!strcmp(type, "cardbus")) {
  397. dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
  398. } else {
  399. dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
  400. dev->rom_base_reg = PCI_ROM_ADDRESS;
  401. dev->irq = sd->op->irqs[0];
  402. if (dev->irq == 0xffffffff)
  403. dev->irq = PCI_IRQ_NONE;
  404. }
  405. }
  406. pci_parse_of_addrs(sd->op, node, dev);
  407. if (ofpci_verbose)
  408. printk(" adding to system ...\n");
  409. pci_device_add(dev, bus);
  410. return dev;
  411. }
  412. static void __devinit apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p)
  413. {
  414. u32 idx, first, last;
  415. first = 8;
  416. last = 0;
  417. for (idx = 0; idx < 8; idx++) {
  418. if ((map & (1 << idx)) != 0) {
  419. if (first > idx)
  420. first = idx;
  421. if (last < idx)
  422. last = idx;
  423. }
  424. }
  425. *first_p = first;
  426. *last_p = last;
  427. }
  428. static void pci_resource_adjust(struct resource *res,
  429. struct resource *root)
  430. {
  431. res->start += root->start;
  432. res->end += root->start;
  433. }
  434. /* For PCI bus devices which lack a 'ranges' property we interrogate
  435. * the config space values to set the resources, just like the generic
  436. * Linux PCI probing code does.
  437. */
  438. static void __devinit pci_cfg_fake_ranges(struct pci_dev *dev,
  439. struct pci_bus *bus,
  440. struct pci_pbm_info *pbm)
  441. {
  442. struct resource *res;
  443. u8 io_base_lo, io_limit_lo;
  444. u16 mem_base_lo, mem_limit_lo;
  445. unsigned long base, limit;
  446. pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo);
  447. pci_read_config_byte(dev, PCI_IO_LIMIT, &io_limit_lo);
  448. base = (io_base_lo & PCI_IO_RANGE_MASK) << 8;
  449. limit = (io_limit_lo & PCI_IO_RANGE_MASK) << 8;
  450. if ((io_base_lo & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) {
  451. u16 io_base_hi, io_limit_hi;
  452. pci_read_config_word(dev, PCI_IO_BASE_UPPER16, &io_base_hi);
  453. pci_read_config_word(dev, PCI_IO_LIMIT_UPPER16, &io_limit_hi);
  454. base |= (io_base_hi << 16);
  455. limit |= (io_limit_hi << 16);
  456. }
  457. res = bus->resource[0];
  458. if (base <= limit) {
  459. res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO;
  460. if (!res->start)
  461. res->start = base;
  462. if (!res->end)
  463. res->end = limit + 0xfff;
  464. pci_resource_adjust(res, &pbm->io_space);
  465. }
  466. pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo);
  467. pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo);
  468. base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16;
  469. limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16;
  470. res = bus->resource[1];
  471. if (base <= limit) {
  472. res->flags = ((mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) |
  473. IORESOURCE_MEM);
  474. res->start = base;
  475. res->end = limit + 0xfffff;
  476. pci_resource_adjust(res, &pbm->mem_space);
  477. }
  478. pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
  479. pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo);
  480. base = (mem_base_lo & PCI_PREF_RANGE_MASK) << 16;
  481. limit = (mem_limit_lo & PCI_PREF_RANGE_MASK) << 16;
  482. if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
  483. u32 mem_base_hi, mem_limit_hi;
  484. pci_read_config_dword(dev, PCI_PREF_BASE_UPPER32, &mem_base_hi);
  485. pci_read_config_dword(dev, PCI_PREF_LIMIT_UPPER32, &mem_limit_hi);
  486. /*
  487. * Some bridges set the base > limit by default, and some
  488. * (broken) BIOSes do not initialize them. If we find
  489. * this, just assume they are not being used.
  490. */
  491. if (mem_base_hi <= mem_limit_hi) {
  492. base |= ((long) mem_base_hi) << 32;
  493. limit |= ((long) mem_limit_hi) << 32;
  494. }
  495. }
  496. res = bus->resource[2];
  497. if (base <= limit) {
  498. res->flags = ((mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) |
  499. IORESOURCE_MEM | IORESOURCE_PREFETCH);
  500. res->start = base;
  501. res->end = limit + 0xfffff;
  502. pci_resource_adjust(res, &pbm->mem_space);
  503. }
  504. }
  505. /* Cook up fake bus resources for SUNW,simba PCI bridges which lack
  506. * a proper 'ranges' property.
  507. */
  508. static void __devinit apb_fake_ranges(struct pci_dev *dev,
  509. struct pci_bus *bus,
  510. struct pci_pbm_info *pbm)
  511. {
  512. struct resource *res;
  513. u32 first, last;
  514. u8 map;
  515. pci_read_config_byte(dev, APB_IO_ADDRESS_MAP, &map);
  516. apb_calc_first_last(map, &first, &last);
  517. res = bus->resource[0];
  518. res->start = (first << 21);
  519. res->end = (last << 21) + ((1 << 21) - 1);
  520. res->flags = IORESOURCE_IO;
  521. pci_resource_adjust(res, &pbm->io_space);
  522. pci_read_config_byte(dev, APB_MEM_ADDRESS_MAP, &map);
  523. apb_calc_first_last(map, &first, &last);
  524. res = bus->resource[1];
  525. res->start = (first << 21);
  526. res->end = (last << 21) + ((1 << 21) - 1);
  527. res->flags = IORESOURCE_MEM;
  528. pci_resource_adjust(res, &pbm->mem_space);
  529. }
  530. static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
  531. struct device_node *node,
  532. struct pci_bus *bus);
  533. #define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
  534. static void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm,
  535. struct device_node *node,
  536. struct pci_dev *dev)
  537. {
  538. struct pci_bus *bus;
  539. const u32 *busrange, *ranges;
  540. int len, i, simba;
  541. struct resource *res;
  542. unsigned int flags;
  543. u64 size;
  544. if (ofpci_verbose)
  545. printk("of_scan_pci_bridge(%s)\n", node->full_name);
  546. /* parse bus-range property */
  547. busrange = of_get_property(node, "bus-range", &len);
  548. if (busrange == NULL || len != 8) {
  549. printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %s\n",
  550. node->full_name);
  551. return;
  552. }
  553. ranges = of_get_property(node, "ranges", &len);
  554. simba = 0;
  555. if (ranges == NULL) {
  556. const char *model = of_get_property(node, "model", NULL);
  557. if (model && !strcmp(model, "SUNW,simba"))
  558. simba = 1;
  559. }
  560. bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
  561. if (!bus) {
  562. printk(KERN_ERR "Failed to create pci bus for %s\n",
  563. node->full_name);
  564. return;
  565. }
  566. bus->primary = dev->bus->number;
  567. bus->subordinate = busrange[1];
  568. bus->bridge_ctl = 0;
  569. /* parse ranges property, or cook one up by hand for Simba */
  570. /* PCI #address-cells == 3 and #size-cells == 2 always */
  571. res = &dev->resource[PCI_BRIDGE_RESOURCES];
  572. for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
  573. res->flags = 0;
  574. bus->resource[i] = res;
  575. ++res;
  576. }
  577. if (simba) {
  578. apb_fake_ranges(dev, bus, pbm);
  579. goto after_ranges;
  580. } else if (ranges == NULL) {
  581. pci_cfg_fake_ranges(dev, bus, pbm);
  582. goto after_ranges;
  583. }
  584. i = 1;
  585. for (; len >= 32; len -= 32, ranges += 8) {
  586. struct resource *root;
  587. flags = pci_parse_of_flags(ranges[0]);
  588. size = GET_64BIT(ranges, 6);
  589. if (flags == 0 || size == 0)
  590. continue;
  591. if (flags & IORESOURCE_IO) {
  592. res = bus->resource[0];
  593. if (res->flags) {
  594. printk(KERN_ERR "PCI: ignoring extra I/O range"
  595. " for bridge %s\n", node->full_name);
  596. continue;
  597. }
  598. root = &pbm->io_space;
  599. } else {
  600. if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
  601. printk(KERN_ERR "PCI: too many memory ranges"
  602. " for bridge %s\n", node->full_name);
  603. continue;
  604. }
  605. res = bus->resource[i];
  606. ++i;
  607. root = &pbm->mem_space;
  608. }
  609. res->start = GET_64BIT(ranges, 1);
  610. res->end = res->start + size - 1;
  611. res->flags = flags;
  612. /* Another way to implement this would be to add an of_device
  613. * layer routine that can calculate a resource for a given
  614. * range property value in a PCI device.
  615. */
  616. pci_resource_adjust(res, root);
  617. }
  618. after_ranges:
  619. sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
  620. bus->number);
  621. if (ofpci_verbose)
  622. printk(" bus name: %s\n", bus->name);
  623. pci_of_scan_bus(pbm, node, bus);
  624. }
  625. static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
  626. struct device_node *node,
  627. struct pci_bus *bus)
  628. {
  629. struct device_node *child;
  630. const u32 *reg;
  631. int reglen, devfn, prev_devfn;
  632. struct pci_dev *dev;
  633. if (ofpci_verbose)
  634. printk("PCI: scan_bus[%s] bus no %d\n",
  635. node->full_name, bus->number);
  636. child = NULL;
  637. prev_devfn = -1;
  638. while ((child = of_get_next_child(node, child)) != NULL) {
  639. if (ofpci_verbose)
  640. printk(" * %s\n", child->full_name);
  641. reg = of_get_property(child, "reg", &reglen);
  642. if (reg == NULL || reglen < 20)
  643. continue;
  644. devfn = (reg[0] >> 8) & 0xff;
  645. /* This is a workaround for some device trees
  646. * which list PCI devices twice. On the V100
  647. * for example, device number 3 is listed twice.
  648. * Once as "pm" and once again as "lomp".
  649. */
  650. if (devfn == prev_devfn)
  651. continue;
  652. prev_devfn = devfn;
  653. /* create a new pci_dev for this device */
  654. dev = of_create_pci_dev(pbm, child, bus, devfn, 0);
  655. if (!dev)
  656. continue;
  657. if (ofpci_verbose)
  658. printk("PCI: dev header type: %x\n",
  659. dev->hdr_type);
  660. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  661. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  662. of_scan_pci_bridge(pbm, child, dev);
  663. }
  664. }
  665. static ssize_t
  666. show_pciobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
  667. {
  668. struct pci_dev *pdev;
  669. struct device_node *dp;
  670. pdev = to_pci_dev(dev);
  671. dp = pdev->dev.archdata.prom_node;
  672. return snprintf (buf, PAGE_SIZE, "%s\n", dp->full_name);
  673. }
  674. static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_pciobppath_attr, NULL);
  675. static void __devinit pci_bus_register_of_sysfs(struct pci_bus *bus)
  676. {
  677. struct pci_dev *dev;
  678. struct pci_bus *child_bus;
  679. int err;
  680. list_for_each_entry(dev, &bus->devices, bus_list) {
  681. /* we don't really care if we can create this file or
  682. * not, but we need to assign the result of the call
  683. * or the world will fall under alien invasion and
  684. * everybody will be frozen on a spaceship ready to be
  685. * eaten on alpha centauri by some green and jelly
  686. * humanoid.
  687. */
  688. err = sysfs_create_file(&dev->dev.kobj, &dev_attr_obppath.attr);
  689. }
  690. list_for_each_entry(child_bus, &bus->children, node)
  691. pci_bus_register_of_sysfs(child_bus);
  692. }
  693. int pci_host_bridge_read_pci_cfg(struct pci_bus *bus_dev,
  694. unsigned int devfn,
  695. int where, int size,
  696. u32 *value)
  697. {
  698. static u8 fake_pci_config[] = {
  699. 0x8e, 0x10, /* Vendor: 0x108e (Sun) */
  700. 0xf0, 0x80, /* Device: 0x80f0 (Fire) */
  701. 0x46, 0x01, /* Command: 0x0146 (SERR, PARITY, MASTER, MEM) */
  702. 0xa0, 0x22, /* Status: 0x02a0 (DEVSEL_MED, FB2B, 66MHZ) */
  703. 0x00, 0x00, 0x00, 0x06, /* Class: 0x06000000 host bridge */
  704. 0x00, /* Cacheline: 0x00 */
  705. 0x40, /* Latency: 0x40 */
  706. 0x00, /* Header-Type: 0x00 normal */
  707. };
  708. *value = 0;
  709. if (where >= 0 && where < sizeof(fake_pci_config) &&
  710. (where + size) >= 0 &&
  711. (where + size) < sizeof(fake_pci_config) &&
  712. size <= sizeof(u32)) {
  713. while (size--) {
  714. *value <<= 8;
  715. *value |= fake_pci_config[where + size];
  716. }
  717. }
  718. return PCIBIOS_SUCCESSFUL;
  719. }
  720. int pci_host_bridge_write_pci_cfg(struct pci_bus *bus_dev,
  721. unsigned int devfn,
  722. int where, int size,
  723. u32 value)
  724. {
  725. return PCIBIOS_SUCCESSFUL;
  726. }
  727. struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm)
  728. {
  729. struct device_node *node = pbm->prom_node;
  730. struct pci_dev *host_pdev;
  731. struct pci_bus *bus;
  732. printk("PCI: Scanning PBM %s\n", node->full_name);
  733. /* XXX parent device? XXX */
  734. bus = pci_create_bus(NULL, pbm->pci_first_busno, pbm->pci_ops, pbm);
  735. if (!bus) {
  736. printk(KERN_ERR "Failed to create bus for %s\n",
  737. node->full_name);
  738. return NULL;
  739. }
  740. bus->secondary = pbm->pci_first_busno;
  741. bus->subordinate = pbm->pci_last_busno;
  742. bus->resource[0] = &pbm->io_space;
  743. bus->resource[1] = &pbm->mem_space;
  744. /* Create the dummy host bridge and link it in. */
  745. host_pdev = of_create_pci_dev(pbm, node, bus, 0x00, 1);
  746. bus->self = host_pdev;
  747. pci_of_scan_bus(pbm, node, bus);
  748. pci_bus_add_devices(bus);
  749. pci_bus_register_of_sysfs(bus);
  750. return bus;
  751. }
  752. static void __init pci_scan_each_controller_bus(void)
  753. {
  754. struct pci_pbm_info *pbm;
  755. for (pbm = pci_pbm_root; pbm; pbm = pbm->next)
  756. pbm->scan_bus(pbm);
  757. }
  758. extern void power_init(void);
  759. static int __init pcibios_init(void)
  760. {
  761. pci_controller_probe();
  762. if (pci_pbm_root == NULL)
  763. return 0;
  764. pci_scan_each_controller_bus();
  765. isa_init();
  766. ebus_init();
  767. power_init();
  768. return 0;
  769. }
  770. subsys_initcall(pcibios_init);
  771. void __devinit pcibios_fixup_bus(struct pci_bus *pbus)
  772. {
  773. struct pci_pbm_info *pbm = pbus->sysdata;
  774. /* Generic PCI bus probing sets these to point at
  775. * &io{port,mem}_resouce which is wrong for us.
  776. */
  777. pbus->resource[0] = &pbm->io_space;
  778. pbus->resource[1] = &pbm->mem_space;
  779. }
  780. struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r)
  781. {
  782. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  783. struct resource *root = NULL;
  784. if (r->flags & IORESOURCE_IO)
  785. root = &pbm->io_space;
  786. if (r->flags & IORESOURCE_MEM)
  787. root = &pbm->mem_space;
  788. return root;
  789. }
  790. void pcibios_update_irq(struct pci_dev *pdev, int irq)
  791. {
  792. }
  793. void pcibios_align_resource(void *data, struct resource *res,
  794. resource_size_t size, resource_size_t align)
  795. {
  796. }
  797. int pcibios_enable_device(struct pci_dev *dev, int mask)
  798. {
  799. u16 cmd, oldcmd;
  800. int i;
  801. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  802. oldcmd = cmd;
  803. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  804. struct resource *res = &dev->resource[i];
  805. /* Only set up the requested stuff */
  806. if (!(mask & (1<<i)))
  807. continue;
  808. if (res->flags & IORESOURCE_IO)
  809. cmd |= PCI_COMMAND_IO;
  810. if (res->flags & IORESOURCE_MEM)
  811. cmd |= PCI_COMMAND_MEMORY;
  812. }
  813. if (cmd != oldcmd) {
  814. printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
  815. pci_name(dev), cmd);
  816. /* Enable the appropriate bits in the PCI command register. */
  817. pci_write_config_word(dev, PCI_COMMAND, cmd);
  818. }
  819. return 0;
  820. }
  821. void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
  822. struct resource *res)
  823. {
  824. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  825. struct resource zero_res, *root;
  826. zero_res.start = 0;
  827. zero_res.end = 0;
  828. zero_res.flags = res->flags;
  829. if (res->flags & IORESOURCE_IO)
  830. root = &pbm->io_space;
  831. else
  832. root = &pbm->mem_space;
  833. pci_resource_adjust(&zero_res, root);
  834. region->start = res->start - zero_res.start;
  835. region->end = res->end - zero_res.start;
  836. }
  837. EXPORT_SYMBOL(pcibios_resource_to_bus);
  838. void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res,
  839. struct pci_bus_region *region)
  840. {
  841. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  842. struct resource *root;
  843. res->start = region->start;
  844. res->end = region->end;
  845. if (res->flags & IORESOURCE_IO)
  846. root = &pbm->io_space;
  847. else
  848. root = &pbm->mem_space;
  849. pci_resource_adjust(res, root);
  850. }
  851. EXPORT_SYMBOL(pcibios_bus_to_resource);
  852. char * __devinit pcibios_setup(char *str)
  853. {
  854. return str;
  855. }
  856. /* Platform support for /proc/bus/pci/X/Y mmap()s. */
  857. /* If the user uses a host-bridge as the PCI device, he may use
  858. * this to perform a raw mmap() of the I/O or MEM space behind
  859. * that controller.
  860. *
  861. * This can be useful for execution of x86 PCI bios initialization code
  862. * on a PCI card, like the xfree86 int10 stuff does.
  863. */
  864. static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma,
  865. enum pci_mmap_state mmap_state)
  866. {
  867. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  868. unsigned long space_size, user_offset, user_size;
  869. if (mmap_state == pci_mmap_io) {
  870. space_size = (pbm->io_space.end -
  871. pbm->io_space.start) + 1;
  872. } else {
  873. space_size = (pbm->mem_space.end -
  874. pbm->mem_space.start) + 1;
  875. }
  876. /* Make sure the request is in range. */
  877. user_offset = vma->vm_pgoff << PAGE_SHIFT;
  878. user_size = vma->vm_end - vma->vm_start;
  879. if (user_offset >= space_size ||
  880. (user_offset + user_size) > space_size)
  881. return -EINVAL;
  882. if (mmap_state == pci_mmap_io) {
  883. vma->vm_pgoff = (pbm->io_space.start +
  884. user_offset) >> PAGE_SHIFT;
  885. } else {
  886. vma->vm_pgoff = (pbm->mem_space.start +
  887. user_offset) >> PAGE_SHIFT;
  888. }
  889. return 0;
  890. }
  891. /* Adjust vm_pgoff of VMA such that it is the physical page offset
  892. * corresponding to the 32-bit pci bus offset for DEV requested by the user.
  893. *
  894. * Basically, the user finds the base address for his device which he wishes
  895. * to mmap. They read the 32-bit value from the config space base register,
  896. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  897. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  898. *
  899. * Returns negative error code on failure, zero on success.
  900. */
  901. static int __pci_mmap_make_offset(struct pci_dev *pdev,
  902. struct vm_area_struct *vma,
  903. enum pci_mmap_state mmap_state)
  904. {
  905. unsigned long user_paddr, user_size;
  906. int i, err;
  907. /* First compute the physical address in vma->vm_pgoff,
  908. * making sure the user offset is within range in the
  909. * appropriate PCI space.
  910. */
  911. err = __pci_mmap_make_offset_bus(pdev, vma, mmap_state);
  912. if (err)
  913. return err;
  914. /* If this is a mapping on a host bridge, any address
  915. * is OK.
  916. */
  917. if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_HOST)
  918. return err;
  919. /* Otherwise make sure it's in the range for one of the
  920. * device's resources.
  921. */
  922. user_paddr = vma->vm_pgoff << PAGE_SHIFT;
  923. user_size = vma->vm_end - vma->vm_start;
  924. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  925. struct resource *rp = &pdev->resource[i];
  926. /* Active? */
  927. if (!rp->flags)
  928. continue;
  929. /* Same type? */
  930. if (i == PCI_ROM_RESOURCE) {
  931. if (mmap_state != pci_mmap_mem)
  932. continue;
  933. } else {
  934. if ((mmap_state == pci_mmap_io &&
  935. (rp->flags & IORESOURCE_IO) == 0) ||
  936. (mmap_state == pci_mmap_mem &&
  937. (rp->flags & IORESOURCE_MEM) == 0))
  938. continue;
  939. }
  940. if ((rp->start <= user_paddr) &&
  941. (user_paddr + user_size) <= (rp->end + 1UL))
  942. break;
  943. }
  944. if (i > PCI_ROM_RESOURCE)
  945. return -EINVAL;
  946. return 0;
  947. }
  948. /* Set vm_flags of VMA, as appropriate for this architecture, for a pci device
  949. * mapping.
  950. */
  951. static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma,
  952. enum pci_mmap_state mmap_state)
  953. {
  954. vma->vm_flags |= (VM_IO | VM_RESERVED);
  955. }
  956. /* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  957. * device mapping.
  958. */
  959. static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma,
  960. enum pci_mmap_state mmap_state)
  961. {
  962. /* Our io_remap_pfn_range takes care of this, do nothing. */
  963. }
  964. /* Perform the actual remap of the pages for a PCI device mapping, as appropriate
  965. * for this architecture. The region in the process to map is described by vm_start
  966. * and vm_end members of VMA, the base physical address is found in vm_pgoff.
  967. * The pci device structure is provided so that architectures may make mapping
  968. * decisions on a per-device or per-bus basis.
  969. *
  970. * Returns a negative error code on failure, zero on success.
  971. */
  972. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  973. enum pci_mmap_state mmap_state,
  974. int write_combine)
  975. {
  976. int ret;
  977. ret = __pci_mmap_make_offset(dev, vma, mmap_state);
  978. if (ret < 0)
  979. return ret;
  980. __pci_mmap_set_flags(dev, vma, mmap_state);
  981. __pci_mmap_set_pgprot(dev, vma, mmap_state);
  982. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  983. ret = io_remap_pfn_range(vma, vma->vm_start,
  984. vma->vm_pgoff,
  985. vma->vm_end - vma->vm_start,
  986. vma->vm_page_prot);
  987. if (ret)
  988. return ret;
  989. return 0;
  990. }
  991. #ifdef CONFIG_NUMA
  992. int pcibus_to_node(struct pci_bus *pbus)
  993. {
  994. struct pci_pbm_info *pbm = pbus->sysdata;
  995. return pbm->numa_node;
  996. }
  997. EXPORT_SYMBOL(pcibus_to_node);
  998. #endif
  999. /* Return the domain nuber for this pci bus */
  1000. int pci_domain_nr(struct pci_bus *pbus)
  1001. {
  1002. struct pci_pbm_info *pbm = pbus->sysdata;
  1003. int ret;
  1004. if (pbm == NULL || pbm->parent == NULL) {
  1005. ret = -ENXIO;
  1006. } else {
  1007. ret = pbm->index;
  1008. }
  1009. return ret;
  1010. }
  1011. EXPORT_SYMBOL(pci_domain_nr);
  1012. #ifdef CONFIG_PCI_MSI
  1013. int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
  1014. {
  1015. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  1016. int virt_irq;
  1017. if (!pbm->setup_msi_irq)
  1018. return -EINVAL;
  1019. return pbm->setup_msi_irq(&virt_irq, pdev, desc);
  1020. }
  1021. void arch_teardown_msi_irq(unsigned int virt_irq)
  1022. {
  1023. struct msi_desc *entry = get_irq_msi(virt_irq);
  1024. struct pci_dev *pdev = entry->dev;
  1025. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  1026. if (!pbm->teardown_msi_irq)
  1027. return;
  1028. return pbm->teardown_msi_irq(virt_irq, pdev);
  1029. }
  1030. #endif /* !(CONFIG_PCI_MSI) */
  1031. struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
  1032. {
  1033. return pdev->dev.archdata.prom_node;
  1034. }
  1035. EXPORT_SYMBOL(pci_device_to_OF_node);
  1036. static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit)
  1037. {
  1038. struct pci_dev *ali_isa_bridge;
  1039. u8 val;
  1040. /* ALI sound chips generate 31-bits of DMA, a special register
  1041. * determines what bit 31 is emitted as.
  1042. */
  1043. ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL,
  1044. PCI_DEVICE_ID_AL_M1533,
  1045. NULL);
  1046. pci_read_config_byte(ali_isa_bridge, 0x7e, &val);
  1047. if (set_bit)
  1048. val |= 0x01;
  1049. else
  1050. val &= ~0x01;
  1051. pci_write_config_byte(ali_isa_bridge, 0x7e, val);
  1052. pci_dev_put(ali_isa_bridge);
  1053. }
  1054. int pci_dma_supported(struct pci_dev *pdev, u64 device_mask)
  1055. {
  1056. u64 dma_addr_mask;
  1057. if (pdev == NULL) {
  1058. dma_addr_mask = 0xffffffff;
  1059. } else {
  1060. struct iommu *iommu = pdev->dev.archdata.iommu;
  1061. dma_addr_mask = iommu->dma_addr_mask;
  1062. if (pdev->vendor == PCI_VENDOR_ID_AL &&
  1063. pdev->device == PCI_DEVICE_ID_AL_M5451 &&
  1064. device_mask == 0x7fffffff) {
  1065. ali_sound_dma_hack(pdev,
  1066. (dma_addr_mask & 0x80000000) != 0);
  1067. return 1;
  1068. }
  1069. }
  1070. if (device_mask >= (1UL << 32UL))
  1071. return 0;
  1072. return (device_mask & dma_addr_mask) == dma_addr_mask;
  1073. }
  1074. void pci_resource_to_user(const struct pci_dev *pdev, int bar,
  1075. const struct resource *rp, resource_size_t *start,
  1076. resource_size_t *end)
  1077. {
  1078. struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller;
  1079. unsigned long offset;
  1080. if (rp->flags & IORESOURCE_IO)
  1081. offset = pbm->io_space.start;
  1082. else
  1083. offset = pbm->mem_space.start;
  1084. *start = rp->start - offset;
  1085. *end = rp->end - offset;
  1086. }
  1087. #endif /* !(CONFIG_PCI) */