Chia-I Wu | 82f50aa | 2014-08-05 10:43:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include "dispatch_tables.h" |
| 26 | #include "gpu.h" |
| 27 | #include "obj.h" |
| 28 | |
| 29 | /** |
| 30 | * Return true if an (not so) arbitrary pointer casted to intel_base points to |
| 31 | * a valid intel_base. This assumes at least the first sizeof(void*) bytes of |
| 32 | * the address are accessible, and they does not happen to be our magic |
| 33 | * values. |
| 34 | */ |
| 35 | bool intel_base_is_valid(const struct intel_base *base) |
| 36 | { |
| 37 | if (base->dispatch != &intel_normal_dispatch_table && |
| 38 | base->dispatch != &intel_debug_dispatch_table) |
| 39 | return false; |
| 40 | |
| 41 | return !intel_gpu_is_valid((const struct intel_gpu *) base); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Initialize intel_base_dbg. It is assumed that the struct has already been |
| 46 | * zero initialized. |
| 47 | */ |
| 48 | bool intel_base_dbg_init(struct intel_base_dbg *dbg, |
| 49 | XGL_DBG_OBJECT_TYPE type, |
| 50 | const void *create_info, |
| 51 | XGL_SIZE create_info_size) |
| 52 | { |
| 53 | dbg->alloc_id = icd_get_allocator_id(); |
| 54 | dbg->type = type; |
| 55 | |
| 56 | if (create_info_size) { |
| 57 | dbg->create_info = |
| 58 | icd_alloc(create_info_size, 0, XGL_SYSTEM_ALLOC_DEBUG); |
| 59 | if (!dbg->create_info) |
| 60 | return false; |
| 61 | |
| 62 | memcpy(dbg->create_info, create_info, create_info_size); |
| 63 | } |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | void intel_base_dbg_cleanup(struct intel_base_dbg *dbg) |
| 69 | { |
| 70 | if (dbg->tag) |
| 71 | icd_free(dbg->tag); |
| 72 | |
| 73 | if (dbg->create_info) |
| 74 | icd_free(dbg->create_info); |
| 75 | } |
| 76 | |
| 77 | struct intel_base_dbg *intel_base_dbg_create(XGL_DBG_OBJECT_TYPE type, |
| 78 | const void *create_info, |
| 79 | XGL_SIZE create_info_size) |
| 80 | { |
| 81 | struct intel_base_dbg *dbg; |
| 82 | |
| 83 | dbg = icd_alloc(sizeof(*dbg), 0, XGL_SYSTEM_ALLOC_DEBUG); |
| 84 | if (!dbg) |
| 85 | return NULL; |
| 86 | |
| 87 | if (!intel_base_dbg_init(dbg, type, create_info, create_info_size)) { |
| 88 | icd_free(dbg); |
| 89 | return NULL; |
| 90 | } |
| 91 | |
| 92 | return dbg; |
| 93 | } |
| 94 | |
| 95 | void intel_base_dbg_destroy(struct intel_base_dbg *dbg) |
| 96 | { |
| 97 | intel_base_dbg_cleanup(dbg); |
| 98 | icd_free(dbg); |
| 99 | } |
Chia-I Wu | 53fc6aa | 2014-08-06 14:22:51 +0800 | [diff] [blame^] | 100 | |
| 101 | XGL_RESULT XGLAPI intelDestroyObject( |
| 102 | XGL_OBJECT object) |
| 103 | { |
| 104 | struct intel_obj *obj = intel_obj(object); |
| 105 | |
| 106 | obj->destroy(obj); |
| 107 | |
| 108 | return XGL_SUCCESS; |
| 109 | } |
| 110 | |
| 111 | XGL_RESULT XGLAPI intelGetObjectInfo( |
| 112 | XGL_BASE_OBJECT object, |
| 113 | XGL_OBJECT_INFO_TYPE infoType, |
| 114 | XGL_SIZE* pDataSize, |
| 115 | XGL_VOID* pData) |
| 116 | { |
| 117 | struct intel_base *base = intel_base(object); |
| 118 | XGL_RESULT ret = XGL_SUCCESS; |
| 119 | |
| 120 | switch (infoType) { |
| 121 | case XGL_INFO_TYPE_MEMORY_REQUIREMENTS: |
| 122 | /* |
| 123 | * Since most objects do not need a bo, we could use a callback so |
| 124 | * that we do not need to embed XGL_MEMORY_REQUIREMENTS. |
| 125 | */ |
| 126 | memcpy(pData, &base->mem_requirements, |
| 127 | sizeof(XGL_MEMORY_REQUIREMENTS)); |
| 128 | *pDataSize = sizeof(XGL_MEMORY_REQUIREMENTS); |
| 129 | break; |
| 130 | default: |
| 131 | ret = XGL_ERROR_INVALID_VALUE; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | XGL_RESULT XGLAPI intelBindObjectMemory( |
| 139 | XGL_OBJECT object, |
| 140 | XGL_GPU_MEMORY mem, |
| 141 | XGL_GPU_SIZE offset) |
| 142 | { |
| 143 | struct intel_obj *obj = intel_obj(object); |
| 144 | |
| 145 | obj->mem = mem; |
| 146 | obj->offset = offset; |
| 147 | |
| 148 | return XGL_SUCCESS; |
| 149 | } |