7 #include <asm/arch/hardware.h>
8 #include <asm/scatterlist.h>
12 * For SA-1111 these functions are "magic" and utilize bounce
13 * buffers as need to workaround SA-1111 DMA bugs. They are called in
14 * place of their pci_* counterparts when dev_is_sa1111() returns true.
16 dma_addr_t sa1111_map_single(void *, size_t, int);
17 void sa1111_unmap_single(dma_addr_t, size_t, int);
18 int sa1111_map_sg(struct scatterlist *, int, int);
19 void sa1111_unmap_sg(struct scatterlist *, int, int);
20 void sa1111_dma_sync_single(dma_addr_t, size_t, int);
21 void sa1111_dma_sync_sg(struct scatterlist *, int, int);
25 #define SA1111_FAKE_PCIDEV ((struct pci_dev *) 1111)
27 static inline int dev_is_sa1111(const struct pci_dev *dev)
29 return (dev == SA1111_FAKE_PCIDEV);
34 static inline int dev_is_sa1111(const struct pci_dev *dev) { return 0; }
39 * The PCI address space does equal the physical memory address space.
40 * The networking and block device layers use this boolean for bounce
43 #define PCI_DMA_BUS_IS_PHYS (0)
46 static inline void pcibios_set_master(struct pci_dev *dev)
48 /* No special bus mastering setup handling */
51 static inline void pcibios_penalize_isa_irq(int irq)
53 /* We don't do dynamic PCI IRQ allocation */
56 #define pcibios_scan_all_fns() 0
60 /* Allocate and map kernel buffer using consistent mode DMA for a device.
61 * hwdev should be valid struct pci_dev pointer for PCI devices,
62 * NULL for PCI-like buses (ISA, EISA).
63 * Returns non-NULL cpu-view pointer to the buffer if successful and
64 * sets *dma_addrp to the pci side dma address as well, else *dma_addrp
67 extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *handle);
69 /* Free and unmap a consistent DMA buffer.
70 * cpu_addr is what was returned from pci_alloc_consistent,
71 * size must be the same as what as passed into pci_alloc_consistent,
72 * and likewise dma_addr must be the same as what *dma_addrp was set to.
74 * References to the memory and mappings associated with cpu_addr/dma_addr
75 * past this call are illegal.
78 pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr,
79 dma_addr_t dma_handle)
81 consistent_free(vaddr, size, dma_handle);
84 /* Map a single buffer of the indicated size for DMA in streaming mode.
85 * The 32-bit bus address to use is returned.
87 * Once the device is given the dma address, the device owns this memory
88 * until either pci_unmap_single or pci_dma_sync_single is performed.
90 static inline dma_addr_t
91 pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
93 if (dev_is_sa1111(hwdev))
94 return sa1111_map_single(ptr, size, direction);
96 consistent_sync(ptr, size, direction);
97 return virt_to_bus(ptr);
100 /* Unmap a single streaming mode DMA translation. The dma_addr and size
101 * must match what was provided for in a previous pci_map_single call. All
102 * other usages are undefined.
104 * After this call, reads by the cpu to the buffer are guarenteed to see
105 * whatever the device wrote there.
108 pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction)
110 if (dev_is_sa1111(hwdev))
111 sa1111_unmap_single(dma_addr, size, direction);
116 /* Whether pci_unmap_{single,page} is a nop depends upon the
120 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
121 dma_addr_t ADDR_NAME;
122 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
124 #define pci_unmap_addr(PTR, ADDR_NAME) \
126 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
127 (((PTR)->ADDR_NAME) = (VAL))
128 #define pci_unmap_len(PTR, LEN_NAME) \
130 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
131 (((PTR)->LEN_NAME) = (VAL))
132 #else /* !(CONFIG_SA1111) */
133 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
134 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
135 #define pci_unmap_addr(PTR, ADDR_NAME) (0)
136 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
137 #define pci_unmap_len(PTR, LEN_NAME) (0)
138 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
139 #endif /* CONFIG_SA1111 */
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
157 pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
161 if (dev_is_sa1111(hwdev))
162 return sa1111_map_sg(sg, nents, direction);
164 for (i = 0; i < nents; i++, sg++) {
165 char *vaddr = sg->address;
168 vaddr = ((char *)page_address(sg->page)) + sg->offset;
170 consistent_sync(vaddr, sg->length, direction);
171 sg->dma_address = virt_to_bus(vaddr);
177 /* Unmap a set of streaming mode DMA translations.
178 * Again, cpu read rules concerning calls here are the same as for
179 * pci_unmap_single() above.
182 pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
184 if (dev_is_sa1111(hwdev)) {
185 sa1111_unmap_sg(sg, nents, direction);
192 /* Make physical memory consistent for a single
193 * streaming mode DMA translation after a transfer.
195 * If you perform a pci_map_single() but wish to interrogate the
196 * buffer using the cpu, yet do not wish to teardown the PCI dma
197 * mapping, you must call this function before doing so. At the
198 * next point you give the PCI dma address back to the card, the
199 * device again owns the buffer.
202 pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction)
204 if (dev_is_sa1111(hwdev)) {
205 sa1111_dma_sync_single(dma_handle, size, direction);
209 consistent_sync(bus_to_virt(dma_handle), size, direction);
212 /* Make physical memory consistent for a set of streaming
213 * mode DMA translations after a transfer.
215 * The same as pci_dma_sync_single but for a scatter-gather list,
216 * same rules and usage.
219 pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction)
223 if (dev_is_sa1111(hwdev)) {
224 sa1111_dma_sync_sg(sg, nelems, direction);
228 for (i = 0; i < nelems; i++, sg++)
229 consistent_sync(sg->address, sg->length, direction);
232 /* Return whether the given PCI device DMA address mask can
233 * be supported properly. For example, if your device can
234 * only drive the low 24-bits during PCI bus mastering, then
235 * you would pass 0x00ffffff as the mask to this function.
237 static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
242 /* This isn't fine. */
243 #define pci_dac_dma_supported(pci_dev, mask) (0)
245 /* Return the index of the PCI controller for device PDEV. */
246 #define pci_controller_num(PDEV) (0)
249 #if defined(CONFIG_SA1111) && !defined(CONFIG_PCI)
250 /* SA-1111 needs these prototypes even when !defined(CONFIG_PCI) */
252 /* kmem_cache style wrapper around pci_alloc_consistent() */
253 struct pci_pool *pci_pool_create (const char *name, struct pci_dev *dev,
254 size_t size, size_t align, size_t allocation, int flags);
255 void pci_pool_destroy (struct pci_pool *pool);
257 void *pci_pool_alloc (struct pci_pool *pool, int flags, dma_addr_t *handle);
258 void pci_pool_free (struct pci_pool *pool, void *vaddr, dma_addr_t addr);
261 #endif /* __KERNEL__ */