blob: 65b18348b84227c6f566cbbd6e6c1d7958bb7074 [file] [log] [blame]
Chia-I Wu82f50aa2014-08-05 10:43:03 +08001/*
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 */
35bool 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 */
48bool 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
68void 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
77struct 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
Courtney Goeltzenleuchterd6b3bac2014-08-06 17:10:36 -060087 memset(dbg, 0, sizeof(*dbg));
Chia-I Wu82f50aa2014-08-05 10:43:03 +080088 if (!intel_base_dbg_init(dbg, type, create_info, create_info_size)) {
89 icd_free(dbg);
90 return NULL;
91 }
92
93 return dbg;
94}
95
96void intel_base_dbg_destroy(struct intel_base_dbg *dbg)
97{
98 intel_base_dbg_cleanup(dbg);
99 icd_free(dbg);
100}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800101
102XGL_RESULT XGLAPI intelDestroyObject(
103 XGL_OBJECT object)
104{
105 struct intel_obj *obj = intel_obj(object);
106
107 obj->destroy(obj);
108
109 return XGL_SUCCESS;
110}
111
112XGL_RESULT XGLAPI intelGetObjectInfo(
113 XGL_BASE_OBJECT object,
114 XGL_OBJECT_INFO_TYPE infoType,
115 XGL_SIZE* pDataSize,
116 XGL_VOID* pData)
117{
118 struct intel_base *base = intel_base(object);
119 XGL_RESULT ret = XGL_SUCCESS;
120
121 switch (infoType) {
122 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
123 /*
124 * Since most objects do not need a bo, we could use a callback so
125 * that we do not need to embed XGL_MEMORY_REQUIREMENTS.
126 */
127 memcpy(pData, &base->mem_requirements,
128 sizeof(XGL_MEMORY_REQUIREMENTS));
129 *pDataSize = sizeof(XGL_MEMORY_REQUIREMENTS);
130 break;
131 default:
132 ret = XGL_ERROR_INVALID_VALUE;
133 break;
134 }
135
136 return ret;
137}
138
139XGL_RESULT XGLAPI intelBindObjectMemory(
140 XGL_OBJECT object,
141 XGL_GPU_MEMORY mem,
142 XGL_GPU_SIZE offset)
143{
144 struct intel_obj *obj = intel_obj(object);
145
146 obj->mem = mem;
147 obj->offset = offset;
148
149 return XGL_SUCCESS;
150}