static u64 add_io_space (struct acpi_resource_address64 *addr) { u64 offset; int sparse = 0; int i; if (addr->address_translation_offset == 0) return IO_SPACE_BASE(0); /* part of legacy IO space */ if (addr->attribute.io.translation_attribute == ACPI_SPARSE_TRANSLATION) sparse = 1; offset = (u64) ioremap(addr->address_translation_offset, 0); for (i = 0; i < num_io_spaces; i++) if (io_space[i].mmio_base == offset && io_space[i].sparse == sparse) return IO_SPACE_BASE(i); if (num_io_spaces == MAX_IO_SPACES) { printk("Too many IO port spaces\n"); return ~0; } i = num_io_spaces++; io_space[i].mmio_base = offset; io_space[i].sparse = sparse; return IO_SPACE_BASE(i); }
static u64 __devinit add_io_space (struct pci_root_info *info, struct acpi_resource_address64 *addr) { struct resource *resource; char *name; u64 base, min, max, base_port; unsigned int sparse = 0, space_nr, len; resource = kzalloc(sizeof(*resource), GFP_KERNEL); if (!resource) { printk(KERN_ERR "PCI: No memory for %s I/O port space\n", info->name); goto out; } len = strlen(info->name) + 32; name = kzalloc(len, GFP_KERNEL); if (!name) { printk(KERN_ERR "PCI: No memory for %s I/O port space name\n", info->name); goto free_resource; } min = addr->minimum; max = min + addr->address_length - 1; if (addr->info.io.translation_type == ACPI_SPARSE_TRANSLATION) sparse = 1; space_nr = new_space(addr->translation_offset, sparse); if (space_nr == ~0) goto free_name; base = __pa(io_space[space_nr].mmio_base); base_port = IO_SPACE_BASE(space_nr); snprintf(name, len, "%s I/O Ports %08lx-%08lx", info->name, base_port + min, base_port + max); /* * The SDM guarantees the legacy 0-64K space is sparse, but if the * mapping is done by the processor (not the bridge), ACPI may not * mark it as sparse. */ if (space_nr == 0) sparse = 1; resource->name = name; resource->flags = IORESOURCE_MEM; resource->start = base + (sparse ? IO_SPACE_SPARSE_ENCODING(min) : min); resource->end = base + (sparse ? IO_SPACE_SPARSE_ENCODING(max) : max); insert_resource(&iomem_resource, resource); return base_port; free_name: kfree(name); free_resource: kfree(resource); out: return ~0; }