4 #include <linux/config.h>
9 extern dma_addr_t bad_dma_address;
11 /* Can be used to override the logic in pci_scan_bus for skipping
12 already-configured bus numbers - to be used for buggy BIOSes
13 or architectures with incomplete PCI setup by the loader */
16 extern unsigned int pcibios_assign_all_busses(void);
18 #define pcibios_assign_all_busses() 0
20 #define pcibios_scan_all_fns() 0
22 extern unsigned long pci_mem_start;
23 #define PCIBIOS_MIN_IO 0x1000
24 #define PCIBIOS_MIN_MEM (pci_mem_start)
26 void pcibios_config_init(void);
27 struct pci_bus * pcibios_scan_root(int bus);
28 extern int (*pci_config_read)(int seg, int bus, int dev, int fn, int reg, int len, u32 *value);
29 extern int (*pci_config_write)(int seg, int bus, int dev, int fn, int reg, int len, u32 value);
31 void pcibios_set_master(struct pci_dev *dev);
32 void pcibios_penalize_isa_irq(int irq);
33 struct irq_routing_table *pcibios_get_irq_routing_table(void);
34 int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
36 #include <linux/types.h>
37 #include <linux/slab.h>
38 #include <asm/scatterlist.h>
39 #include <linux/string.h>
42 #include <asm/mmzone.h>
47 /* Allocate and map kernel buffer using consistent mode DMA for a device.
48 * hwdev should be valid struct pci_dev pointer for PCI devices,
49 * NULL for PCI-like buses (ISA, EISA).
50 * Returns non-NULL cpu-view pointer to the buffer if successful and
51 * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
54 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
55 dma_addr_t *dma_handle);
57 /* Free and unmap a consistent DMA buffer.
58 * cpu_addr is what was returned from pci_alloc_consistent,
59 * size must be the same as what as passed into pci_alloc_consistent,
60 * and likewise dma_addr must be the same as what *dma_addrp was set to.
62 * References to the memory and mappings associated with cpu_addr/dma_addr
63 * past this call are illegal.
65 extern void pci_free_consistent(struct pci_dev *hwdev, size_t size,
66 void *vaddr, dma_addr_t dma_handle);
71 extern dma_addr_t swiotlb_map_single (struct pci_dev *hwdev, void *ptr, size_t size,
73 extern void swiotlb_unmap_single (struct pci_dev *hwdev, dma_addr_t dev_addr,
74 size_t size, int dir);
75 extern void swiotlb_sync_single (struct pci_dev *hwdev, dma_addr_t dev_addr,
76 size_t size, int dir);
77 extern void swiotlb_sync_sg (struct pci_dev *hwdev, struct scatterlist *sg, int nelems,
81 #ifdef CONFIG_GART_IOMMU
83 /* Map a single buffer of the indicated size for DMA in streaming mode.
84 * The 32-bit bus address to use is returned.
86 * Once the device is given the dma address, the device owns this memory
87 * until either pci_unmap_single or pci_dma_sync_single is performed.
89 extern dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
90 size_t size, int direction);
93 void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t addr,
94 size_t size, int direction);
97 * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
98 * to pci_map_single, but takes a struct page instead of a virtual address
101 #define pci_map_page(dev,page,offset,size,dir) \
102 pci_map_single((dev), page_address(page)+(offset), (size), (dir))
104 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
105 dma_addr_t ADDR_NAME;
106 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
108 #define pci_unmap_addr(PTR, ADDR_NAME) \
110 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
111 (((PTR)->ADDR_NAME) = (VAL))
112 #define pci_unmap_len(PTR, LEN_NAME) \
114 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
115 (((PTR)->LEN_NAME) = (VAL))
117 static inline void pci_dma_sync_single(struct pci_dev *hwdev,
118 dma_addr_t dma_handle,
119 size_t size, int direction)
121 #ifdef CONFIG_SWIOTLB
123 return swiotlb_sync_single(hwdev,dma_handle,size,direction);
125 BUG_ON(direction == PCI_DMA_NONE);
128 static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
129 struct scatterlist *sg,
130 int nelems, int direction)
132 BUG_ON(direction == PCI_DMA_NONE);
133 #ifdef CONFIG_SWIOTLB
135 return swiotlb_sync_sg(hwdev,sg,nelems,direction);
139 /* The PCI address space does equal the physical memory
140 * address space. The networking and block device layers use
141 * this boolean for bounce buffer decisions.
143 #define PCI_DMA_BUS_IS_PHYS (0)
147 static inline dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr,
148 size_t size, int direction)
152 if (direction == PCI_DMA_NONE)
154 addr = virt_to_bus(ptr);
157 * This is gross, but what should I do.
158 * Unfortunately drivers do not test the return value of this.
160 if ((addr+size) & ~hwdev->dma_mask)
165 static inline void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
166 size_t size, int direction)
168 if (direction == PCI_DMA_NONE)
173 static inline dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
174 unsigned long offset, size_t size, int direction)
177 if (direction == PCI_DMA_NONE)
179 addr = page_to_pfn(page) * PAGE_SIZE + offset;
180 if ((addr+size) & ~hwdev->dma_mask)
185 /* pci_unmap_{page,single} is a nop so... */
186 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
187 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
188 #define pci_unmap_addr(PTR, ADDR_NAME) (0)
189 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
190 #define pci_unmap_len(PTR, LEN_NAME) (0)
191 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
193 /* Make physical memory consistent for a single
194 * streaming mode DMA translation after a transfer.
196 * If you perform a pci_map_single() but wish to interrogate the
197 * buffer using the cpu, yet do not wish to teardown the PCI dma
198 * mapping, you must call this function before doing so. At the
199 * next point you give the PCI dma address back to the card, the
200 * device again owns the buffer.
202 static inline void pci_dma_sync_single(struct pci_dev *hwdev,
203 dma_addr_t dma_handle,
204 size_t size, int direction)
206 if (direction == PCI_DMA_NONE)
208 flush_write_buffers();
211 /* Make physical memory consistent for a set of streaming
212 * mode DMA translations after a transfer.
214 * The same as pci_dma_sync_single but for a scatter-gather list,
215 * same rules and usage.
217 static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
218 struct scatterlist *sg,
219 int nelems, int direction)
221 if (direction == PCI_DMA_NONE)
223 flush_write_buffers();
226 #define PCI_DMA_BUS_IS_PHYS 1
230 extern int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
231 int nents, int direction);
232 extern void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
233 int nents, int direction);
235 #define pci_unmap_page pci_unmap_single
237 /* Return whether the given PCI device DMA address mask can
238 * be supported properly. For example, if your device can
239 * only drive the low 24-bits during PCI bus mastering, then
240 * you would pass 0x00ffffff as the mask to this function.
242 static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
245 * we fall back to GFP_DMA when the mask isn't all 1s,
246 * so we can't guarantee allocations that must be
247 * within a tighter range than GFP_DMA..
249 if(mask < 0x00ffffff)
255 /* This is always fine. */
256 #define pci_dac_dma_supported(pci_dev, mask) (1)
258 static __inline__ dma64_addr_t
259 pci_dac_page_to_dma(struct pci_dev *pdev, struct page *page, unsigned long offset, int direction)
261 return ((dma64_addr_t) page_to_bus(page) +
262 (dma64_addr_t) offset);
265 static __inline__ struct page *
266 pci_dac_dma_to_page(struct pci_dev *pdev, dma64_addr_t dma_addr)
268 return pfn_to_page(phys_to_pfn(dma_addr));
271 static __inline__ unsigned long
272 pci_dac_dma_to_offset(struct pci_dev *pdev, dma64_addr_t dma_addr)
274 return (dma_addr & ~PAGE_MASK);
277 static __inline__ void
278 pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len, int direction)
280 flush_write_buffers();
283 /* These macros should be used after a pci_map_sg call has been done
284 * to get bus addresses of each of the SG entries and their lengths.
285 * You should only work with the number of sg entries pci_map_sg
288 #define sg_dma_address(sg) ((sg)->dma_address)
289 #define sg_dma_len(sg) ((sg)->length)
291 /* Return the index of the PCI controller for device. */
292 static inline int pci_controller_num(struct pci_dev *dev)
297 #define HAVE_PCI_MMAP
298 extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
299 enum pci_mmap_state mmap_state, int write_combine);
301 #endif /* __KERNEL__ */
303 #endif /* __x8664_PCI_H */