1c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/* Copyright (c) Imagination Technologies Ltd. 2c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 3c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * The contents of this file are subject to the MIT license as set out below. 4c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 5c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Permission is hereby granted, free of charge, to any person obtaining a copy 6c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * of this software and associated documentation files (the "Software"), to deal 7c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * in the Software without restriction, including without limitation the rights 8c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * copies of the Software, and to permit persons to whom the Software is 10c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * furnished to do so, subject to the following conditions: 11c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 12c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * The above copyright notice and this permission notice shall be included in 13c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * all copies or substantial portions of the Software. 14c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 15c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * THE SOFTWARE. 22c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 23c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 24c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#ifndef HAL_PUBLIC_H 25c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define HAL_PUBLIC_H 26c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 27c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/* Authors of third party hardware composer (HWC) modules will need to include 28c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * this header to access functionality in the gralloc and framebuffer HALs. 29c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 30c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 31c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <hardware/gralloc.h> 32c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 33c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) 34c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define HW_ALIGN 32 35c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 36c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/* This can be tuned down as appropriate for the SOC. 37c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 38c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * IMG formats are usually a single sub-alloc. 39c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Some OEM video formats are two sub-allocs (Y, UV planes). 40c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Future OEM video formats might be three sub-allocs (Y, U, V planes). 41c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 42c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define MAX_SUB_ALLOCS 3 43c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 44c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct 45c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 46c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev native_handle_t base; 47c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 48c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* These fields can be sent cross process. They are also valid 49c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * to duplicate within the same process. 50c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 51c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * A table is stored within psPrivateData on gralloc_module_t (this 52c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * is obviously per-process) which maps stamps to a mapped 53c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock 54c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * count associated with it, satisfying the requirements of the 55c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Android API. This also prevents us from leaking maps/allocations. 56c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 57c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * This table has entries inserted either by alloc() 58c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * (alloc_device_t) or map() (gralloc_module_t). Entries are removed 59c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * by free() (alloc_device_t) and unmap() (gralloc_module_t). 60c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 61c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * As a special case for framebuffer_device_t, framebuffer_open() 62c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * will add and framebuffer_close() will remove from this table. 63c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 64c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 65c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define IMG_NATIVE_HANDLE_NUMFDS MAX_SUB_ALLOCS 66c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* The `fd' field is used to "export" a meminfo to another process. 67c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Therefore, it is allocated by alloc_device_t, and consumed by 68c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * gralloc_module_t. The framebuffer_device_t does not need a handle, 69c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * and the special value IMG_FRAMEBUFFER_FD is used instead. 70c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 71c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int fd[MAX_SUB_ALLOCS]; 72c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 73c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(unsigned long long) / sizeof(int)) + 5) 74c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* A KERNEL unique identifier for any exported kernel meminfo. Each 75c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * exported kernel meminfo will have a unique stamp, but note that in 76c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * userspace, several meminfos across multiple processes could have 77c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * the same stamp. As the native_handle can be dup(2)'d, there could be 78c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * multiple handles with the same stamp but different file descriptors. 79c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 80c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev unsigned long long ui64Stamp; 81c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 82c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* This is used for buffer usage validation when locking a buffer, 83c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * and also in WSEGL (for the composition bypass feature). 84c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 85c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int usage; 86c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 87c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* In order to do efficient cache flushes we need the buffer dimensions 88c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * and format. These are available on the ANativeWindowBuffer, 89c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * but the platform doesn't pass them down to the graphics HAL. 90c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * 91c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * These fields are also used in the composition bypass. In this 92c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * capacity, these are the "real" values for the backing allocation. 93c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 94c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int iWidth; 95c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int iHeight; 96c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int iFormat; 97c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev unsigned int uiBpp; 98c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 99c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev__attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; 100c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 101c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct 102c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 103c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev framebuffer_device_t base; 104c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 105c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* The HWC was loaded. post() is no longer responsible for presents */ 106c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int bBypassPost; 107c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 108c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* HWC path for present posts */ 109c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int (*Post2)(framebuffer_device_t *fb, buffer_handle_t *buffers, 110c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int num_buffers, void *data, int data_length); 111c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 112c322989ae6ff6769490828de1b5eda12b749cce9Iliyan MalchevIMG_framebuffer_device_public_t; 113c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 114c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct IMG_gralloc_module_public_t 115c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 116c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev gralloc_module_t base; 117c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 118c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* If the framebuffer has been opened, this will point to the 119c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * framebuffer device data required by the allocator, WSEGL 120c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * modules and composerhal. 121c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */ 122c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev IMG_framebuffer_device_public_t *psFrameBufferDevice; 123c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 124c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int (*GetPhyAddrs)(struct IMG_gralloc_module_public_t const* module, 125c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev buffer_handle_t handle, 126c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev unsigned int auiPhyAddr[MAX_SUB_ALLOCS]); 1278c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling 1288c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling /* Custom-blit components in lieu of overlay hardware */ 1298c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling int (*Blit)(struct IMG_gralloc_module_public_t const *module, 1308c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling buffer_handle_t src, 1318c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling void *dest[MAX_SUB_ALLOCS], int format); 1328c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling 1338c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling int (*Blit2)(struct IMG_gralloc_module_public_t const *module, 1348c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling buffer_handle_t src, buffer_handle_t dest, 1358c7ffe560fa2ef015d7fd06d06806d582835de09Erik Gilling int w, int h, int x, int y); 136c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 137c322989ae6ff6769490828de1b5eda12b749cce9Iliyan MalchevIMG_gralloc_module_public_t; 138c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 139c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct 140c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 141c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int l, t, w, h; 142c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 143c322989ae6ff6769490828de1b5eda12b749cce9Iliyan MalchevIMG_write_lock_rect_t; 144c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 145c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevtypedef struct IMG_buffer_format_public_t 146c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{ 147c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Buffer formats are returned as a linked list */ 148c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev struct IMG_buffer_format_public_t *psNext; 149c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 150c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* HAL_PIXEL_FORMAT_... enumerant */ 151c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int iHalPixelFormat; 152c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 153c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* WSEGL_PIXELFORMAT_... enumerant */ 154c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int iWSEGLPixelFormat; 155c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 156c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Friendly name for format */ 157c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev const char *const szName; 158c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 159c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* Bits (not bytes) per pixel */ 160c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev unsigned int uiBpp; 161c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 162c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev /* GPU output format (creates EGLConfig for format) */ 163c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev int bGPURenderable; 164c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev} 165c322989ae6ff6769490828de1b5eda12b749cce9Iliyan MalchevIMG_buffer_format_public_t; 166c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev 167d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse/* 168d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse * These are vendor specific pixel formats, by (informal) convention IMGTec 169d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse * formats start from the top of the range, TI formats start from the bottom 170d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse */ 171d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse#define HAL_PIXEL_FORMAT_BGRX_8888 0x1FF 172d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse#define HAL_PIXEL_FORMAT_TI_NV12 0x100 173dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse#define HAL_PIXEL_FORMAT_TI_UNUSED 0x101 /* Free for use */ 174dfc644c88eeac97a2dd0feb5967e746fa64dd1c6Tony Lofthouse#define HAL_PIXEL_FORMAT_TI_NV12_1D 0x102 175d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse 17690b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#ifndef GRALLOC_USAGE_SYSTEM_HEAP 17790b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#define GRALLOC_USAGE_SYSTEM_HEAP GRALLOC_USAGE_PRIVATE_0 17890b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#else 17990b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#error GRALLOC_USAGE_SYSTEM_HEAP should only be defined by hal_public.h 18090b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#endif 18190b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse 18290b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#ifndef GRALLOC_USAGE_PHYS_CONTIG 18390b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#define GRALLOC_USAGE_PHYS_CONTIG GRALLOC_USAGE_PRIVATE_1 18490b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#else 18590b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#error GRALLOC_USAGE_PHYS_CONTIG should only be defined by hal_public.h 18690b0b5624e863d01c6a6bdc736546745db6a4c8fTony Lofthouse#endif 187c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#endif /* HAL_PUBLIC_H */ 188d5de2f43e7464783fd3168408a904c3ab646d652Tony Lofthouse 189