r600g: delete old path
[mesa.git] / src / gallium / winsys / r600 / drm / r600_drm.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 * Corbin Simpson <MostAwesomeDude@gmail.com>
26 * Joakim Sindholt <opensource@zhasha.com>
27 */
28 #include <stdio.h>
29 #include <errno.h>
30 #include <sys/ioctl.h>
31 #include "util/u_inlines.h"
32 #include "util/u_debug.h"
33 #include <pipebuffer/pb_bufmgr.h>
34 #include "radeon_priv.h"
35 #include "r600_drm_public.h"
36 #include "xf86drm.h"
37 #include "radeon_drm.h"
38
39 static int radeon_get_device(struct radeon *radeon)
40 {
41 struct drm_radeon_info info;
42 int r;
43
44 radeon->device = 0;
45 info.request = RADEON_INFO_DEVICE_ID;
46 info.value = (uintptr_t)&radeon->device;
47 r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
48 sizeof(struct drm_radeon_info));
49 return r;
50 }
51
52 struct radeon *radeon_new(int fd, unsigned device)
53 {
54 struct radeon *radeon;
55 int r;
56
57 radeon = calloc(1, sizeof(*radeon));
58 if (radeon == NULL) {
59 return NULL;
60 }
61 radeon->fd = fd;
62 radeon->device = device;
63 radeon->refcount = 1;
64 if (fd >= 0) {
65 r = radeon_get_device(radeon);
66 if (r) {
67 fprintf(stderr, "Failed to get device id\n");
68 return radeon_decref(radeon);
69 }
70 }
71 radeon->family = radeon_family_from_device(radeon->device);
72 if (radeon->family == CHIP_UNKNOWN) {
73 fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->device);
74 return radeon_decref(radeon);
75 }
76 switch (radeon->family) {
77 case CHIP_R600:
78 case CHIP_RV610:
79 case CHIP_RV630:
80 case CHIP_RV670:
81 case CHIP_RV620:
82 case CHIP_RV635:
83 case CHIP_RS780:
84 case CHIP_RS880:
85 case CHIP_RV770:
86 case CHIP_RV730:
87 case CHIP_RV710:
88 case CHIP_RV740:
89 case CHIP_CEDAR:
90 case CHIP_REDWOOD:
91 case CHIP_JUNIPER:
92 case CHIP_CYPRESS:
93 case CHIP_HEMLOCK:
94 break;
95 case CHIP_R100:
96 case CHIP_RV100:
97 case CHIP_RS100:
98 case CHIP_RV200:
99 case CHIP_RS200:
100 case CHIP_R200:
101 case CHIP_RV250:
102 case CHIP_RS300:
103 case CHIP_RV280:
104 case CHIP_R300:
105 case CHIP_R350:
106 case CHIP_RV350:
107 case CHIP_RV380:
108 case CHIP_R420:
109 case CHIP_R423:
110 case CHIP_RV410:
111 case CHIP_RS400:
112 case CHIP_RS480:
113 case CHIP_RS600:
114 case CHIP_RS690:
115 case CHIP_RS740:
116 case CHIP_RV515:
117 case CHIP_R520:
118 case CHIP_RV530:
119 case CHIP_RV560:
120 case CHIP_RV570:
121 case CHIP_R580:
122 default:
123 fprintf(stderr, "%s unknown or unsupported chipset 0x%04X\n",
124 __func__, radeon->device);
125 break;
126 }
127
128 /* setup class */
129 switch (radeon->family) {
130 case CHIP_R600:
131 case CHIP_RV610:
132 case CHIP_RV630:
133 case CHIP_RV670:
134 case CHIP_RV620:
135 case CHIP_RV635:
136 case CHIP_RS780:
137 case CHIP_RS880:
138 radeon->chip_class = R600;
139 break;
140 case CHIP_RV770:
141 case CHIP_RV730:
142 case CHIP_RV710:
143 case CHIP_RV740:
144 radeon->chip_class = R700;
145 break;
146 case CHIP_CEDAR:
147 case CHIP_REDWOOD:
148 case CHIP_JUNIPER:
149 case CHIP_CYPRESS:
150 case CHIP_HEMLOCK:
151 radeon->chip_class = EVERGREEN;
152 break;
153 default:
154 fprintf(stderr, "%s unknown or unsupported chipset 0x%04X\n",
155 __func__, radeon->device);
156 break;
157 }
158
159 radeon->mman = pb_malloc_bufmgr_create();
160 if (!radeon->mman)
161 return NULL;
162 radeon->kman = radeon_bo_pbmgr_create(radeon);
163 if (!radeon->kman)
164 return NULL;
165 radeon->cman = pb_cache_manager_create(radeon->kman, 100000);
166 if (!radeon->cman)
167 return NULL;
168 return radeon;
169 }
170
171 struct radeon *r600_drm_winsys_create(int drmfd)
172 {
173 return radeon_new(drmfd, 0);
174 }
175
176 struct radeon *radeon_decref(struct radeon *radeon)
177 {
178 if (radeon == NULL)
179 return NULL;
180 if (--radeon->refcount > 0) {
181 return NULL;
182 }
183
184 radeon->mman->destroy(radeon->mman);
185 radeon->cman->destroy(radeon->cman);
186 radeon->kman->destroy(radeon->kman);
187 drmClose(radeon->fd);
188 free(radeon);
189 return NULL;
190 }