pci.c 33 KB

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