Files @ 95e39e5412bd
Branch filter:

Location: vmkdrivers/BLD/build/HEADERS/92-vmkdrivers-asm-x64/vmkernel64/release/asm/dma-mapping.h

unknown
ESXi-6.0-GA
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
 * Portions Copyright 2008 VMware, Inc.
 */
#ifndef _X8664_DMA_MAPPING_H
#define _X8664_DMA_MAPPING_H 1

/*
 * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
 * documentation.
 */


#include <asm/scatterlist.h>
#include <asm/io.h>
#include <asm/swiotlb.h>

struct dma_mapping_ops {
	int             (*mapping_error)(dma_addr_t dma_addr);
	void*           (*alloc_coherent)(struct device *dev, size_t size,
                                dma_addr_t *dma_handle, gfp_t gfp);
	void            (*free_coherent)(struct device *dev, size_t size,
                                void *vaddr, dma_addr_t dma_handle);
	dma_addr_t      (*map_single)(struct device *hwdev, void *ptr,
                                size_t size, int direction);
	/* like map_single, but doesn't check the device mask */
	dma_addr_t      (*map_simple)(struct device *hwdev, char *ptr,
                                size_t size, int direction);
	void            (*unmap_single)(struct device *dev, dma_addr_t addr,
		                size_t size, int direction);
	void            (*sync_single_for_cpu)(struct device *hwdev,
		                dma_addr_t dma_handle, size_t size,
				int direction);
	void            (*sync_single_for_device)(struct device *hwdev,
                                dma_addr_t dma_handle, size_t size,
				int direction);
	void            (*sync_single_range_for_cpu)(struct device *hwdev,
                                dma_addr_t dma_handle, unsigned long offset,
		                size_t size, int direction);
	void            (*sync_single_range_for_device)(struct device *hwdev,
				dma_addr_t dma_handle, unsigned long offset,
		                size_t size, int direction);
	void            (*sync_sg_for_cpu)(struct device *hwdev,
                                struct scatterlist *sg, int nelems,
				int direction);
	void            (*sync_sg_for_device)(struct device *hwdev,
				struct scatterlist *sg, int nelems,
				int direction);
	int             (*map_sg)(struct device *hwdev, struct scatterlist *sg,
		                int nents, int direction);
	void            (*unmap_sg)(struct device *hwdev,
				struct scatterlist *sg, int nents,
				int direction);
	int             (*dma_supported)(struct device *hwdev, u64 mask);
	int		is_phys;
};

extern dma_addr_t bad_dma_address;
extern struct dma_mapping_ops* dma_ops;
extern int iommu_merge;

static inline int valid_dma_direction(int dma_direction)
{
	return ((dma_direction == DMA_BIDIRECTIONAL) ||
		(dma_direction == DMA_TO_DEVICE) ||
		(dma_direction == DMA_FROM_DEVICE));
}

extern void *dma_alloc_coherent(struct device *dev, size_t size,
				dma_addr_t *dma_handle, gfp_t gfp);
extern void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
			      dma_addr_t dma_handle);



#if defined(__VMKLNX__)

/*
 * DMA mapping functions on vmklinux are not inlined so as to 
 * support further revision and improvements for the behavior of
 * of stable third-party binary drivers using these functions.
 */

extern int dma_mapping_error(dma_addr_t dma_addr);

#define dma_unmap_page(dev,dma_address,size,dir) \
	dma_unmap_single(dev,dma_address,size,dir)

extern dma_addr_t
dma_map_single(struct device *hwdev, void *ptr, size_t size,
	       int direction);

extern dma_addr_t
dma_map_page(struct device *hwdev, struct page *page, unsigned long offset,
             size_t size, int direction);

extern void
dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
		 int direction);
extern void
dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
			size_t size, int direction);
extern void
dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
			   size_t size, int direction);
extern void
dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
			      unsigned long offset, size_t size, int direction);
extern void
dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
				 unsigned long offset, size_t size, int direction);
extern void
dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
		    int nelems, int direction);
extern void
dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
		       int nelems, int direction);
extern int
dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction);
extern void
dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
	     int direction);

struct vmklnx_codma;
extern struct vmklnx_codma vmklnx_codma;
extern int vmklnx_dma_supported(struct vmklnx_codma *codma,
                                struct device *hwdev, u64 mask);

static inline int dma_supported(struct device *hwdev, u64 mask)
{
        return vmklnx_dma_supported(&vmklnx_codma, hwdev, mask);
}

#else /* !defined(__VMKLNX__) */

/**                                          
 *  dma_mapping_error - Check a bus address for a mapping error       
 *  @dma_addr: bus address previously returned by dma_map_single or dma_map_page
 *                                           
 *  Performs a platform-specific check to determine if the
 *  mapped bus address is valid for use with DMA
 *                                           
 *  RETURN VALUE:
 *  TRUE if the bus address incurred a mapping error, FALSE otherwise
 *
 *  SEE ALSO:
 *  dma_map_single
 *                                           
 */                                          
static inline int dma_mapping_error(dma_addr_t dma_addr)
{
	if (dma_ops->mapping_error)
		return dma_ops->mapping_error(dma_addr);

	return (dma_addr == bad_dma_address);
}

/**                                          
 *  dma_map_single - Map a buffer for streaming DMA use with a given device       
 *  @hwdev: device to be used in the DMA operation    
 *  @ptr: virtual address of the buffer
 *  @size: length of the buffer, in bytes
 *  @direction: direction of the DMA to set up
 *                                           
 *  Sets up any platform-specific bus connectivity required to
 *  make a buffer usable for a DMA operation and returns a mapped bus address
 *  for the buffer.  The mapped address should be checked for an error using 
 *  dma_mapping_error.  When the buffer will no longer be used for DMA, the 
 *  buffer should be unmapped using dma_unmap_single.
 *  'direction' can be any one of
 *  DMA_BIDIRECTIONAL (the device either reads or writes the buffer),
 *  DMA_TO_DEVICE (the device reads the buffer), 
 *  DMA_FROM_DEVICE (the device writes the buffer), or
 *  DMA_NONE (neither reads nor writes should be allowed - may not be supported
 *  on all platforms)
 *
 *  RETURN VALUE:
 *  A bus address accessible by the device
 *
 *  SEE ALSO:
 *  dma_unmap_single, dma_mapping_error
 *                                           
 */                                          
static inline dma_addr_t
dma_map_single(struct device *hwdev, void *ptr, size_t size,
	       int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	return dma_ops->map_single(hwdev, ptr, size, direction);
}

#define dma_map_page(dev,page,offset,size,dir) \
	dma_map_single((dev), page_address(page)+(offset), (size), (dir))

#define dma_unmap_page dma_unmap_single

/**                                          
 *  dma_unmap_single - Tear down a streaming DMA mapping for a buffer       
 *  @dev: device that had been used in the DMA operation     
 *  @addr: mapped bus address for the buffer, previously returned by dma_map_single
 *  @size: length of the buffer, in bytes
 *  @direction: direction of the DMA that was set up by dma_map_single
 *                                           
 *  Tears down the platform-specific bus connectivity that was needed to make a 
 *  buffer usable for DMA.  
 *  'direction' can be any one of
 *  DMA_BIDIRECTIONAL (the device either reads or writes the buffer),
 *  DMA_TO_DEVICE (the device reads the buffer), 
 *  DMA_FROM_DEVICE (the device writes the buffer), or
 *  DMA_NONE (neither reads nor writes should be allowed)
 *
 *  RETURN VALUE:
 *  Does not return any value
 *                                           
 *  SEE ALSO:
 *  dma_map_single
 *                                           
 */                                          
static inline void
dma_unmap_single(struct device *dev, dma_addr_t addr,size_t size,
		 int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	dma_ops->unmap_single(dev, addr, size, direction);
}

/**                                          
 *  dma_sync_single_for_cpu - Allow the CPU to access a buffer that is currently DMA-mapped      
 *  @hwdev: device to which the buffer is mapped    
 *  @dma_handle: bus address of the buffer
 *  @size: length of the buffer, in bytes
 *  @direction: direction of the existing DMA mapping
 *
 *  Transfers access ownership for a buffer that has been set up for DMA back to
 *  the CPU and synchronizes any changes that have been made by the device with
 *  the CPU.  The bus mapping that was created with dma_map_single is not 
 *  destroyed.  Afterward, the CPU can safely read and write the buffer.  The
 *  device should not access the buffer until access rights have been 
 *  transferred back to the device using dma_sync_single_for_device.
 *
 *  RETURN VALUE:
 *  Does not return any value
 *
 *  SEE ALSO:
 *  dma_sync_single_for_device, dma_map_single
 *                                           
 */                                          
static inline void
dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
			size_t size, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	if (dma_ops->sync_single_for_cpu)
		dma_ops->sync_single_for_cpu(hwdev, dma_handle, size,
					     direction);
	flush_write_buffers();
}

/**                                          
 *  dma_sync_single_for_device - Re-enable device access to a DMA-mapped buffer     
 *  @hwdev: device to which the buffer is mapped    
 *  @dma_handle: bus address of the buffer
 *  @size: length of the buffer, in bytes
 *  @direction: direction of the existing DMA mapping
 *                                           
 *  Transfers access ownership back to a device from the CPU and synchronizes 
 *  any changes that the CPU has made so that they will be visible by the device.
 *
 *  RETURN VALUE:
 *  Does not return any value
 *
 *  SEE ALSO:
 *  dma_sync_single_for_cpu, dma_map_single
 *                                           
 */                                          
static inline void
dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
			   size_t size, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	if (dma_ops->sync_single_for_device)
		dma_ops->sync_single_for_device(hwdev, dma_handle, size,
						direction);
	flush_write_buffers();
}

static inline void
dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
			      unsigned long offset, size_t size, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	if (dma_ops->sync_single_range_for_cpu) {
		dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, size, direction);
	}

	flush_write_buffers();
}

static inline void
dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
				 unsigned long offset, size_t size, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	if (dma_ops->sync_single_range_for_device)
		dma_ops->sync_single_range_for_device(hwdev, dma_handle,
						      offset, size, direction);

	flush_write_buffers();
}

static inline void
dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
		    int nelems, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	if (dma_ops->sync_sg_for_cpu)
		dma_ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
	flush_write_buffers();
}

static inline void
dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
		       int nelems, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	if (dma_ops->sync_sg_for_device) {
		dma_ops->sync_sg_for_device(hwdev, sg, nelems, direction);
	}

	flush_write_buffers();
}

/**                                          
 *  dma_map_sg - Map scatter/gather buffers for DMA use with a hardware device  
 *  @hwdev: device to be used in the DMA operations    
 *  @sg: start of the scatter/gather list of entries to be mapped
 *  @nents: number of elements in the list to be mapped
 *  @direction: direction of the DMA, with values as in dma_map_single
 *                                           
 *  Sets up the platform-specific bus connectivity for each of the buffers in a 
 *  scatterlist so that they may be used in DMA with the given hardware device.
 *  dma_unmap_sg should be used on these scatterlist elements when they will no
 *  longer be used with DMA.
 *                                           
 *  RETURN VALUE:
 *  0 if a failure was encountered, nents if the mappings succeeded
 *
 *  SEE ALSO:
 *  dma_map_single, dma_unmap_sg
 *                                           
 */                                          
static inline int
dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	return dma_ops->map_sg(hwdev, sg, nents, direction);
}

/**                                          
 *  dma_unmap_sg - Unmap scatter/gather buffers that were previously mapped for DMA
 *  @hwdev: device to which these buffers have been mapped    
 *  @sg: start of the scatter/gather list of entries to be unmapped
 *  @nents: number of elements in the list to be unmapped
 *  @direction: direction of the existing DMA mapping
 *                                           
 *  Tears down the platform-specific bus connectivity for each of the buffers in 
 *  a scatterlist that had been previously set up for DMA using
 *  dma_map_sg.
 *
 *  RETURN VALUE:
 *  Does not return any value
 *
 *  SEE ALSO:
 *  dma_map_sg, dma_map_single  
 *
 */                                          
static inline void
dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
	     int direction)
{
	BUG_ON(!valid_dma_direction(direction));
	/* take out this ifdef block when we have iommu support */
	dma_ops->unmap_sg(hwdev, sg, nents, direction);
}

extern int dma_supported(struct device *hwdev, u64 mask);

#endif /* !defined(__VMKLNX__) */

/* same for gart, swiotlb, and nommu */
static inline int dma_get_cache_alignment(void)
{
	return boot_cpu_data.x86_clflush_size;
}

#define dma_is_consistent(h) 1

extern int dma_set_mask(struct device *dev, u64 mask);

static inline void
dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction dir)
{
	flush_write_buffers();
}

extern struct device fallback_dev;
extern int panic_on_overflow;

#endif /* _X8664_DMA_MAPPING_H */