Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/omap: add OMAP_BO flags to affect buffer allocation

On SoCs with DMM/TILER, we have two ways to allocate buffers: normal
dma_alloc or via DMM (which basically functions as an IOMMU). DMM can
map 128MB at a time, and we only map the DMM buffers when they are used
(i.e. not at alloc time). If DMM is present, omapdrm always uses DMM.

There are use cases that require lots of big buffers that are being used
at the same time by different IPs. At the moment the userspace has a
hard maximum of 128MB.

This patch adds three new flags that can be used by the userspace to
solve the situation:

OMAP_BO_MEM_CONTIG: The driver will use dma_alloc to get the memory.
This can be used to avoid DMM if the userspace knows it needs more than
128M of memory at the same time.

OMAP_BO_MEM_DMM: The driver will use DMM to get the memory. There's not
much use for this flag at the moment, as on platforms with DMM it is
used by default, but it's here for completeness.

OMAP_BO_MEM_PIN: The driver will pin the memory at alloc time, and keep
it pinned. This can be used to 1) get an error at alloc time if DMM
space is full, and 2) get rid of the constant pin/unpin operations which
may have some effect on performance.

If none of the flags are given, the behavior is the same as currently.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Reviewed-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191010120000.1421-9-jjhiblot@ti.com

+61 -2
+52 -2
drivers/gpu/drm/omapdrm/omap_gem.c
··· 1097 1097 list_del(&omap_obj->mm_list); 1098 1098 mutex_unlock(&priv->list_lock); 1099 1099 1100 + if (omap_obj->flags & OMAP_BO_MEM_PIN) 1101 + omap_gem_unpin_locked(obj); 1102 + 1100 1103 /* 1101 1104 * We own the sole reference to the object at this point, but to keep 1102 1105 * lockdep happy, we must still take the omap_obj_lock to call ··· 1150 1147 return false; 1151 1148 } 1152 1149 1150 + if ((flags & OMAP_BO_MEM_CONTIG) && (flags & OMAP_BO_MEM_DMM)) 1151 + return false; 1152 + 1153 + if ((flags & OMAP_BO_MEM_DMM) && !priv->usergart) 1154 + return false; 1155 + 1153 1156 if (flags & OMAP_BO_TILED_MASK) { 1154 1157 if (!priv->usergart) 1158 + return false; 1159 + 1160 + if (flags & OMAP_BO_MEM_CONTIG) 1155 1161 return false; 1156 1162 1157 1163 switch (flags & OMAP_BO_TILED_MASK) { ··· 1177 1165 return true; 1178 1166 } 1179 1167 1180 - /* GEM buffer object constructor */ 1168 + /** 1169 + * omap_gem_new() - Create a new GEM buffer 1170 + * @dev: The DRM device 1171 + * @gsize: The requested size for the GEM buffer. If the buffer is tiled 1172 + * (2D buffer), the size is a pair of values: height and width 1173 + * expressed in pixels. If the buffers is not tiled, it is expressed 1174 + * in bytes. 1175 + * @flags: Flags give additionnal information about the allocation: 1176 + * OMAP_BO_TILED_x: use the TILER (2D buffers). The TILER container 1177 + * unit can be 8, 16 or 32 bits. Cache is always disabled for 1178 + * tiled buffers. 1179 + * OMAP_BO_SCANOUT: Scannout buffer, consummable by the DSS 1180 + * OMAP_BO_CACHED: Buffer CPU caching mode: cached 1181 + * OMAP_BO_WC: Buffer CPU caching mode: write-combined 1182 + * OMAP_BO_UNCACHED: Buffer CPU caching mode: uncached 1183 + * OMAP_BO_MEM_CONTIG: The driver will use dma_alloc to get the memory. 1184 + * This can be used to avoid DMM if the userspace knows it needs 1185 + * more than 128M of memory at the same time. 1186 + * OMAP_BO_MEM_DMM: The driver will use DMM to get the memory. There's 1187 + * not much use for this flag at the moment, as on platforms with 1188 + * DMM it is used by default, but it's here for completeness. 1189 + * OMAP_BO_MEM_PIN: The driver will pin the memory at alloc time, and 1190 + * keep it pinned. This can be used to 1) get an error at alloc 1191 + * time if DMM space is full, and 2) get rid of the constant 1192 + * pin/unpin operations which may have some effect on performance. 1193 + * 1194 + * Return: The GEM buffer or NULL if the allocation failed 1195 + */ 1181 1196 struct drm_gem_object *omap_gem_new(struct drm_device *dev, 1182 1197 union omap_gem_size gsize, u32 flags) 1183 1198 { ··· 1232 1193 */ 1233 1194 flags &= ~(OMAP_BO_CACHED|OMAP_BO_WC|OMAP_BO_UNCACHED); 1234 1195 flags |= tiler_get_cpu_cache_flags(); 1235 - } else if ((flags & OMAP_BO_SCANOUT) && !priv->has_dmm) { 1196 + } else if ((flags & OMAP_BO_MEM_CONTIG) || 1197 + ((flags & OMAP_BO_SCANOUT) && !priv->has_dmm)) { 1236 1198 /* 1237 1199 * If we don't have DMM, we must allocate scanout buffers 1238 1200 * from contiguous DMA memory. ··· 1293 1253 goto err_release; 1294 1254 } 1295 1255 1256 + if (flags & OMAP_BO_MEM_PIN) { 1257 + ret = omap_gem_pin(obj, NULL); 1258 + if (ret) 1259 + goto err_free_dma; 1260 + } 1261 + 1296 1262 mutex_lock(&priv->list_lock); 1297 1263 list_add(&omap_obj->mm_list, &priv->obj_list); 1298 1264 mutex_unlock(&priv->list_lock); 1299 1265 1300 1266 return obj; 1301 1267 1268 + err_free_dma: 1269 + if (flags & OMAP_BO_MEM_DMA_API) 1270 + dma_free_wc(dev->dev, size, omap_obj->vaddr, 1271 + omap_obj->dma_addr); 1302 1272 err_release: 1303 1273 drm_gem_object_release(obj); 1304 1274 err_free:
+9
include/uapi/drm/omap_drm.h
··· 47 47 #define OMAP_BO_UNCACHED 0x00000004 48 48 #define OMAP_BO_CACHE_MASK 0x00000006 49 49 50 + /* Force allocation from contiguous DMA memory */ 51 + #define OMAP_BO_MEM_CONTIG 0x00000008 52 + 53 + /* Force allocation via DMM */ 54 + #define OMAP_BO_MEM_DMM 0x00000010 55 + 56 + /* Pin the buffer when allocating and keep pinned */ 57 + #define OMAP_BO_MEM_PIN 0x00000020 58 + 50 59 /* Use TILER for the buffer. The TILER container unit can be 8, 16 or 32 bits. */ 51 60 #define OMAP_BO_TILED_8 0x00000100 52 61 #define OMAP_BO_TILED_16 0x00000200