blob: df41b7504e9d1141dd37802ee1393ff0694c4a05 [file] [log] [blame]
Chia-I Wuf9911eb2014-08-06 13:50:31 +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
Chia-I Wuf9911eb2014-08-06 13:50:31 +080025#include "dev.h"
26#include "mem.h"
27
28XGL_RESULT intel_mem_alloc(struct intel_dev *dev,
29 const XGL_MEMORY_ALLOC_INFO *info,
30 struct intel_mem **mem_ret)
31{
32 struct intel_mem *mem;
33
Courtney Goeltzenleuchter5975c1d2014-08-06 17:09:11 -060034 if ((info->alignment != 0) && (4096 % info->alignment))
Chia-I Wuf9911eb2014-08-06 13:50:31 +080035 return XGL_ERROR_INVALID_ALIGNMENT;
36 if (info->heapCount != 1 || info->heaps[0] != 0)
37 return XGL_ERROR_INVALID_POINTER;
38
Courtney Goeltzenleuchterfb4fb532014-08-14 09:35:21 -060039 mem = (struct intel_mem *) intel_base_create(dev, sizeof(*mem),
Chia-I Wubbf2c932014-08-07 12:20:08 +080040 dev->base.dbg, XGL_DBG_OBJECT_GPU_MEMORY, info, 0);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080041 if (!mem)
42 return XGL_ERROR_OUT_OF_MEMORY;
43
Chia-I Wuf9911eb2014-08-06 13:50:31 +080044 mem->bo = intel_winsys_alloc_buffer(dev->winsys,
45 "xgl-gpu-memory", info->allocationSize, 0);
46 if (!mem->bo) {
47 intel_mem_free(mem);
48 return XGL_ERROR_UNKNOWN;
49 }
50
Courtney Goeltzenleuchterc35ab462014-08-06 17:10:04 -060051 *mem_ret = mem;
52
Chia-I Wuf9911eb2014-08-06 13:50:31 +080053 return XGL_SUCCESS;
54}
55
56void intel_mem_free(struct intel_mem *mem)
57{
58 if (mem->bo)
59 intel_bo_unreference(mem->bo);
60
Chia-I Wubbf2c932014-08-07 12:20:08 +080061 intel_base_destroy(&mem->base);
Chia-I Wuf9911eb2014-08-06 13:50:31 +080062}
63
64XGL_RESULT intel_mem_set_priority(struct intel_mem *mem,
65 XGL_MEMORY_PRIORITY priority)
66{
67 /* pin the bo when XGL_MEMORY_PRIORITY_VERY_HIGH? */
68 return XGL_SUCCESS;
69}
70
Chia-I Wuf9911eb2014-08-06 13:50:31 +080071XGL_RESULT XGLAPI intelAllocMemory(
72 XGL_DEVICE device,
73 const XGL_MEMORY_ALLOC_INFO* pAllocInfo,
74 XGL_GPU_MEMORY* pMem)
75{
76 struct intel_dev *dev = intel_dev(device);
77
78 return intel_mem_alloc(dev, pAllocInfo, (struct intel_mem **) pMem);
79}
80
81XGL_RESULT XGLAPI intelFreeMemory(
82 XGL_GPU_MEMORY mem_)
83{
84 struct intel_mem *mem = intel_mem(mem_);
85
86 intel_mem_free(mem);
87
88 return XGL_SUCCESS;
89}
90
91XGL_RESULT XGLAPI intelSetMemoryPriority(
92 XGL_GPU_MEMORY mem_,
93 XGL_MEMORY_PRIORITY priority)
94{
95 struct intel_mem *mem = intel_mem(mem_);
96
97 return intel_mem_set_priority(mem, priority);
98}
99
100XGL_RESULT XGLAPI intelMapMemory(
101 XGL_GPU_MEMORY mem_,
102 XGL_FLAGS flags,
103 XGL_VOID** ppData)
104{
105 struct intel_mem *mem = intel_mem(mem_);
106 void *ptr = intel_mem_map(mem, flags);
107
108 *ppData = ptr;
109
110 return (ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN;
111}
112
113XGL_RESULT XGLAPI intelUnmapMemory(
114 XGL_GPU_MEMORY mem_)
115{
116 struct intel_mem *mem = intel_mem(mem_);
117
118 intel_mem_unmap(mem);
119
120 return XGL_SUCCESS;
121}