1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
/* sis.c -- sis driver -*- linux-c -*-
*/
/*-
* Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Sung-Ching Lin <sclin@sis.com.tw>
*/
#include "drmP.h"
#include "sis_drm.h"
#define DRIVER_AUTHOR "SIS, Tungsten Graphics"
#define DRIVER_NAME "sis"
#define DRIVER_DESC "SIS 300/630/540 and XGI V3XE/V5/V8"
#define DRIVER_DATE "20070626"
#define DRIVER_MAJOR 1
#define DRIVER_MINOR 3
#define DRIVER_PATCHLEVEL 0
struct drm_sis_private {
struct device dev;
struct device *drmdev;
struct drm_heap agp_heap;
struct drm_heap fb_heap;
} drm_sis_private_t;
enum sis_family {
SIS_OTHER = 0,
SIS_CHIP_315 = 1,
};
int sisdrm_probe(struct device *, void *, void *);
void sisdrm_attach(struct device *, struct device *, void *);
int sisdrm_detach(struct device *, int);
void sisdrm_lastclose(struct drm_device *);
void sisdrm_close(struct drm_device *, struct drm_file *);
int sisdrm_ioctl(struct drm_device *, u_long, caddr_t, struct drm_file *);
int sis_alloc(struct drm_heap *, drm_sis_mem_t *, struct drm_file *);
int sis_free(struct drm_heap *, drm_sis_mem_t *, struct drm_file *);
int sis_fb_init(struct drm_device *, void *, struct drm_file *);
int sis_agp_init(struct drm_device *, void *, struct drm_file *);
const static struct drm_pcidev sis_pciidlist[] = {
{PCI_VENDOR_SIS, PCI_PRODUCT_SIS_300},
{PCI_VENDOR_SIS, PCI_PRODUCT_SIS_5300},
{PCI_VENDOR_SIS, PCI_PRODUCT_SIS_6300},
{PCI_VENDOR_SIS, PCI_PRODUCT_SIS_6330},
{PCI_VENDOR_SIS, PCI_PRODUCT_SIS_7300},
{PCI_VENDOR_XGI, 0x0042, SIS_CHIP_315},
{PCI_VENDOR_XGI, PCI_PRODUCT_XGI_VOLARI_V3XT},
{0, 0, 0}
};
static const struct drm_driver_info sis_driver = {
.close = sisdrm_close,
.lastclose = sisdrm_lastclose,
.ioctl = sisdrm_ioctl,
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
.date = DRIVER_DATE,
.major = DRIVER_MAJOR,
.minor = DRIVER_MINOR,
.patchlevel = DRIVER_PATCHLEVEL,
.flags = DRIVER_AGP | DRIVER_MTRR,
};
int
sisdrm_probe(struct device *parent, void *match, void *aux)
{
return (drm_pciprobe((struct pci_attach_args *)aux, sis_pciidlist));
}
void
sisdrm_attach(struct device *parent, struct device *self, void *aux)
{
struct drm_sis_private *dev_priv = (struct drm_sis_private *)self;
struct pci_attach_args *pa = aux;
int is_agp;
is_agp = pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP,
NULL, NULL);
printf("\n");
TAILQ_INIT(&dev_priv->agp_heap);
TAILQ_INIT(&dev_priv->fb_heap);
dev_priv->drmdev = drm_attach_pci(&sis_driver, pa, is_agp, self);
}
int
sisdrm_detach(struct device *self, int flags)
{
struct drm_sis_private *dev_priv = (struct drm_sis_private *)self;
if (dev_priv->drmdev != NULL) {
config_detach(dev_priv->drmdev, flags);
dev_priv->drmdev = NULL;
}
return (0);
}
struct cfattach sisdrm_ca = {
sizeof(struct drm_sis_private), sisdrm_probe, sisdrm_attach,
sisdrm_detach
};
struct cfdriver sisdrm_cd = {
0, "sisdrm", DV_DULL
};
void
sisdrm_close(struct drm_device *dev, struct drm_file *file_priv)
{
struct drm_sis_private *dev_priv = dev->dev_private;
drm_mem_release(&dev_priv->agp_heap, file_priv);
drm_mem_release(&dev_priv->fb_heap, file_priv);
}
void
sisdrm_lastclose(struct drm_device *dev)
{
struct drm_sis_private *dev_priv = dev->dev_private;
drm_mem_takedown(&dev_priv->agp_heap);
drm_mem_takedown(&dev_priv->fb_heap);
}
int
sisdrm_ioctl(struct drm_device *dev, u_long cmd, caddr_t data,
struct drm_file *file_priv)
{
struct drm_sis_private *dev_priv = dev->dev_private;
if (dev_priv == NULL)
return (EINVAL);
if (file_priv->authenticated == 1) {
switch (cmd) {
case DRM_IOCTL_SIS_FB_ALLOC:
return (sis_alloc(&dev_priv->fb_heap,
(drm_sis_mem_t *)data, file_priv));
case DRM_IOCTL_SIS_FB_FREE:
return (sis_free(&dev_priv->fb_heap,
(drm_sis_mem_t *)data, file_priv));
case DRM_IOCTL_SIS_AGP_ALLOC:
return (sis_alloc(&dev_priv->agp_heap,
(drm_sis_mem_t *)data, file_priv));
case DRM_IOCTL_SIS_AGP_FREE:
return (sis_free(&dev_priv->agp_heap,
(drm_sis_mem_t *)data, file_priv));
}
}
if (file_priv->master == 1) {
switch (cmd) {
case DRM_IOCTL_SIS_AGP_INIT:
return (sis_agp_init(dev, data, file_priv));
case DRM_IOCTL_SIS_FB_INIT:
return (sis_fb_init(dev, data, file_priv));
}
}
return (EINVAL);
}
/* fb management via fb device */
/* Called by the X Server to initialize the FB heap. Allocations will fail
* unless this is called. Offset is the beginning of the heap from the
* framebuffer offset (MaxXFBMem in XFree86).
*
* Memory layout according to Thomas Winischofer:
* |------------------|DDDDDDDDDDDDDDDDDDDDDDDDDDDDD|HHHH|CCCCCCCCCCC|
*
* X driver/sisfb HW- Command-
* framebuffer memory DRI heap Cursor queue
*/
int
sis_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
struct drm_sis_private *dev_priv = dev->dev_private;
drm_sis_fb_t *fb = data;
DRM_DEBUG("offset = %u, size = %u", fb->offset, fb->size);
return (drm_init_heap(&dev_priv->fb_heap, fb->offset, fb->size));
}
int
sis_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
{
struct drm_sis_private *dev_priv = dev->dev_private;
drm_sis_agp_t *agp = data;
DRM_DEBUG("offset = %u, size = %u", agp->offset, agp->size);
return (drm_init_heap(&dev_priv->agp_heap, agp->offset, agp->size));
}
int
sis_alloc(struct drm_heap *heap, drm_sis_mem_t *mem,
struct drm_file *file_priv)
{
struct drm_mem *block;
/* Original code had no aligment restrictions. Should we page align? */
if ((block = drm_alloc_block(heap, mem->size, 0, file_priv)) == NULL)
return (ENOMEM);
mem->offset = block->start;
mem->free = block->start;
DRM_DEBUG("alloc agp, size = %d, offset = %d\n", mem->size,
mem->offset);
return (0);
}
int
sis_free(struct drm_heap *heap, drm_sis_mem_t *mem, struct drm_file *file_priv)
{
DRM_DEBUG("free fb, free = 0x%lx\n", mem->free);
return (drm_mem_free(heap, mem->free, file_priv));
}
|