1 |
1276 |
phoenix |
#ifndef ASMARM_PCI_H
|
2 |
|
|
#define ASMARM_PCI_H
|
3 |
|
|
|
4 |
|
|
#ifdef __KERNEL__
|
5 |
|
|
|
6 |
|
|
#include <linux/mm.h>
|
7 |
|
|
#include <asm/arch/hardware.h>
|
8 |
|
|
#include <asm/scatterlist.h>
|
9 |
|
|
#include <asm/io.h>
|
10 |
|
|
|
11 |
|
|
/*
|
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.
|
15 |
|
|
*/
|
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);
|
22 |
|
|
|
23 |
|
|
#ifdef CONFIG_SA1111
|
24 |
|
|
|
25 |
|
|
#define SA1111_FAKE_PCIDEV ((struct pci_dev *) 1111)
|
26 |
|
|
|
27 |
|
|
static inline int dev_is_sa1111(const struct pci_dev *dev)
|
28 |
|
|
{
|
29 |
|
|
return (dev == SA1111_FAKE_PCIDEV);
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
#else
|
33 |
|
|
|
34 |
|
|
static inline int dev_is_sa1111(const struct pci_dev *dev) { return 0; }
|
35 |
|
|
|
36 |
|
|
#endif
|
37 |
|
|
|
38 |
|
|
/*
|
39 |
|
|
* The PCI address space does equal the physical memory address space.
|
40 |
|
|
* The networking and block device layers use this boolean for bounce
|
41 |
|
|
* buffer decisions.
|
42 |
|
|
*/
|
43 |
|
|
#define PCI_DMA_BUS_IS_PHYS (0)
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
static inline void pcibios_set_master(struct pci_dev *dev)
|
47 |
|
|
{
|
48 |
|
|
/* No special bus mastering setup handling */
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
static inline void pcibios_penalize_isa_irq(int irq)
|
52 |
|
|
{
|
53 |
|
|
/* We don't do dynamic PCI IRQ allocation */
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
#define pcibios_scan_all_fns() 0
|
57 |
|
|
|
58 |
|
|
struct pci_dev;
|
59 |
|
|
|
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
|
65 |
|
|
* is undefined.
|
66 |
|
|
*/
|
67 |
|
|
extern void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *handle);
|
68 |
|
|
|
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.
|
73 |
|
|
*
|
74 |
|
|
* References to the memory and mappings associated with cpu_addr/dma_addr
|
75 |
|
|
* past this call are illegal.
|
76 |
|
|
*/
|
77 |
|
|
static inline void
|
78 |
|
|
pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr,
|
79 |
|
|
dma_addr_t dma_handle)
|
80 |
|
|
{
|
81 |
|
|
consistent_free(vaddr, size, dma_handle);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
/* Map a single buffer of the indicated size for DMA in streaming mode.
|
85 |
|
|
* The 32-bit bus address to use is returned.
|
86 |
|
|
*
|
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.
|
89 |
|
|
*/
|
90 |
|
|
static inline dma_addr_t
|
91 |
|
|
pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
|
92 |
|
|
{
|
93 |
|
|
if (dev_is_sa1111(hwdev))
|
94 |
|
|
return sa1111_map_single(ptr, size, direction);
|
95 |
|
|
|
96 |
|
|
consistent_sync(ptr, size, direction);
|
97 |
|
|
return virt_to_bus(ptr);
|
98 |
|
|
}
|
99 |
|
|
|
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.
|
103 |
|
|
*
|
104 |
|
|
* After this call, reads by the cpu to the buffer are guarenteed to see
|
105 |
|
|
* whatever the device wrote there.
|
106 |
|
|
*/
|
107 |
|
|
static inline void
|
108 |
|
|
pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr, size_t size, int direction)
|
109 |
|
|
{
|
110 |
|
|
if (dev_is_sa1111(hwdev))
|
111 |
|
|
sa1111_unmap_single(dma_addr, size, direction);
|
112 |
|
|
|
113 |
|
|
/* nothing to do */
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
/* Whether pci_unmap_{single,page} is a nop depends upon the
|
117 |
|
|
* configuration.
|
118 |
|
|
*/
|
119 |
|
|
#ifdef CONFIG_SA1111
|
120 |
|
|
#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
|
121 |
|
|
dma_addr_t ADDR_NAME;
|
122 |
|
|
#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
|
123 |
|
|
__u32 LEN_NAME;
|
124 |
|
|
#define pci_unmap_addr(PTR, ADDR_NAME) \
|
125 |
|
|
((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) \
|
129 |
|
|
((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 */
|
140 |
|
|
|
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).
|
146 |
|
|
*
|
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.
|
152 |
|
|
*
|
153 |
|
|
* Device ownership issues as mentioned above for pci_map_single are
|
154 |
|
|
* the same here.
|
155 |
|
|
*/
|
156 |
|
|
static inline int
|
157 |
|
|
pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
|
158 |
|
|
{
|
159 |
|
|
int i;
|
160 |
|
|
|
161 |
|
|
if (dev_is_sa1111(hwdev))
|
162 |
|
|
return sa1111_map_sg(sg, nents, direction);
|
163 |
|
|
|
164 |
|
|
for (i = 0; i < nents; i++, sg++) {
|
165 |
|
|
char *vaddr = sg->address;
|
166 |
|
|
|
167 |
|
|
if (!vaddr)
|
168 |
|
|
vaddr = ((char *)page_address(sg->page)) + sg->offset;
|
169 |
|
|
|
170 |
|
|
consistent_sync(vaddr, sg->length, direction);
|
171 |
|
|
sg->dma_address = virt_to_bus(vaddr);
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
return nents;
|
175 |
|
|
}
|
176 |
|
|
|
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.
|
180 |
|
|
*/
|
181 |
|
|
static inline void
|
182 |
|
|
pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nents, int direction)
|
183 |
|
|
{
|
184 |
|
|
if (dev_is_sa1111(hwdev)) {
|
185 |
|
|
sa1111_unmap_sg(sg, nents, direction);
|
186 |
|
|
return;
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
/* nothing to do */
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/* Make physical memory consistent for a single
|
193 |
|
|
* streaming mode DMA translation after a transfer.
|
194 |
|
|
*
|
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.
|
200 |
|
|
*/
|
201 |
|
|
static inline void
|
202 |
|
|
pci_dma_sync_single(struct pci_dev *hwdev, dma_addr_t dma_handle, size_t size, int direction)
|
203 |
|
|
{
|
204 |
|
|
if (dev_is_sa1111(hwdev)) {
|
205 |
|
|
sa1111_dma_sync_single(dma_handle, size, direction);
|
206 |
|
|
return;
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
consistent_sync(bus_to_virt(dma_handle), size, direction);
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
/* Make physical memory consistent for a set of streaming
|
213 |
|
|
* mode DMA translations after a transfer.
|
214 |
|
|
*
|
215 |
|
|
* The same as pci_dma_sync_single but for a scatter-gather list,
|
216 |
|
|
* same rules and usage.
|
217 |
|
|
*/
|
218 |
|
|
static inline void
|
219 |
|
|
pci_dma_sync_sg(struct pci_dev *hwdev, struct scatterlist *sg, int nelems, int direction)
|
220 |
|
|
{
|
221 |
|
|
int i;
|
222 |
|
|
|
223 |
|
|
if (dev_is_sa1111(hwdev)) {
|
224 |
|
|
sa1111_dma_sync_sg(sg, nelems, direction);
|
225 |
|
|
return;
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
for (i = 0; i < nelems; i++, sg++)
|
229 |
|
|
consistent_sync(sg->address, sg->length, direction);
|
230 |
|
|
}
|
231 |
|
|
|
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.
|
236 |
|
|
*/
|
237 |
|
|
static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
|
238 |
|
|
{
|
239 |
|
|
return 1;
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
/* This isn't fine. */
|
243 |
|
|
#define pci_dac_dma_supported(pci_dev, mask) (0)
|
244 |
|
|
|
245 |
|
|
/* Return the index of the PCI controller for device PDEV. */
|
246 |
|
|
#define pci_controller_num(PDEV) (0)
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
#if defined(CONFIG_SA1111) && !defined(CONFIG_PCI)
|
250 |
|
|
/* SA-1111 needs these prototypes even when !defined(CONFIG_PCI) */
|
251 |
|
|
|
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);
|
256 |
|
|
|
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);
|
259 |
|
|
#endif
|
260 |
|
|
|
261 |
|
|
#endif /* __KERNEL__ */
|
262 |
|
|
|
263 |
|
|
#endif
|