Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 2 | * This program is free software; you can redistribute it and/or modify it |
| 3 | * under the terms of the GNU General Public License as published by the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Free Software Foundation; either version 2 of the License, or (at your |
| 5 | * option) any later version. |
| 6 | * |
Ralf Baechle | c539ef7 | 2012-01-11 15:37:16 +0100 | [diff] [blame] | 7 | * Copyright (C) 2003, 04, 11 Ralf Baechle (ralf@linux-mips.org) |
| 8 | * Copyright (C) 2011 Wind River Systems, |
| 9 | * written by Ralf Baechle (ralf@linux-mips.org) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Ralf Baechle | c539ef7 | 2012-01-11 15:37:16 +0100 | [diff] [blame] | 11 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/bootmem.h> |
Paul Gortmaker | cae39d1 | 2011-07-28 18:46:31 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/pci.h> |
John Crispin | a48cf37 | 2012-05-04 10:50:13 +0200 | [diff] [blame] | 19 | #include <linux/of_address.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Ralf Baechle | c539ef7 | 2012-01-11 15:37:16 +0100 | [diff] [blame] | 21 | #include <asm/cpu-info.h> |
| 22 | |
Ralf Baechle | 982f6ff | 2009-09-17 02:25:07 +0200 | [diff] [blame] | 23 | unsigned long PCIBIOS_MIN_IO; |
Paul Burton | f8091a8 | 2016-10-05 18:18:11 +0100 | [diff] [blame] | 24 | EXPORT_SYMBOL(PCIBIOS_MIN_IO); |
| 25 | |
Ralf Baechle | 982f6ff | 2009-09-17 02:25:07 +0200 | [diff] [blame] | 26 | unsigned long PCIBIOS_MIN_MEM; |
Paul Burton | f8091a8 | 2016-10-05 18:18:11 +0100 | [diff] [blame] | 27 | EXPORT_SYMBOL(PCIBIOS_MIN_MEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Paul Burton | f474ba9 | 2016-10-05 18:18:09 +0100 | [diff] [blame] | 29 | static int __init pcibios_set_cache_line_size(void) |
Ralf Baechle | c539ef7 | 2012-01-11 15:37:16 +0100 | [diff] [blame] | 30 | { |
| 31 | struct cpuinfo_mips *c = ¤t_cpu_data; |
| 32 | unsigned int lsize; |
| 33 | |
| 34 | /* |
| 35 | * Set PCI cacheline size to that of the highest level in the |
| 36 | * cache hierarchy. |
| 37 | */ |
| 38 | lsize = c->dcache.linesz; |
| 39 | lsize = c->scache.linesz ? : lsize; |
| 40 | lsize = c->tcache.linesz ? : lsize; |
| 41 | |
| 42 | BUG_ON(!lsize); |
| 43 | |
| 44 | pci_dfl_cache_line_size = lsize >> 2; |
| 45 | |
| 46 | pr_debug("PCI: pci_cache_line_size set to %d bytes\n", lsize); |
Paul Burton | f474ba9 | 2016-10-05 18:18:09 +0100 | [diff] [blame] | 47 | return 0; |
Ralf Baechle | c539ef7 | 2012-01-11 15:37:16 +0100 | [diff] [blame] | 48 | } |
Paul Burton | f474ba9 | 2016-10-05 18:18:09 +0100 | [diff] [blame] | 49 | arch_initcall(pcibios_set_cache_line_size); |
Ralf Baechle | c539ef7 | 2012-01-11 15:37:16 +0100 | [diff] [blame] | 50 | |
Bjorn Helgaas | 8221a01 | 2016-06-17 14:43:34 -0500 | [diff] [blame] | 51 | void pci_resource_to_user(const struct pci_dev *dev, int bar, |
| 52 | const struct resource *rsrc, resource_size_t *start, |
| 53 | resource_size_t *end) |
| 54 | { |
| 55 | phys_addr_t size = resource_size(rsrc); |
| 56 | |
| 57 | *start = fixup_bigphys_addr(rsrc->start, size); |
| 58 | *end = rsrc->start + size; |
| 59 | } |
| 60 | |
Ralf Baechle | 98873f5 | 2008-12-09 17:58:46 +0000 | [diff] [blame] | 61 | int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, |
| 62 | enum pci_mmap_state mmap_state, int write_combine) |
| 63 | { |
| 64 | unsigned long prot; |
| 65 | |
| 66 | /* |
| 67 | * I/O space can be accessed via normal processor loads and stores on |
| 68 | * this platform but for now we elect not to do this and portable |
| 69 | * drivers should not do this anyway. |
| 70 | */ |
| 71 | if (mmap_state == pci_mmap_io) |
| 72 | return -EINVAL; |
| 73 | |
| 74 | /* |
| 75 | * Ignore write-combine; for now only return uncached mappings. |
| 76 | */ |
| 77 | prot = pgprot_val(vma->vm_page_prot); |
| 78 | prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED; |
| 79 | vma->vm_page_prot = __pgprot(prot); |
| 80 | |
| 81 | return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, |
| 82 | vma->vm_end - vma->vm_start, vma->vm_page_prot); |
| 83 | } |