pci.c 32 KB

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