12 #include <linux/sched.h>
13 #include <linux/stat.h>
14 #include <linux/slab.h>
15 #include <linux/pci.h>
24 base = sparse ? hose->sparse_mem_base : hose->dense_mem_base;
26 base = sparse ? hose->sparse_io_base : hose->dense_io_base;
29 vma->
vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
36 static int __pci_mmap_fits(
struct pci_dev *pdev,
int num,
40 int shift = sparse ? 5 : 0;
46 if (start < size && size - start >= nr)
48 WARN(1,
"process \"%s\" tried to map%s 0x%08lx-0x%08lx on %s BAR %d "
50 current->comm, sparse ?
" sparse" :
"", start, start + nr,
51 pci_name(pdev), num, size);
64 static int pci_mmap_resource(
struct kobject *kobj,
78 if (i >= PCI_ROM_RESOURCE)
81 if (!__pci_mmap_fits(pdev, i, vma, sparse))
91 return hose_mmap_page_range(pdev->
sysdata, vma, mmap_type, sparse);
94 static int pci_mmap_resource_sparse(
struct file *filp,
struct kobject *kobj,
98 return pci_mmap_resource(kobj, attr, vma, 1);
101 static int pci_mmap_resource_dense(
struct file *filp,
struct kobject *kobj,
105 return pci_mmap_resource(kobj, attr, vma, 0);
136 static int sparse_mem_mmap_fits(
struct pci_dev *pdev,
int num)
141 unsigned long sparse_size;
149 dense_offset = (
long)(hose->dense_mem_base - hose->sparse_mem_base);
150 sparse_size = dense_offset >= 0x400000000
UL ? 0x20000000 : 0x8000000;
152 return bar.end < sparse_size;
155 static int pci_create_one_attr(
struct pci_dev *pdev,
int num,
char *
name,
157 unsigned long sparse)
161 sprintf(name,
"resource%d%s", num, suffix);
162 res_attr->
mmap = sparse ? pci_mmap_resource_sparse :
163 pci_mmap_resource_dense;
166 res_attr->
size = sparse ? size << 5 :
size;
171 static int pci_create_attr(
struct pci_dev *pdev,
int num)
175 unsigned long sparse_base, dense_base;
184 sparse_base = hose->sparse_mem_base;
185 dense_base = hose->dense_mem_base;
186 if (sparse_base && !sparse_mem_mmap_fits(pdev, num)) {
192 sparse_base = hose->sparse_io_base;
193 dense_base = hose->dense_io_base;
212 retval = pci_create_one_attr(pdev, num, attr_name, suffix, attr,
221 return pci_create_one_attr(pdev, num, attr_name,
"_dense", attr, 0);
242 retval = pci_create_attr(pdev, i);
263 if (start < size && size - start >= nr)
265 WARN(1,
"process \"%s\" tried to map%s 0x%08lx-0x%08lx on hose %d "
267 current->comm, sparse ?
" sparse" :
"", start, start + nr,
277 base = (mmap_type ==
pci_mmap_mem) ? hose->sparse_mem_base :
278 hose->sparse_io_base;
287 int sparse = has_sparse(hose, mmap_type);
292 if (!__legacy_mmap_fits(hose, vma, res_size, sparse))
295 return hose_mmap_page_range(hose, vma, mmap_type, sparse);
309 if (!has_sparse(hose, mmap_type))
313 bus->
legacy_mem->attr.name =
"legacy_mem_sparse";
316 bus->
legacy_io->attr.name =
"legacy_io_sparse";
327 port += hose->io_space->start;
331 *((
u8 *)val) =
inb(port);
336 *((
u16 *)val) =
inw(port);
341 *((
u32 *)val) =
inl(port);
351 port += hose->io_space->start;