pci.c 33 KB

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