@@ -3106,4 +3106,73 @@ const struct vring *virtqueue_get_vring(const struct virtqueue *vq)
3106
3106
}
3107
3107
EXPORT_SYMBOL_GPL (virtqueue_get_vring );
3108
3108
3109
+ /**
3110
+ * virtqueue_dma_map_single_attrs - map DMA for _vq
3111
+ * @_vq: the struct virtqueue we're talking about.
3112
+ * @ptr: the pointer of the buffer to do dma
3113
+ * @size: the size of the buffer to do dma
3114
+ * @dir: DMA direction
3115
+ * @attrs: DMA Attrs
3116
+ *
3117
+ * The caller calls this to do dma mapping in advance. The DMA address can be
3118
+ * passed to this _vq when it is in pre-mapped mode.
3119
+ *
3120
+ * return DMA address. Caller should check that by virtqueue_dma_mapping_error().
3121
+ */
3122
+ dma_addr_t virtqueue_dma_map_single_attrs (struct virtqueue * _vq , void * ptr ,
3123
+ size_t size ,
3124
+ enum dma_data_direction dir ,
3125
+ unsigned long attrs )
3126
+ {
3127
+ struct vring_virtqueue * vq = to_vvq (_vq );
3128
+
3129
+ if (!vq -> use_dma_api )
3130
+ return (dma_addr_t )virt_to_phys (ptr );
3131
+
3132
+ return dma_map_single_attrs (vring_dma_dev (vq ), ptr , size , dir , attrs );
3133
+ }
3134
+ EXPORT_SYMBOL_GPL (virtqueue_dma_map_single_attrs );
3135
+
3136
+ /**
3137
+ * virtqueue_dma_unmap_single_attrs - unmap DMA for _vq
3138
+ * @_vq: the struct virtqueue we're talking about.
3139
+ * @addr: the dma address to unmap
3140
+ * @size: the size of the buffer
3141
+ * @dir: DMA direction
3142
+ * @attrs: DMA Attrs
3143
+ *
3144
+ * Unmap the address that is mapped by the virtqueue_dma_map_* APIs.
3145
+ *
3146
+ */
3147
+ void virtqueue_dma_unmap_single_attrs (struct virtqueue * _vq , dma_addr_t addr ,
3148
+ size_t size , enum dma_data_direction dir ,
3149
+ unsigned long attrs )
3150
+ {
3151
+ struct vring_virtqueue * vq = to_vvq (_vq );
3152
+
3153
+ if (!vq -> use_dma_api )
3154
+ return ;
3155
+
3156
+ dma_unmap_single_attrs (vring_dma_dev (vq ), addr , size , dir , attrs );
3157
+ }
3158
+ EXPORT_SYMBOL_GPL (virtqueue_dma_unmap_single_attrs );
3159
+
3160
+ /**
3161
+ * virtqueue_dma_mapping_error - check dma address
3162
+ * @_vq: the struct virtqueue we're talking about.
3163
+ * @addr: DMA address
3164
+ *
3165
+ * Returns 0 means dma valid. Other means invalid dma address.
3166
+ */
3167
+ int virtqueue_dma_mapping_error (struct virtqueue * _vq , dma_addr_t addr )
3168
+ {
3169
+ struct vring_virtqueue * vq = to_vvq (_vq );
3170
+
3171
+ if (!vq -> use_dma_api )
3172
+ return 0 ;
3173
+
3174
+ return dma_mapping_error (vring_dma_dev (vq ), addr );
3175
+ }
3176
+ EXPORT_SYMBOL_GPL (virtqueue_dma_mapping_error );
3177
+
3109
3178
MODULE_LICENSE ("GPL" );
0 commit comments