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