Lines Matching +full:bus +full:- +full:num

1 // SPDX-License-Identifier: GPL-2.0
3 * arch/alpha/kernel/pci-sysfs.c
10 * drivers/pci/pci-sysfs.c
25 base = sparse ? hose->sparse_mem_base : hose->dense_mem_base; in hose_mmap_page_range()
27 base = sparse ? hose->sparse_io_base : hose->dense_io_base; in hose_mmap_page_range()
29 vma->vm_pgoff += base >> PAGE_SHIFT; in hose_mmap_page_range()
31 return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, in hose_mmap_page_range()
32 vma->vm_end - vma->vm_start, in hose_mmap_page_range()
33 vma->vm_page_prot); in hose_mmap_page_range()
36 static int __pci_mmap_fits(struct pci_dev *pdev, int num, in __pci_mmap_fits() argument
43 start = vma->vm_pgoff; in __pci_mmap_fits()
44 size = ((pci_resource_len(pdev, num) - 1) >> (PAGE_SHIFT - shift)) + 1; in __pci_mmap_fits()
46 if (start < size && size - start >= nr) in __pci_mmap_fits()
48 WARN(1, "process \"%s\" tried to map%s 0x%08lx-0x%08lx on %s BAR %d " in __pci_mmap_fits()
50 current->comm, sparse ? " sparse" : "", start, start + nr, in __pci_mmap_fits()
51 pci_name(pdev), num, size); in __pci_mmap_fits()
56 * pci_mmap_resource - map a PCI resource into user memory space
62 * Use the bus mapping routines to map a PCI resource into userspace.
71 struct resource *res = attr->private; in pci_mmap_resource()
77 if (res == &pdev->resource[i]) in pci_mmap_resource()
80 return -ENODEV; in pci_mmap_resource()
82 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) in pci_mmap_resource()
83 return -EINVAL; in pci_mmap_resource()
86 return -EINVAL; in pci_mmap_resource()
88 pcibios_resource_to_bus(pdev->bus, &bar, res); in pci_mmap_resource()
89 vma->vm_pgoff += bar.start >> (PAGE_SHIFT - (sparse ? 5 : 0)); in pci_mmap_resource()
90 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; in pci_mmap_resource()
92 return hose_mmap_page_range(pdev->sysdata, vma, mmap_type, sparse); in pci_mmap_resource()
110 * pci_remove_resource_files - cleanup resource files
123 res_attr = pdev->res_attr[i]; in pci_remove_resource_files()
125 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); in pci_remove_resource_files()
129 res_attr = pdev->res_attr_wc[i]; in pci_remove_resource_files()
131 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); in pci_remove_resource_files()
137 static int sparse_mem_mmap_fits(struct pci_dev *pdev, int num) in sparse_mem_mmap_fits() argument
140 struct pci_controller *hose = pdev->sysdata; in sparse_mem_mmap_fits()
144 pcibios_resource_to_bus(pdev->bus, &bar, &pdev->resource[num]); in sparse_mem_mmap_fits()
149 to 128M or 512M of the bus space. */ in sparse_mem_mmap_fits()
150 dense_offset = (long)(hose->dense_mem_base - hose->sparse_mem_base); in sparse_mem_mmap_fits()
156 static int pci_create_one_attr(struct pci_dev *pdev, int num, char *name, in pci_create_one_attr() argument
160 size_t size = pci_resource_len(pdev, num); in pci_create_one_attr()
162 sprintf(name, "resource%d%s", num, suffix); in pci_create_one_attr()
163 res_attr->mmap = sparse ? pci_mmap_resource_sparse : in pci_create_one_attr()
165 res_attr->attr.name = name; in pci_create_one_attr()
166 res_attr->attr.mode = S_IRUSR | S_IWUSR; in pci_create_one_attr()
167 res_attr->size = sparse ? size << 5 : size; in pci_create_one_attr()
168 res_attr->private = &pdev->resource[num]; in pci_create_one_attr()
169 return sysfs_create_bin_file(&pdev->dev.kobj, res_attr); in pci_create_one_attr()
172 static int pci_create_attr(struct pci_dev *pdev, int num) in pci_create_attr() argument
178 struct pci_controller *hose = pdev->sysdata; in pci_create_attr()
184 if (pdev->resource[num].flags & IORESOURCE_MEM) { in pci_create_attr()
185 sparse_base = hose->sparse_mem_base; in pci_create_attr()
186 dense_base = hose->dense_mem_base; in pci_create_attr()
187 if (sparse_base && !sparse_mem_mmap_fits(pdev, num)) { in pci_create_attr()
193 sparse_base = hose->sparse_io_base; in pci_create_attr()
194 dense_base = hose->dense_io_base; in pci_create_attr()
208 return -ENOMEM; in pci_create_attr()
212 pdev->res_attr[num] = attr; in pci_create_attr()
213 retval = pci_create_one_attr(pdev, num, attr_name, suffix, attr, in pci_create_attr()
221 pdev->res_attr_wc[num] = attr; in pci_create_attr()
222 return pci_create_one_attr(pdev, num, attr_name, "_dense", attr, 0); in pci_create_attr()
226 * pci_create_resource_files - create resource files in sysfs for @pdev
254 /* Legacy I/O bus mapping stuff. */
263 start = vma->vm_pgoff; in __legacy_mmap_fits()
264 size = ((res_size - 1) >> PAGE_SHIFT) + 1; in __legacy_mmap_fits()
266 if (start < size && size - start >= nr) in __legacy_mmap_fits()
268 WARN(1, "process \"%s\" tried to map%s 0x%08lx-0x%08lx on hose %d " in __legacy_mmap_fits()
270 current->comm, sparse ? " sparse" : "", start, start + nr, in __legacy_mmap_fits()
271 hose->index, size); in __legacy_mmap_fits()
280 base = (mmap_type == pci_mmap_mem) ? hose->sparse_mem_base : in has_sparse()
281 hose->sparse_io_base; in has_sparse()
286 int pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma, in pci_mmap_legacy_page_range() argument
289 struct pci_controller *hose = bus->sysdata; in pci_mmap_legacy_page_range()
293 res_size = (mmap_type == pci_mmap_mem) ? bus->legacy_mem->size : in pci_mmap_legacy_page_range()
294 bus->legacy_io->size; in pci_mmap_legacy_page_range()
296 return -EINVAL; in pci_mmap_legacy_page_range()
302 * pci_adjust_legacy_attr - adjustment of legacy file attributes
303 * @bus: bus to create files under
308 void pci_adjust_legacy_attr(struct pci_bus *bus, enum pci_mmap_state mmap_type) in pci_adjust_legacy_attr() argument
310 struct pci_controller *hose = bus->sysdata; in pci_adjust_legacy_attr()
316 bus->legacy_mem->attr.name = "legacy_mem_sparse"; in pci_adjust_legacy_attr()
317 bus->legacy_mem->size <<= 5; in pci_adjust_legacy_attr()
319 bus->legacy_io->attr.name = "legacy_io_sparse"; in pci_adjust_legacy_attr()
320 bus->legacy_io->size <<= 5; in pci_adjust_legacy_attr()
325 /* Legacy I/O bus read/write functions */
326 int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val, size_t size) in pci_legacy_read() argument
328 struct pci_controller *hose = bus->sysdata; in pci_legacy_read()
330 port += hose->io_space->start; in pci_legacy_read()
338 return -EINVAL; in pci_legacy_read()
343 return -EINVAL; in pci_legacy_read()
347 return -EINVAL; in pci_legacy_read()
350 int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val, size_t size) in pci_legacy_write() argument
352 struct pci_controller *hose = bus->sysdata; in pci_legacy_write()
354 port += hose->io_space->start; in pci_legacy_write()
362 return -EINVAL; in pci_legacy_write()
367 return -EINVAL; in pci_legacy_write()
371 return -EINVAL; in pci_legacy_write()