static int alloc_device_close(struct hw_device_t *device) { alloc_device_t* dev = reinterpret_cast<alloc_device_t*>(device); if (dev) { delete dev; ump_close(); // Our UMP memory refs will be released automatically here... } return 0; }
void platform_free_eglimage (EGLDisplay display, EGLContext context, GLuint tex_id, EGLImageKHR * image, gpointer * image_platform_data) { fbdev_pixmap *pixmap = *image_platform_data; eglDestroyImageKHR (display, *image); ump_reference_release ((ump_handle) pixmap->data); ump_close (); g_slice_free (fbdev_pixmap, *image_platform_data); }
static int alloc_device_close(struct hw_device_t *device) { alloc_device_t* dev = reinterpret_cast<alloc_device_t*>(device); if (dev) { #if GRALLOC_ARM_DMA_BUF_MODULE private_module_t *m = reinterpret_cast<private_module_t*>(device); if ( 0 != ion_close(m->ion_client) ) AERR( "Failed to close ion_client: %d", m->ion_client ); close(m->ion_client); #endif delete dev; #if GRALLOC_ARM_UMP_MODULE ump_close(); // Our UMP memory refs will be released automatically here... #endif } return 0; }
gboolean platform_alloc_eglimage (EGLDisplay display, EGLContext context, GLint format, GLint type, gint width, gint height, GLuint tex_id, EGLImageKHR * image, gpointer * image_platform_data) { fbdev_pixmap pixmap; pixmap.flags = FBDEV_PIXMAP_SUPPORTS_UMP; pixmap.width = width; pixmap.height = height; switch (format) { case GL_LUMINANCE: g_return_val_if_fail (type == GL_UNSIGNED_BYTE, FALSE); pixmap.red_size = 0; pixmap.green_size = 0; pixmap.blue_size = 0; pixmap.alpha_size = 0; pixmap.luminance_size = 8; break; case GL_LUMINANCE_ALPHA: g_return_val_if_fail (type == GL_UNSIGNED_BYTE, FALSE); pixmap.red_size = 0; pixmap.green_size = 0; pixmap.blue_size = 0; pixmap.alpha_size = 8; pixmap.luminance_size = 8; break; case GL_RGB: if (type == GL_UNSIGNED_BYTE) { pixmap.red_size = 8; pixmap.green_size = 8; pixmap.blue_size = 8; pixmap.alpha_size = 0; pixmap.luminance_size = 0; } else if (type == GL_UNSIGNED_SHORT_5_6_5) { pixmap.red_size = 5; pixmap.green_size = 6; pixmap.blue_size = 5; pixmap.alpha_size = 0; pixmap.luminance_size = 0; } else { g_return_val_if_reached (FALSE); } break; case GL_RGBA: g_return_val_if_fail (type == GL_UNSIGNED_BYTE, FALSE); pixmap.red_size = 8; pixmap.green_size = 8; pixmap.blue_size = 8; pixmap.alpha_size = 8; pixmap.luminance_size = 0; break; default: g_assert_not_reached (); return FALSE; } pixmap.buffer_size = pixmap.red_size + pixmap.green_size + pixmap.blue_size + pixmap.alpha_size + pixmap.luminance_size; pixmap.bytes_per_pixel = pixmap.buffer_size / 8; pixmap.format = 0; if (ump_open () != UMP_OK) { GST_ERROR ("Failed to open UMP"); return FALSE; } pixmap.data = ump_ref_drv_allocate (GST_ROUND_UP_4 (pixmap.width) * pixmap.height * pixmap.bytes_per_pixel, UMP_REF_DRV_CONSTRAINT_PHYSICALLY_LINEAR); if (pixmap.data == UMP_INVALID_MEMORY_HANDLE) { GST_ERROR ("Failed to allocate pixmap data via UMP"); ump_close (); return FALSE; } *image_platform_data = g_slice_dup (fbdev_pixmap, &pixmap); *image = eglCreateImageKHR (display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer) * image_platform_data, NULL); if (!image) { GST_ERROR ("Failed to create EGLImage for pixmap"); ump_reference_release ((ump_handle) pixmap.data); ump_close (); g_slice_free (fbdev_pixmap, *image_platform_data); return FALSE; } return TRUE; }
int main(int argc, char *argv[]) { int result = EXIT_FAILURE; if (UMP_OK == ump_open()) { const int SZ_4KB = 4096; const int alloc_size = 16 * SZ_4KB; const int resize_1 = 1 * SZ_4KB; const int resize_2 = -9 * SZ_4KB; #define NUM_ALLOCS 128 ump_handle h[NUM_ALLOCS]; int i; for (i = 0; i < NUM_ALLOCS; i++) { h[i] = UMP_INVALID_MEMORY_HANDLE; } for (i = 0; i < NUM_ALLOCS; i++) { u8 * p; h[i] = ump_allocate(alloc_size, UMP_PROT_CPU_RD | UMP_PROT_CPU_WR | UMP_HINT_CPU_RD | UMP_HINT_CPU_WR | UMP_PROT_W_RD | UMP_PROT_W_WR); if (UMP_INVALID_MEMORY_HANDLE == h[i]) { printf("Failed to allocate\n"); break; } p = ump_map(h[i], 0, alloc_size); if (NULL != p) { STDLIB_MEMSET(p, 0xFF, alloc_size); ump_cpu_msync_now(h[i], UMP_MSYNC_CLEAN, p, alloc_size); ump_unmap(h[i], p, alloc_size); } else { printf("Failed to map\n"); break; } } if (i == NUM_ALLOCS) { int resize_failure = 0; printf("%d allocations succeeded\n", NUM_ALLOCS); for (i = 0; i < NUM_ALLOCS; i++) { ump_secure_id check_id; check_id = ump_secure_id_get(h[i]); if (UMP_INVALID_SECURE_ID == check_id) { printf("Handle %d has an invalid secure id!\n", i); } else { int j; for (j = i + 1; j < NUM_ALLOCS; j++) { ump_secure_id id; id = ump_secure_id_get(h[j]); if (id == check_id) { printf("Duplicate IDs found for handles %d and %d, both have %u\n", i, j, id); } } } } printf("doing resize check\n"); for (i = 0; i < NUM_ALLOCS; i++) { u64 new_size; ump_resize_result res; res = ump_resize(h[i], resize_1, &new_size); if (UMP_RESIZE_OK != res) { printf("resize failed with error code 0x%08X\n", res); resize_failure++; } else { if (new_size != (alloc_size + resize_1)) { printf("Hmm, the new size isn't what I expected: %llu != %d\n", (unsigned long long)new_size, alloc_size + resize_1); resize_failure++; } else { int j; u8 * map; map = (u8*)ump_map(h[i], 0, new_size); if (NULL == map) { resize_failure++; /* record this as a resize failure */ break; } for (j = 0; j < alloc_size; j++) { if (map[j] != 0xFF) { printf("Expected 0xFF, have 0x%02X\n", map[j]); resize_failure++; } } for (j = alloc_size; j < new_size; j++) { if (map[j] != 0) { printf("Expected 0x00, have 0x%02X\n", map[j]); resize_failure++; } } ump_unmap(h[i], map, new_size); } res = ump_resize(h[i], resize_2, &new_size); if (UMP_RESIZE_OK != res) { printf("resize failed with error code 0x%08x\n", res); resize_failure++; } else { if (new_size != (alloc_size + resize_1 + resize_2)) { printf("Hmm, the new size isn't what I expected: %llu != %d\n", (unsigned long long)new_size, alloc_size + resize_1 + resize_2); resize_failure++; } else { int j; u8 * map; map = (u8*)ump_map(h[i], 0, new_size); if (NULL == map) { resize_failure++; break; } ump_cpu_msync_now(h[i], UMP_MSYNC_CLEAN_AND_INVALIDATE, map, new_size); for (j = 0; j < new_size; j++) { if (map[j] != 0xFF) { printf("expected 0xFF, have 0x%02X\n", map[j]); resize_failure++; } } ump_unmap(h[i], map, new_size); } } } } if (resize_failure) { printf("%d resize failures found\n", resize_failure); } else { printf("resize check OK\n"); result = EXIT_SUCCESS; } } for (i = 0; i < NUM_ALLOCS; i++) { ump_release(h[i]); } ump_close(); } return result; }