blob: 4a05f3d71438aa991c8e5582025ae3fe0bf9bb9c [file] [log] [blame]
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +01001/**************************************************************************
2 *
3 * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
Jakob Bornecrantz5dbc1b32010-01-05 20:55:02 +010029#include "config.h"
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010030#include <errno.h>
31#include <stdlib.h>
32#include <string.h>
33#include "internal.h"
34
35int kms_create(int fd, struct kms_driver **out)
36{
Jakob Bornecrantzd920fa92010-01-12 17:53:49 +000037 return linux_create(fd, out);
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010038}
39
40int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out)
41{
42 switch (key) {
Jakob Bornecrantz44a0e0a2010-01-23 01:41:49 +000043 case KMS_BO_TYPE:
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010044 break;
45 default:
46 return -EINVAL;
47 }
48 return kms->get_prop(kms, key, out);
49}
50
Jakob Bornecrantz201f5792009-12-04 16:06:42 +010051int kms_destroy(struct kms_driver **kms)
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010052{
Jakob Bornecrantz201f5792009-12-04 16:06:42 +010053 if (!(*kms))
54 return 0;
55
56 free(*kms);
57 *kms = NULL;
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010058 return 0;
59}
60
61int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out)
62{
63 unsigned width = 0;
64 unsigned height = 0;
Jakob Bornecrantz44a0e0a2010-01-23 01:41:49 +000065 enum kms_bo_type type = KMS_BO_TYPE_SCANOUT_X8R8G8B8;
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010066 int i;
67
68 for (i = 0; attr[i];) {
69 unsigned key = attr[i++];
70 unsigned value = attr[i++];
71
72 switch (key) {
73 case KMS_WIDTH:
74 width = value;
75 break;
76 case KMS_HEIGHT:
77 height = value;
78 break;
79 case KMS_BO_TYPE:
80 type = value;
81 break;
82 default:
83 return EINVAL;
84 }
85 }
86
87 if (width == 0 || height == 0)
88 return -EINVAL;
89
Jakob Bornecrantz44a0e0a2010-01-23 01:41:49 +000090 /* XXX sanity check type */
91
92 if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 &&
93 (width != 64 || height != 64))
94 return -EINVAL;
95
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +010096 return kms->bo_create(kms, width, height, type, attr, out);
97}
98
99int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out)
100{
101 switch (key) {
102 case KMS_PITCH:
103 *out = bo->pitch;
104 break;
105 case KMS_HANDLE:
106 *out = bo->handle;
107 break;
108 default:
109 return -EINVAL;
110 }
111
112 return 0;
113}
114
115int kms_bo_map(struct kms_bo *bo, void **out)
116{
117 return bo->kms->bo_map(bo, out);
118}
119
120int kms_bo_unmap(struct kms_bo *bo)
121{
122 return bo->kms->bo_unmap(bo);
123}
124
Jakob Bornecrantz201f5792009-12-04 16:06:42 +0100125int kms_bo_destroy(struct kms_bo **bo)
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +0100126{
Jakob Bornecrantz201f5792009-12-04 16:06:42 +0100127 int ret;
128
129 if (!(*bo))
130 return 0;
131
132 ret = (*bo)->kms->bo_destroy(*bo);
133 if (ret)
134 return ret;
135
136 *bo = NULL;
137 return 0;
Jakob Bornecrantz8c0571a2009-11-24 17:54:10 +0100138}