📄 pci.c
字号:
addr.max_address_range + offset, flags)) printk(KERN_ERR "alloc 0x%lx-0x%lx from %s for %s failed\n", addr.min_address_range + offset, addr.max_address_range + offset, root->name, info->name); } return AE_OK;}struct pci_bus *pcibios_scan_root (void *handle, int seg, int bus){ struct pci_root_info info; struct pci_controller *controller; unsigned int windows = 0; char *name; controller = alloc_pci_controller(seg); if (!controller) goto out1; controller->acpi_handle = handle; acpi_walk_resources(handle, METHOD_NAME__CRS, count_window, &windows); controller->window = kmalloc(sizeof(*controller->window) * windows, GFP_KERNEL); if (!controller->window) goto out2; name = kmalloc(16, GFP_KERNEL); if (!name) goto out3; sprintf(name, "PCI Bus %02x:%02x", seg, bus); info.controller = controller; info.name = name; acpi_walk_resources(handle, METHOD_NAME__CRS, add_window, &info); return scan_root_bus(bus, pci_root_ops, controller);out3: kfree(controller->window);out2: kfree(controller);out1: return NULL;}void __initpcibios_config_init (void){ if (pci_root_ops) return; printk("PCI: Using SAL to access configuration space\n"); pci_root_ops = &pci_sal_ops; pci_config_read = pci_sal_read; pci_config_write = pci_sal_write; return;}void __initpcibios_init (void){ pcibios_config_init(); platform_pci_fixup(0); /* phase 0 fixups (before buses scanned) */ platform_pci_fixup(1); /* phase 1 fixups (after buses scanned) */ return;}void __initpcibios_fixup_device_resources (struct pci_dev *dev, struct pci_bus *bus){ struct pci_controller *controller = PCI_CONTROLLER(dev); struct pci_window *window; int i, j; for (i = 0; i < PCI_NUM_RESOURCES; i++) { if (!dev->resource[i].start) continue;#define contains(win, res) ((res)->start >= (win)->start && \ (res)->end <= (win)->end) for (j = 0; j < controller->windows; j++) { window = &controller->window[j]; if (((dev->resource[i].flags & IORESOURCE_MEM && window->resource.flags & IORESOURCE_MEM) || (dev->resource[i].flags & IORESOURCE_IO && window->resource.flags & IORESOURCE_IO)) && contains(&window->resource, &dev->resource[i])) { dev->resource[i].start += window->offset; dev->resource[i].end += window->offset; } } }}/* * Called after each bus is probed, but before its children are examined. */void __devinitpcibios_fixup_bus (struct pci_bus *b){ struct list_head *ln; for (ln = b->devices.next; ln != &b->devices; ln = ln->next) pcibios_fixup_device_resources(pci_dev_b(ln), b);}void __devinitpcibios_update_resource (struct pci_dev *dev, struct resource *root, struct resource *res, int resource){ unsigned long where, size; u32 reg; where = PCI_BASE_ADDRESS_0 + (resource * 4); size = res->end - res->start; pci_read_config_dword(dev, where, ®); reg = (reg & size) | (((u32)(res->start - root->start)) & ~size); pci_write_config_dword(dev, where, reg); /* ??? FIXME -- record old value for shutdown. */}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. */}void __devinitpcibios_fixup_pbus_ranges (struct pci_bus * bus, struct pbus_set_ranges_data * ranges){ ranges->io_start -= bus->resource[0]->start; ranges->io_end -= bus->resource[0]->start; ranges->mem_start -= bus->resource[1]->start; ranges->mem_end -= bus->resource[1]->start;}static inline intpcibios_enable_resources (struct pci_dev *dev, int mask){ u16 cmd, old_cmd; int idx; struct resource *r; if (!dev) return -EINVAL; pci_read_config_word(dev, PCI_COMMAND, &cmd); old_cmd = cmd; for (idx=0; idx<6; idx++) { /* Only set up the desired resources. */ if (!(mask & (1 << idx))) continue; r = &dev->resource[idx]; if (!r->start && r->end) { printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", dev->slot_name); return -EINVAL; } if (r->flags & IORESOURCE_IO) cmd |= PCI_COMMAND_IO; if (r->flags & IORESOURCE_MEM) cmd |= PCI_COMMAND_MEMORY; } if (dev->resource[PCI_ROM_RESOURCE].start) cmd |= PCI_COMMAND_MEMORY; if (cmd != old_cmd) { printk("PCI: Enabling device %s (%04x -> %04x)\n", dev->slot_name, 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; printk(KERN_INFO "PCI: Found IRQ %d for device %s\n", dev->irq, dev->slot_name); return 0;}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_LOCKED | VM_IO); if (write_combine) vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); else vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); if (remap_page_range(vma->vm_start, vma->vm_pgoff << PAGE_SHIFT, vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0;}/** * 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_set_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,", dev->slot_name, 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -