pci.c 33 KB

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