blob: 2ea35f4fab283f6b36d903a47d562f2e61919150 [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
Chia-I Wu26f0bd02014-08-07 10:38:40 +080044XGL_RESULT intel_base_get_info(struct intel_base *base, int type,
45 XGL_SIZE *size, XGL_VOID *data)
46{
47 XGL_RESULT ret = XGL_SUCCESS;
48 XGL_SIZE s;
49
50 switch (type) {
51 case XGL_INFO_TYPE_MEMORY_REQUIREMENTS:
52 s = sizeof(XGL_MEMORY_REQUIREMENTS);
53 memset(data, 0, s);
54 *size = s;
55 break;
56 default:
57 ret = XGL_ERROR_INVALID_VALUE;
58 break;
59 }
60
61 return ret;
62}
63
Chia-I Wu82f50aa2014-08-05 10:43:03 +080064/**
Chia-I Wu660caf82014-08-07 10:54:26 +080065 * Create an intel_base_dbg. When alloc_size is non-zero, a buffer of that
66 * size is allocated and zeroed.
Chia-I Wu82f50aa2014-08-05 10:43:03 +080067 */
Chia-I Wu660caf82014-08-07 10:54:26 +080068struct intel_base_dbg *intel_base_dbg_create(XGL_DBG_OBJECT_TYPE type,
69 const void *create_info,
70 XGL_SIZE create_info_size,
71 XGL_SIZE alloc_size)
Chia-I Wu82f50aa2014-08-05 10:43:03 +080072{
Chia-I Wu660caf82014-08-07 10:54:26 +080073 struct intel_base_dbg *dbg;
74
75 if (alloc_size)
76 alloc_size = sizeof(*dbg);
77
78 assert(alloc_size >= sizeof(*dbg));
79
80 dbg = icd_alloc(alloc_size, 0, XGL_SYSTEM_ALLOC_DEBUG);
81 if (!dbg)
82 return NULL;
83
84 memset(dbg, 0, alloc_size);
85
Chia-I Wu82f50aa2014-08-05 10:43:03 +080086 dbg->alloc_id = icd_get_allocator_id();
87 dbg->type = type;
88
89 if (create_info_size) {
90 dbg->create_info =
91 icd_alloc(create_info_size, 0, XGL_SYSTEM_ALLOC_DEBUG);
Chia-I Wu660caf82014-08-07 10:54:26 +080092 if (!dbg->create_info) {
93 icd_free(dbg);
94 return NULL;
95 }
Chia-I Wu82f50aa2014-08-05 10:43:03 +080096
97 memcpy(dbg->create_info, create_info, create_info_size);
98 }
99
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800100 return dbg;
101}
102
103void intel_base_dbg_destroy(struct intel_base_dbg *dbg)
104{
Chia-I Wu660caf82014-08-07 10:54:26 +0800105 if (dbg->tag)
106 icd_free(dbg->tag);
107
108 if (dbg->create_info)
109 icd_free(dbg->create_info);
110
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800111 icd_free(dbg);
112}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800113
114XGL_RESULT XGLAPI intelDestroyObject(
115 XGL_OBJECT object)
116{
117 struct intel_obj *obj = intel_obj(object);
118
119 obj->destroy(obj);
120
121 return XGL_SUCCESS;
122}
123
124XGL_RESULT XGLAPI intelGetObjectInfo(
125 XGL_BASE_OBJECT object,
126 XGL_OBJECT_INFO_TYPE infoType,
127 XGL_SIZE* pDataSize,
128 XGL_VOID* pData)
129{
130 struct intel_base *base = intel_base(object);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800131
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800132 return base->get_info(base, infoType, pDataSize, pData);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800133}
134
135XGL_RESULT XGLAPI intelBindObjectMemory(
136 XGL_OBJECT object,
137 XGL_GPU_MEMORY mem,
138 XGL_GPU_SIZE offset)
139{
140 struct intel_obj *obj = intel_obj(object);
141
142 obj->mem = mem;
143 obj->offset = offset;
144
145 return XGL_SUCCESS;
146}