pci.c 32 KB

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