📄 pci.c
字号:
break; } res->start = region->start + offset; res->end = region->end + offset;}EXPORT_SYMBOL(pcibios_bus_to_resource);static int __devinit is_valid_resource(struct pci_dev *dev, int idx){ unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; struct resource *devr = &dev->resource[idx]; if (!dev->bus) return 0; for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) { struct resource *busr = dev->bus->resource[i]; if (!busr || ((busr->flags ^ devr->flags) & type_mask)) continue; if ((devr->start) && (devr->start >= busr->start) && (devr->end <= busr->end)) return 1; } return 0;}static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev){ struct pci_bus_region region; int i; int limit = (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) ? \ PCI_BRIDGE_RESOURCES : PCI_NUM_RESOURCES; for (i = 0; i < limit; i++) { if (!dev->resource[i].flags) continue; region.start = dev->resource[i].start; region.end = dev->resource[i].end; pcibios_bus_to_resource(dev, &dev->resource[i], ®ion); if ((is_valid_resource(dev, i))) pci_claim_resource(dev, i); }}/* * Called after each bus is probed, but before its children are examined. */void __devinitpcibios_fixup_bus (struct pci_bus *b){ struct pci_dev *dev; if (b->self) { pci_read_bridge_bases(b); pcibios_fixup_device_resources(b->self); } list_for_each_entry(dev, &b->devices, bus_list) pcibios_fixup_device_resources(dev); return;}void __devinitpcibios_update_irq (struct pci_dev *dev, int irq){ pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); /* ??? FIXME -- record old value for shutdown. */}static inline intpcibios_enable_resources (struct pci_dev *dev, int mask){ u16 cmd, old_cmd; int idx; struct resource *r; unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; if (!dev) return -EINVAL; pci_read_config_word(dev, PCI_COMMAND, &cmd); old_cmd = cmd; for (idx=0; idx<PCI_NUM_RESOURCES; idx++) { /* Only set up the desired resources. */ if (!(mask & (1 << idx))) continue; r = &dev->resource[idx]; if (!(r->flags & type_mask)) continue; if ((idx == PCI_ROM_RESOURCE) && (!(r->flags & IORESOURCE_ROM_ENABLE))) continue; if (!r->start && r->end) { printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev)); return -EINVAL; } if (r->flags & IORESOURCE_IO) cmd |= PCI_COMMAND_IO; if (r->flags & IORESOURCE_MEM) cmd |= PCI_COMMAND_MEMORY; } if (cmd != old_cmd) { printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd); pci_write_config_word(dev, PCI_COMMAND, cmd); } return 0;}intpcibios_enable_device (struct pci_dev *dev, int mask){ int ret; ret = pcibios_enable_resources(dev, mask); if (ret < 0) return ret; return acpi_pci_irq_enable(dev);}voidpcibios_disable_device (struct pci_dev *dev){ acpi_pci_irq_disable(dev);}voidpcibios_align_resource (void *data, struct resource *res, unsigned long size, unsigned long align){}/* * PCI BIOS setup, always defaults to SAL interface */char * __initpcibios_setup (char *str){ return NULL;}intpci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma, enum pci_mmap_state mmap_state, int write_combine){ /* * I/O space cannot be accessed via normal processor loads and * stores on this platform. */ if (mmap_state == pci_mmap_io) /* * XXX we could relax this for I/O spaces for which ACPI * indicates that the space is 1-to-1 mapped. But at the * moment, we don't support multiple PCI address spaces and * the legacy I/O space is not 1-to-1 mapped, so this is moot. */ return -EINVAL; /* * Leave vm_pgoff as-is, the PCI space address is the physical * address on this platform. */ vma->vm_flags |= (VM_SHM | VM_RESERVED | VM_IO); if (write_combine && efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start)) vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); else vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0;}/** * ia64_pci_get_legacy_mem - generic legacy mem routine * @bus: bus to get legacy memory base address for * * Find the base of legacy memory for @bus. This is typically the first * megabyte of bus address space for @bus or is simply 0 on platforms whose * chipsets support legacy I/O and memory routing. Returns the base address * or an error pointer if an error occurred. * * This is the ia64 generic version of this routine. Other platforms * are free to override it with a machine vector. */char *ia64_pci_get_legacy_mem(struct pci_bus *bus){ return (char *)__IA64_UNCACHED_OFFSET;}/** * pci_mmap_legacy_page_range - map legacy memory space to userland * @bus: bus whose legacy space we're mapping * @vma: vma passed in by mmap * * Map legacy memory space for this device back to userspace using a machine * vector to get the base address. */intpci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma){ char *addr; addr = pci_get_legacy_mem(bus); if (IS_ERR(addr)) return PTR_ERR(addr); vma->vm_pgoff += (unsigned long)addr >> PAGE_SHIFT; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_flags |= (VM_SHM | VM_RESERVED | VM_IO); if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0;}/** * ia64_pci_legacy_read - read from legacy I/O space * @bus: bus to read * @port: legacy port value * @val: caller allocated storage for returned value * @size: number of bytes to read * * Simply reads @size bytes from @port and puts the result in @val. * * Again, this (and the write routine) are generic versions that can be * overridden by the platform. This is necessary on platforms that don't * support legacy I/O routing or that hard fail on legacy I/O timeouts. */int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size){ int ret = size; switch (size) { case 1: *val = inb(port); break; case 2: *val = inw(port); break; case 4: *val = inl(port); break; default: ret = -EINVAL; break; } return ret;}/** * ia64_pci_legacy_write - perform a legacy I/O write * @bus: bus pointer * @port: port to write * @val: value to write * @size: number of bytes to write from @val * * Simply writes @size bytes of @val to @port. */int ia64_pci_legacy_write(struct pci_dev *bus, u16 port, u32 val, u8 size){ int ret = 0; switch (size) { case 1: outb(val, port); break; case 2: outw(val, port); break; case 4: outl(val, port); break; default: ret = -EINVAL; break; } return ret;}/** * pci_cacheline_size - determine cacheline size for PCI devices * @dev: void * * We want to use the line-size of the outer-most cache. We assume * that this line-size is the same for all CPUs. * * Code mostly taken from arch/ia64/kernel/palinfo.c:cache_info(). * * RETURNS: An appropriate -ERRNO error value on eror, or zero for success. */static unsigned longpci_cacheline_size (void){ u64 levels, unique_caches; s64 status; pal_cache_config_info_t cci; static u8 cacheline_size; if (cacheline_size) return cacheline_size; status = ia64_pal_cache_summary(&levels, &unique_caches); if (status != 0) { printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n", __FUNCTION__, status); return SMP_CACHE_BYTES; } status = ia64_pal_cache_config_info(levels - 1, /* cache_type (data_or_unified)= */ 2, &cci); if (status != 0) { printk(KERN_ERR "%s: ia64_pal_cache_config_info() failed (status=%ld)\n", __FUNCTION__, status); return SMP_CACHE_BYTES; } cacheline_size = 1 << cci.pcci_line_size; return cacheline_size;}/** * pcibios_prep_mwi - helper function for drivers/pci/pci.c:pci_set_mwi() * @dev: the PCI device for which MWI is enabled * * For ia64, we can get the cacheline sizes from PAL. * * RETURNS: An appropriate -ERRNO error value on eror, or zero for success. */intpcibios_prep_mwi (struct pci_dev *dev){ unsigned long desired_linesize, current_linesize; int rc = 0; u8 pci_linesize; desired_linesize = pci_cacheline_size(); pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &pci_linesize); current_linesize = 4 * pci_linesize; if (desired_linesize != current_linesize) { printk(KERN_WARNING "PCI: slot %s has incorrect PCI cache line size of %lu bytes,", pci_name(dev), current_linesize); if (current_linesize > desired_linesize) { printk(" expected %lu bytes instead\n", desired_linesize); rc = -EINVAL; } else { printk(" correcting to %lu\n", desired_linesize); pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, desired_linesize / 4); } } return rc;}int pci_vector_resources(int last, int nr_released){ int count = nr_released; count += (IA64_LAST_DEVICE_VECTOR - last); return count;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -