5 #include <linux/types.h>
6 #include <linux/slab.h>
7 #include <linux/string.h>
9 #include <asm/scatterlist.h>
11 #include <asm/pci-bridge.h>
15 /* Values for the `which' argument to sys_pciconfig_iobase syscall. */
16 #define IOBASE_BRIDGE_NUMBER 0
17 #define IOBASE_MEMORY 1
19 #define IOBASE_ISA_IO 3
20 #define IOBASE_ISA_MEM 4
23 * Set this to 1 if you want the kernel to re-assign all PCI
26 extern int pci_assign_all_busses;
28 #define pcibios_assign_all_busses() (pci_assign_all_busses)
29 #define pcibios_scan_all_fns(a, b) 0
31 #define PCIBIOS_MIN_IO 0x1000
32 #define PCIBIOS_MIN_MEM 0x10000000
34 extern inline void pcibios_set_master(struct pci_dev *dev)
36 /* No special bus mastering setup handling */
39 extern inline void pcibios_penalize_isa_irq(int irq)
41 /* We don't do dynamic PCI IRQ allocation */
44 extern unsigned long pci_resource_to_bus(struct pci_dev *pdev, struct resource *res);
47 * The PCI bus bridge can translate addresses issued by the processor(s)
48 * into a different address on the PCI bus. On 32-bit cpus, we assume
49 * this mapping is 1-1, but on 64-bit systems it often isn't.
51 * Obsolete ! Drivers should now use pci_resource_to_bus
53 extern unsigned long phys_to_bus(unsigned long pa);
54 extern unsigned long pci_phys_to_bus(unsigned long pa, int busnr);
55 extern unsigned long pci_bus_to_phys(unsigned int ba, int busnr);
58 * Dynamic DMA Mapping stuff
59 * Originally stolen from i386 by ajoshi and updated by paulus
60 * Non-consistent cache support by Dan Malek
63 /* The PCI address space does equal the physical memory
64 * address space. The networking and block device layers use
65 * this boolean for bounce buffer decisions.
67 #define PCI_DMA_BUS_IS_PHYS (1)
69 /* Allocate and map kernel buffer using consistent mode DMA for a device.
70 * hwdev should be valid struct pci_dev pointer for PCI devices,
71 * NULL for PCI-like buses (ISA, EISA).
72 * Returns non-NULL cpu-view pointer to the buffer if successful and
73 * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
76 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
77 dma_addr_t *dma_handle);
79 /* Free and unmap a consistent DMA buffer.
80 * cpu_addr is what was returned from pci_alloc_consistent,
81 * size must be the same as what as passed into pci_alloc_consistent,
82 * and likewise dma_addr must be the same as what *dma_addrp was set to.
84 * References to the memory and mappings associated with cpu_addr/dma_addr
85 * past this call are illegal.
87 extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
88 void *vaddr, dma_addr_t dma_handle);
90 /* Map a single buffer of the indicated size for DMA in streaming mode.
91 * The 32-bit bus address to use is returned.
93 * Once the device is given the dma address, the device owns this memory
94 * until either pci_unmap_single or pci_dma_sync_single_for_cpu is performed.
96 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
97 size_t size, int direction)
99 BUG_ON(direction == PCI_DMA_NONE);
101 consistent_sync(ptr, size, direction);
103 return virt_to_bus(ptr);
106 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
107 size_t size, int direction)
109 BUG_ON(direction == PCI_DMA_NONE);
113 /* pci_unmap_{page,single} is a nop so... */
114 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
115 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
116 #define pci_unmap_addr(PTR, ADDR_NAME) (0)
117 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
118 #define pci_unmap_len(PTR, LEN_NAME) (0)
119 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
122 * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
123 * to pci_map_single, but takes a struct page instead of a virtual address
125 static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
126 unsigned long offset, size_t size,
129 BUG_ON(direction == PCI_DMA_NONE);
130 consistent_sync_page(page, offset, size, direction);
131 return (page - mem_map) * PAGE_SIZE + PCI_DRAM_OFFSET + offset;
134 static inline void pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
135 size_t size, int direction)
137 BUG_ON(direction == PCI_DMA_NONE);
141 /* Map a set of buffers described by scatterlist in streaming
142 * mode for DMA. This is the scather-gather version of the
143 * above pci_map_single interface. Here the scatter gather list
144 * elements are each tagged with the appropriate dma address
145 * and length. They are obtained via sg_dma_{address,length}(SG).
147 * NOTE: An implementation may be able to use a smaller number of
148 * DMA address/length pairs than there are SG table elements.
149 * (for example via virtual mapping capabilities)
150 * The routine returns the number of addr/length pairs actually
151 * used, at most nents.
153 * Device ownership issues as mentioned above for pci_map_single are
156 static inline int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
157 int nents, int direction)
161 BUG_ON(direction == PCI_DMA_NONE);
166 for (i = 0; i < nents; i++, sg++) {
168 consistent_sync_page(sg->page, sg->offset,
169 sg->length, direction);
170 sg->dma_address = page_to_bus(sg->page) + sg->offset;
176 /* Unmap a set of streaming mode DMA translations.
177 * Again, cpu read rules concerning calls here are the same as for
178 * pci_unmap_single() above.
180 static inline void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
181 int nents, int direction)
183 BUG_ON(direction == PCI_DMA_NONE);
187 /* Make physical memory consistent for a single
188 * streaming mode DMA translation after a transfer.
190 * If you perform a pci_map_single() but wish to interrogate the
191 * buffer using the cpu, yet do not wish to teardown the PCI dma
192 * mapping, you must call this function before doing so. At the
193 * next point you give the PCI dma address back to the card, you
194 * must first perform a pci_dma_sync_for_device, and then the device
195 * again owns the buffer.
197 static inline void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev,
198 dma_addr_t dma_handle,
199 size_t size, int direction)
201 BUG_ON(direction == PCI_DMA_NONE);
203 consistent_sync(bus_to_virt(dma_handle), size, direction);
206 static inline void pci_dma_sync_single_for_device(struct pci_dev *hwdev,
207 dma_addr_t dma_handle,
208 size_t size, int direction)
210 BUG_ON(direction == PCI_DMA_NONE);
212 consistent_sync(bus_to_virt(dma_handle), size, direction);
215 /* Make physical memory consistent for a set of streaming
216 * mode DMA translations after a transfer.
218 * The same as pci_dma_sync_single_for_* but for a scatter-gather list,
219 * same rules and usage.
221 static inline void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev,
222 struct scatterlist *sg,
223 int nelems, int direction)
227 BUG_ON(direction == PCI_DMA_NONE);
229 for (i = 0; i < nelems; i++, sg++)
230 consistent_sync_page(sg->page, sg->offset,
231 sg->length, direction);
234 static inline void pci_dma_sync_sg_for_device(struct pci_dev *hwdev,
235 struct scatterlist *sg,
236 int nelems, int direction)
240 BUG_ON(direction == PCI_DMA_NONE);
242 for (i = 0; i < nelems; i++, sg++)
243 consistent_sync_page(sg->page, sg->offset,
244 sg->length, direction);
247 /* Return whether the given PCI device DMA address mask can
248 * be supported properly. For example, if your device can
249 * only drive the low 24-bits during PCI bus mastering, then
250 * you would pass 0x00ffffff as the mask to this function.
252 static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
258 * At present there are very few 32-bit PPC machines that can have
259 * memory above the 4GB point, and we don't support that.
261 #define pci_dac_dma_supported(pci_dev, mask) (0)
263 static inline dma64_addr_t
264 pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
266 return (dma64_addr_t) page_to_bus(page) + offset;
269 static inline struct page *
270 pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
272 return mem_map + (unsigned long)(dma_addr >> PAGE_SHIFT);
275 static inline unsigned long
276 pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
278 return (dma_addr & ~PAGE_MASK);
282 pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
288 pci_dac_dma_sync_single_for_device(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
293 static inline int pci_dma_mapping_error(dma_addr_t dma_addr)
298 /* Return the index of the PCI controller for device PDEV. */
299 #define pci_domain_nr(bus) ((struct pci_controller *)(bus)->sysdata)->index
301 /* Set the name of the bus as it appears in /proc/bus/pci */
302 static inline int pci_name_bus(char *name, struct pci_bus *bus)
304 sprintf(name, "%02x", bus->number);
308 /* Map a range of PCI memory or I/O space for a device into user space */
309 int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
310 enum pci_mmap_state mmap_state, int write_combine);
312 /* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */
313 #define HAVE_PCI_MMAP 1
316 pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
317 struct resource *res);
319 extern void pcibios_add_platform_entries(struct pci_dev *dev);
321 #endif /* __KERNEL__ */
323 #endif /* __PPC_PCI_H */