blob: 996543d15129479c1f93ef1b464b5fe18a248259 [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
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
95void intel_base_dbg_destroy(struct intel_base_dbg *dbg)
96{
97 intel_base_dbg_cleanup(dbg);
98 icd_free(dbg);
99}