blob: 8a8006fce6dc32c97eec638c8064a5e4f6c35f27 [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/**
65 * Initialize intel_base_dbg. It is assumed that the struct has already been
66 * zero initialized.
67 */
68bool intel_base_dbg_init(struct intel_base_dbg *dbg,
69 XGL_DBG_OBJECT_TYPE type,
70 const void *create_info,
71 XGL_SIZE create_info_size)
72{
73 dbg->alloc_id = icd_get_allocator_id();
74 dbg->type = type;
75
76 if (create_info_size) {
77 dbg->create_info =
78 icd_alloc(create_info_size, 0, XGL_SYSTEM_ALLOC_DEBUG);
79 if (!dbg->create_info)
80 return false;
81
82 memcpy(dbg->create_info, create_info, create_info_size);
83 }
84
85 return true;
86}
87
88void intel_base_dbg_cleanup(struct intel_base_dbg *dbg)
89{
90 if (dbg->tag)
91 icd_free(dbg->tag);
92
93 if (dbg->create_info)
94 icd_free(dbg->create_info);
95}
96
97struct intel_base_dbg *intel_base_dbg_create(XGL_DBG_OBJECT_TYPE type,
98 const void *create_info,
99 XGL_SIZE create_info_size)
100{
101 struct intel_base_dbg *dbg;
102
103 dbg = icd_alloc(sizeof(*dbg), 0, XGL_SYSTEM_ALLOC_DEBUG);
104 if (!dbg)
105 return NULL;
106
Courtney Goeltzenleuchterd6b3bac2014-08-06 17:10:36 -0600107 memset(dbg, 0, sizeof(*dbg));
Chia-I Wu82f50aa2014-08-05 10:43:03 +0800108 if (!intel_base_dbg_init(dbg, type, create_info, create_info_size)) {
109 icd_free(dbg);
110 return NULL;
111 }
112
113 return dbg;
114}
115
116void intel_base_dbg_destroy(struct intel_base_dbg *dbg)
117{
118 intel_base_dbg_cleanup(dbg);
119 icd_free(dbg);
120}
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800121
122XGL_RESULT XGLAPI intelDestroyObject(
123 XGL_OBJECT object)
124{
125 struct intel_obj *obj = intel_obj(object);
126
127 obj->destroy(obj);
128
129 return XGL_SUCCESS;
130}
131
132XGL_RESULT XGLAPI intelGetObjectInfo(
133 XGL_BASE_OBJECT object,
134 XGL_OBJECT_INFO_TYPE infoType,
135 XGL_SIZE* pDataSize,
136 XGL_VOID* pData)
137{
138 struct intel_base *base = intel_base(object);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800139
Chia-I Wu26f0bd02014-08-07 10:38:40 +0800140 return base->get_info(base, infoType, pDataSize, pData);
Chia-I Wu53fc6aa2014-08-06 14:22:51 +0800141}
142
143XGL_RESULT XGLAPI intelBindObjectMemory(
144 XGL_OBJECT object,
145 XGL_GPU_MEMORY mem,
146 XGL_GPU_SIZE offset)
147{
148 struct intel_obj *obj = intel_obj(object);
149
150 obj->mem = mem;
151 obj->offset = offset;
152
153 return XGL_SUCCESS;
154}