Monday, December 26, 2016

ION Allocator, Revisited

4 years ago I wrote a LWN paper on ION Allocator.
I'm surprised to see ION still is changing, after 4 years of in staging.

Here's the latest ION interface in ion.h, but Laura is mainly proposing to adjust ION API so that it relies on the kernel's DMA abstraction layer, the DMA mapping API, to handle DMA cache synchronization and MMU mapping, by updating mainly ion_map_dma_buf() in  ion.c file, so that clients does not have to peek into ION objects to manage DMA operations.

It seems the new way would be to call dma_map_sg() directly using the ION object (or the dma_buf object associated with the ION object).

In comparison, the old way is shown in the call flow below.




1090 static struct dma_buf_ops dma_buf_ops = {
1091         .map_dma_buf = ion_map_dma_buf,
878 static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment,
879                                         enum dma_data_direction direction)
75 /**
 76  * ion_client_create() -  allocate a client and returns it
 77  * @dev:                the global ion device
 78  * @name:               used for debugging
 79  */
 80 struct ion_client *ion_client_create(struct ion_device *dev,
 81                                      const char *name);
 82 
 83 /**
 84  * ion_client_destroy() -  free's a client and all it's handles
 85  * @client:     the client
 86  *
 87  * Free the provided client and all it's resources including
 88  * any handles it is holding.
 89  */
 90 void ion_client_destroy(struct ion_client *client);
 91 
 92 /**
 93  * ion_alloc - allocate ion memory
 94  * @client:             the client
 95  * @len:                size of the allocation
 96  * @align:              requested allocation alignment, lots of hardware blocks
 97  *                      have alignment requirements of some kind
 98  * @heap_id_mask:       mask of heaps to allocate from, if multiple bits are set
 99  *                      heaps will be tried in order from highest to lowest
100  *                      id
101  * @flags:              heap flags, the low 16 bits are consumed by ion, the
102  *                      high 16 bits are passed on to the respective heap and
103  *                      can be heap custom
104  *
105  * Allocate memory in one of the heaps provided in heap mask and return
106  * an opaque handle to it.
107  */
108 struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
109                              size_t align, unsigned int heap_id_mask,
110                              unsigned int flags);
111 
112 /**
113  * ion_free - free a handle
114  * @client:     the client
115  * @handle:     the handle to free
116  *
117  * Free the provided handle.
118  */
119 void ion_free(struct ion_client *client, struct ion_handle *handle);
120 
121 /**
122  * ion_map_kernel - create mapping for the given handle
123  * @client:     the client
124  * @handle:     handle to map
125  *
126  * Map the given handle into the kernel and return a kernel address that
127  * can be used to access this address.
128  */
129 void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle);
130 
131 /**
132  * ion_unmap_kernel() - destroy a kernel mapping for a handle
133  * @client:     the client
134  * @handle:     handle to unmap
135  */
136 void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
137 
138 /**
139  * ion_share_dma_buf() - share buffer as dma-buf
140  * @client:     the client
141  * @handle:     the handle
142  */
143 struct dma_buf *ion_share_dma_buf(struct ion_client *client,
144                                                 struct ion_handle *handle);
145 
146 /**
147  * ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd
148  * @client:     the client
149  * @handle:     the handle
150  */
151 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
152 
153 /**
154  * ion_import_dma_buf() - get ion_handle from dma-buf
155  * @client:     the client
156  * @dmabuf:     the dma-buf
157  *
158  * Get the ion_buffer associated with the dma-buf and return the ion_handle.
159  * If no ion_handle exists for this buffer, return newly created ion_handle.
160  * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
161  */
162 struct ion_handle *ion_import_dma_buf(struct ion_client *client,
163                                       struct dma_buf *dmabuf);
164 
165 /**
166  * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get handle
167  * @client:     the client
168  * @fd:         the dma-buf fd
169  *
170  * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
171  * import that fd and return a handle representing it. If a dma-buf from
172  * another exporter is passed in this function will return ERR_PTR(-EINVAL)
173  */
174 struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd);
175 
176 #endif /* _LINUX_ION_H */

No comments:

Post a Comment