1 /*
2 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
3 */
4
5 /*
6 * drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
7 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
8 */
9 /*
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * Copyright (c) 2009, 2013, Intel Corporation.
13 * All rights reserved.
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
21 *
22 * The above copyright notice and this permission notice (including the next
23 * paragraph) shall be included in all copies or substantial portions of the
24 * Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
33 *
34 * Authors:
35 * Rickard E. (Rik) Faith <faith@valinux.com>
36 * Gareth Hughes <gareth@valinux.com>
37 *
38 */
39
40 #ifndef _DRMP_H
41 #define _DRMP_H
42
43 #include <sys/types.h>
44 #include <sys/conf.h>
45 #include <sys/modctl.h>
46 #include <sys/stat.h>
47 #include <sys/file.h>
48 #include <sys/cmn_err.h>
49 #include <sys/varargs.h>
50 #include <sys/pci.h>
51 #include <sys/ddi.h>
52 #include <sys/sunddi.h>
53 #include <sys/sunldi.h>
54 #include <sys/agpgart.h>
55 #include <sys/time.h>
56 #include <sys/gfx_private.h>
57 #include <sys/ddifm.h>
58 #include <sys/fm/protocol.h>
59 #include <sys/fm/util.h>
60 #include <sys/fm/io/ddi.h>
61 #include <drm/drm.h>
62 #include <drm/drm_os_solaris.h>
63 #include "drm_atomic.h"
64 #include <sys/queue.h>
65 #include "drm_linux.h"
66 #include "drm_linux_list.h"
67 #include "drm_mm.h"
68 #include "drm_mode.h"
69
70 #include "drm_sun_idr.h"
71 #include "drm_sun_timer.h"
72 #include "drm_sun_workqueue.h"
73 #include "drm_sun_pci.h"
74
75 #ifndef __inline__
76 #define __inline__ inline
77 #endif
78
79 #if !defined(__FUNCTION__)
80 #if defined(_STDC_C99) || defined(__C99FEATURES__)
81 #define __FUNCTION__ __func__
82 #else
83 #define __FUNCTION__ " "
84 #endif
85 #endif
86
87 #define KB(x) ((x) * 1024)
88 #define MB(x) (KB (KB (x)))
89 #define GB(x) (MB (KB (x)))
90
91 #define DRM_MINOR_NBITS (9)
92 #define DRM_MINOR_SHIFT (0)
93 #define DRM_MINOR_MAX ((1 << DRM_MINOR_NBITS) - 1)
94 #define DRM_DEV2MINOR(dev) ((getminor(dev) >> DRM_MINOR_SHIFT) & DRM_MINOR_MAX)
95
96 #define DRM_CLONEID_NBITS (NBITSMINOR - DRM_MINOR_NBITS)
97 #define DRM_CLONEID_SHIFT (DRM_MINOR_NBITS)
98 #define DRM_CLONEID_MAX ((1 << DRM_CLONEID_NBITS) - 1)
99 #define DRM_DEV2CLONEID(dev) ((getminor(dev) >> DRM_CLONEID_SHIFT) & DRM_CLONEID_MAX)
100
101 #define DRM_MAKEDEV(major_id, minor_id, clone_id) \
102 makedevice(major_id, (minor_id << DRM_MINOR_SHIFT) | (clone_id << DRM_CLONEID_SHIFT))
103
104 /* driver capabilities and requirements mask */
105 #define DRIVER_USE_AGP 0x1
106 #define DRIVER_REQUIRE_AGP 0x2
107 #define DRIVER_USE_MTRR 0x4
108 #define DRIVER_PCI_DMA 0x8
109 #define DRIVER_SG 0x10
110 #define DRIVER_HAVE_DMA 0x20
111 #define DRIVER_HAVE_IRQ 0x40
112 #define DRIVER_IRQ_SHARED 0x80
113 #define DRIVER_IRQ_VBL 0x100
114 #define DRIVER_DMA_QUEUE 0x200
115 #define DRIVER_FB_DMA 0x400
116 #define DRIVER_IRQ_VBL2 0x800
117 #define DRIVER_GEM 0x1000
118 #define DRIVER_MODESET 0x2000
119 #define DRIVER_PRIME 0x4000
120 #define DRIVER_USE_PLATFORM_DEVICE 0x8000
121
122 /* DRM space units */
123 #define DRM_PAGE_SHIFT PAGESHIFT
124 #define DRM_PAGE_SIZE (1 << DRM_PAGE_SHIFT)
125 #define DRM_PAGE_OFFSET (DRM_PAGE_SIZE - 1)
126 #define DRM_PAGE_MASK ~(DRM_PAGE_SIZE - 1)
127 #define DRM_MB2PAGES(x) ((x) << 8)
128 #define DRM_PAGES2BYTES(x) ((x) << DRM_PAGE_SHIFT)
129 #define DRM_BYTES2PAGES(x) ((x) >> DRM_PAGE_SHIFT)
130 #define DRM_PAGES2KB(x) ((x) << 2)
131 #define DRM_ALIGNED(offset) (((offset) & DRM_PAGE_OFFSET) == 0)
132
133 #define PAGE_SHIFT DRM_PAGE_SHIFT
134 #define PAGE_SIZE DRM_PAGE_SIZE
135
136 #define DRM_MAX_INSTANCES 8
137 #define DRM_DEVNODE "drm"
138 #define DRM_UNOPENED 0
139 #define DRM_OPENED 1
140
141 #define DRM_HASH_SIZE 16 /* Size of key hash table */
142 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
143 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
144
145 #define DRM_MEM_DMA 0
146 #define DRM_MEM_SAREA 1
147 #define DRM_MEM_DRIVER 2
148 #define DRM_MEM_MAGIC 3
149 #define DRM_MEM_IOCTLS 4
150 #define DRM_MEM_MAPS 5
151 #define DRM_MEM_BUFS 6
152 #define DRM_MEM_SEGS 7
153 #define DRM_MEM_PAGES 8
154 #define DRM_MEM_FILES 9
155 #define DRM_MEM_QUEUES 10
156 #define DRM_MEM_CMDS 11
157 #define DRM_MEM_MAPPINGS 12
158 #define DRM_MEM_BUFLISTS 13
159 #define DRM_MEM_DRMLISTS 14
160 #define DRM_MEM_TOTALDRM 15
161 #define DRM_MEM_BOUNDDRM 16
162 #define DRM_MEM_CTXBITMAP 17
163 #define DRM_MEM_STUB 18
164 #define DRM_MEM_SGLISTS 19
165 #define DRM_MEM_AGPLISTS 20
166 #define DRM_MEM_CTXLIST 21
167 #define DRM_MEM_MM 22
168 #define DRM_MEM_HASHTAB 23
169 #define DRM_MEM_OBJECTS 24
170
171 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
172 #define DRM_MAP_HASH_OFFSET 0x10000000
173 #define DRM_MAP_HASH_ORDER 12
174 #define DRM_OBJECT_HASH_ORDER 12
175 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
176 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
177 #define DRM_MM_INIT_MAX_PAGES 256
178
179
180 /* Internal types and structures */
181 #define DRM_ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
182 #define DRM_MIN(a, b) ((a) < (b) ? (a) : (b))
183 #define DRM_MAX(a, b) ((a) > (b) ? (a) : (b))
184
185 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
186
187 #define __OS_HAS_AGP 1
188
189 #define DRM_DEV_MOD (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
190 #define DRM_DEV_UID 0
191 #define DRM_DEV_GID 0
192
193 #define DRM_CURRENTPID ddi_get_pid()
194 #define DRM_SPINLOCK(l) mutex_enter(l)
195 #define DRM_SPINUNLOCK(u) mutex_exit(u)
196 #define DRM_UDELAY(d) udelay(d)
197 #define DRM_MEMORYBARRIER()
198
199 #define DRM_MINOR_UNASSIGNED 0
200 #define DRM_MINOR_LEGACY 1
201 #define DRM_MINOR_CONTROL 2
202 #define DRM_MINOR_RENDER 3
203 #define DRM_MINOR_VGATEXT 4
204 #define DRM_MINOR_AGPMASTER 5
205
206 #define DRM_MINOR_ID_BASE_LEGACY 0
207 #define DRM_MINOR_ID_BASE_CONTROL 64
208 #define DRM_MINOR_ID_BASE_RENDER 128
209 #define DRM_MINOR_ID_BASE_VGATEXT 384
210 #define DRM_MINOR_ID_BASE_AGPMASTER 448
211
212 #define DRM_MINOR_ID_LIMIT_LEGACY 63
213 #define DRM_MINOR_ID_LIMIT_CONTROL 127
214 #define DRM_MINOR_ID_LIMIT_RENDER 383
215 #define DRM_MINOR_ID_LIMIT_VGATEXT 447
216 #define DRM_MINOR_ID_LIMIT_AGPMASTER 511
217
218 #define DRM_MINOR_IS_LEGACY(minor_id) \
219 (minor_id >= DRM_MINOR_ID_BASE_LEGACY && minor_id < DRM_MINOR_ID_LIMIT_LEGACY)
220 #define DRM_MINOR_IS_CONTROL(minor_id) \
221 (minor_id >= DRM_MINOR_ID_BASE_CONTROL && minor_id < DRM_MINOR_ID_LIMIT_CONTROL)
222 #define DRM_MINOR_IS_RENDER(minor_id) \
223 (minor_id >= DRM_MINOR_ID_BASE_RENDER && minor_id < DRM_MINOR_ID_LIMIT_RENDER)
224 #define DRM_MINOR_IS_VGATEXT(minor_id) \
225 (minor_id >= DRM_MINOR_ID_BASE_VGATEXT && minor_id < DRM_MINOR_ID_LIMIT_VGATEXT)
226 #define DRM_MINOR_IS_AGPMASTER(minor_id) \
227 (minor_id >= DRM_MINOR_ID_BASE_AGPMASTER && minor_id < DRM_MINOR_ID_LIMIT_AGPMASTER)
228
229 /* Legacy VGA regions */
230 #define VGA_RSRC_NONE 0x00
231 #define VGA_RSRC_LEGACY_IO 0x01
232 #define VGA_RSRC_LEGACY_MEM 0x02
233 #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
234 /* Non-legacy access */
235 #define VGA_RSRC_NORMAL_IO 0x04
236 #define VGA_RSRC_NORMAL_MEM 0x08
237
238
239 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
240
241
242 typedef struct drm_file drm_file_t;
243 typedef struct drm_device drm_device_t;
244 typedef struct drm_driver drm_driver_t;
245
246 #define DRM_COPYFROM_WITH_RETURN(dest, src, size) \
247 if (ddi_copyin((src), (dest), (size), 0)) { \
248 DRM_ERROR("copy from user failed"); \
249 return (-EFAULT); \
250 }
251
252 #define DRM_COPYTO_WITH_RETURN(dest, src, size) \
253 if (ddi_copyout((src), (dest), (size), 0)) { \
254 DRM_ERROR("copy to user failed"); \
255 return (-EFAULT); \
256 }
257
258 #define DRM_COPY_FROM_USER(dest, src, size) \
259 ddi_copyin((src), (dest), (size), 0) /* flag for src */
260
261 #define DRM_COPY_TO_USER(dest, src, size) \
262 ddi_copyout((src), (dest), (size), 0) /* flags for dest */
263
264 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
265 ddi_copyin((arg2), (arg1), (arg3), 0)
266
267 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
268 ddi_copyout((arg2), arg1, arg3, 0)
269
270 #define DRM_READ8(map, offset) \
271 *(volatile uint8_t *)((uintptr_t)((map)->handle) + (offset))
272 #define DRM_READ16(map, offset) \
273 *(volatile uint16_t *)((uintptr_t)((map)->handle) + (offset))
274 #define DRM_READ32(map, offset) \
275 *(volatile uint32_t *)((uintptr_t)((map)->handle) + (offset))
276 #define DRM_READ64(map, offset) \
277 *(volatile uint64_t *)((uintptr_t)((map)->handle) + (offset))
278 #define DRM_WRITE8(map, offset, val) \
279 *(volatile uint8_t *)((uintptr_t)((map)->handle) + (offset)) = (val)
280 #define DRM_WRITE16(map, offset, val) \
281 *(volatile uint16_t *)((uintptr_t)((map)->handle) + (offset)) = (val)
282 #define DRM_WRITE32(map, offset, val) \
283 *(volatile uint32_t *)((uintptr_t)((map)->handle) + (offset)) = (val)
284 #define DRM_WRITE64(map, offset, val) \
285 *(volatile uint64_t *)((uintptr_t)((map)->handle) + (offset)) = (val)
286
287 typedef struct drm_wait_queue {
288 kcondvar_t cv;
289 kmutex_t lock;
290 }wait_queue_head_t;
291
292 #define DRM_INIT_WAITQUEUE(q, pri) \
293 { \
294 mutex_init(&(q)->lock, NULL, MUTEX_DRIVER, pri); \
295 cv_init(&(q)->cv, NULL, CV_DRIVER, NULL); \
296 }
297
298 #define DRM_FINI_WAITQUEUE(q) \
299 { \
300 mutex_destroy(&(q)->lock); \
301 cv_destroy(&(q)->cv); \
302 }
303
304 #define DRM_WAKEUP(q) \
305 { \
306 mutex_enter(&(q)->lock); \
307 cv_broadcast(&(q)->cv); \
308 mutex_exit(&(q)->lock); \
309 }
310
311 #define DRM_WAIT_ON(ret, q, timeout, condition) \
312 mutex_enter(&(q)->lock); \
313 while (!(condition)) { \
314 ret = cv_reltimedwait_sig(&(q)->cv, &(q)->lock, timeout,\
315 TR_CLOCK_TICK); \
316 if (ret == -1) { \
317 ret = EBUSY; \
318 break; \
319 } else if (ret == 0) { \
320 ret = EINTR; \
321 break; \
322 } else { \
323 ret = 0; \
324 } \
325 } \
326 mutex_exit(&(q)->lock);
327
328 #define DRM_WAIT(ret, q, condition) \
329 mutex_enter(&(q)->lock); \
330 if (!(condition)) { \
331 (void) cv_timedwait_sig(&(q)->cv, &(q)->lock, jiffies + 3 * DRM_HZ); \
332 ret = 0; \
333 if (!(condition)) { \
334 /* make sure we got what we want */ \
335 if (wait_for(condition, 3000)) \
336 ret = EBUSY; \
337 } \
338 } \
339 mutex_exit(&(q)->lock);
340
341 /*
342 #define DRM_GETSAREA() \
343 { \
344 drm_local_map_t *map; \
345 TAILQ_FOREACH(map, &dev->maplist, link) { \
346 if (map->type == _DRM_SHM && \
347 map->flags & _DRM_CONTAINS_LOCK) { \
348 dev_priv->sarea = map; \
349 break; \
350 } \
351 } \
352 }
353 */
354
355 #define wake_up_all DRM_WAKEUP
356
357 /**
358 * Test that the hardware lock is held by the caller, returning otherwise.
359 *
360 * \param dev DRM device.
361 * \param filp file pointer of the caller.
362 */
363 #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
364 do { \
365 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
366 _file_priv->master->lock.file_priv != _file_priv) { \
367 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
368 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
369 (void *)_file_priv->master->lock.file_priv, (void *)_file_priv); \
370 return -EINVAL; \
371 } \
372 } while (*"\0")
373
374 /**
375 * Copy and IOCTL return string to user space
376 */
377 #define DRM_COPY(name, value) \
378 len = strlen(value); \
379 if (len > name##_len) len = name##_len; \
380 name##_len = strlen(value); \
381 if (len && name) { \
382 if (DRM_COPY_TO_USER(name, value, len)) \
383 return (EFAULT); \
384 }
385
386 #define DRM_IRQ_ARGS caddr_t arg
387 #define IRQ_HANDLED DDI_INTR_CLAIMED
388 #define IRQ_NONE DDI_INTR_UNCLAIMED
389
390 enum {
391 DRM_IS_NOT_AGP,
392 DRM_IS_AGP,
393 DRM_MIGHT_BE_AGP
394 };
395
396 /* Capabilities taken from src/sys/dev/pci/pcireg.h. */
397 #ifndef PCIY_AGP
398 #define PCIY_AGP 0x02
399 #endif
400
401 #ifndef PCIY_EXPRESS
402 #define PCIY_EXPRESS 0x10
403 #endif
404
405 #define PAGE_ALIGN(addr) (((addr) + DRM_PAGE_SIZE - 1) & DRM_PAGE_MASK)
406 #define DRM_SUSER(p) (crgetsgid(p) == 0 || crgetsuid(p) == 0)
407
408 /*
409 * wait for 400 milliseconds
410 */
411 //#define DRM_HZ drv_usectohz(400000)
412 #define DRM_HZ drv_usectohz(1000000)
413
414 #define DRM_SUPPORT 1
415 #define DRM_UNSUPPORT 0
416
417 #define __OS_HAS_AGP 1
418
419 #ifndef offsetof
420 #define __offsetof(type, field) ((size_t)(&((type *)0)->field))
421 #define offsetof(type, field) __offsetof(type, field)
422 #endif
423
424 typedef struct drm_pci_id_list {
425 int vendor;
426 int device;
427 unsigned long driver_data;
428 } drm_pci_id_list_t;
429
430 #define DRM_DEVICE drm_device_t *dev = dev1
431 #define DRM_IOCTL_ARGS \
432 dev_t dev_id, struct drm_device *dev, void *data, struct drm_file *file, int ioctl_mode, cred_t *credp
433
434 typedef int drm_ioctl_t(DRM_IOCTL_ARGS);
435
436 #define DRM_AUTH 0x1
437 #define DRM_MASTER 0x2
438 #define DRM_ROOT_ONLY 0x4
439 #define DRM_CONTROL_ALLOW 0x8
440 #define DRM_UNLOCKED 0x10
441
442 typedef struct drm_ioctl_desc {
443 drm_ioctl_t *func;
444 int flags;
445 int cmd;
446 unsigned int cmd_drv;
447 const char *name;
448 int (*copyin32)(void *dest, void *src);
449 int (*copyout32)(void *dest, void *src);
450 } drm_ioctl_desc_t;
451
452 /**
453 * Creates a driver or general drm_ioctl_desc array entry for the given
454 * ioctl, for use by drm_ioctl().
455 */
456 #ifdef _MULTI_DATAMODEL
457 #define DRM_IOCTL_DEF(ioctl, _func, _flags, _copyin32, _copyout32) \
458 [DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .flags = _flags, .func = _func, .copyin32 = _copyin32, .copyout32 = _copyout32}
459 #else
460 #define DRM_IOCTL_DEF(ioctl, _func, _flags, _copyin32, _copyout32) \
461 [DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .flags = _flags, .func = _func, .copyin32 = NULL, .copyout32 = NULL}
462 #endif
463
464 typedef struct drm_magic_entry {
465 drm_magic_t magic;
466 struct drm_file *priv;
467 struct drm_magic_entry *next;
468 } drm_magic_entry_t;
469
470 typedef struct drm_magic_head {
471 struct drm_magic_entry *head;
472 struct drm_magic_entry *tail;
473 } drm_magic_head_t;
474
475 typedef struct drm_buf {
476 int idx; /* Index into master buflist */
477 int total; /* Buffer size */
478 int order; /* log-base-2(total) */
479 int used; /* Amount of buffer in use (for DMA) */
480 unsigned long offset; /* Byte offset (used internally) */
481 void *address; /* Address of buffer */
482 unsigned long bus_address; /* Bus address of buffer */
483 struct drm_buf *next; /* Kernel-only: used for free list */
484 volatile int pending; /* On hardware DMA queue */
485 struct drm_file *file_priv;
486 /* Uniq. identifier of holding process */
487 int context; /* Kernel queue for this buffer */
488 enum {
489 DRM_LIST_NONE = 0,
490 DRM_LIST_FREE = 1,
491 DRM_LIST_WAIT = 2,
492 DRM_LIST_PEND = 3,
493 DRM_LIST_PRIO = 4,
494 DRM_LIST_RECLAIM = 5
495 } list; /* Which list we're on */
496
497 int dev_priv_size; /* Size of buffer private storage */
498 void *dev_private; /* Per-buffer private storage */
499 } drm_buf_t;
500
501 typedef struct drm_freelist {
502 int initialized; /* Freelist in use */
503 uint32_t count; /* Number of free buffers */
504 drm_buf_t *next; /* End pointer */
505
506 int low_mark; /* Low water mark */
507 int high_mark; /* High water mark */
508 } drm_freelist_t;
509
510 typedef struct drm_buf_entry {
511 int buf_size;
512 int buf_count;
513 drm_buf_t *buflist;
514 int seg_count;
515 int page_order;
516
517 uint32_t *seglist;
518 unsigned long *seglist_bus;
519
520 drm_freelist_t freelist;
521 } drm_buf_entry_t;
522
523 /* Event queued up for userspace to read */
524 struct drm_pending_event {
525 struct drm_event *event;
526 struct list_head link;
527 struct drm_file *file_priv;
528 pid_t pid; /* pid of requester, no guarantee it's valid by the time
529 we deliver the event, for tracing only */
530 void (*destroy)(void *event, size_t size);
531 };
532
533
534 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
535
536 /**
537 * Kernel side of a mapping
538 */
539 typedef struct drm_local_map {
540 unsigned long offset; /**< Requested physical address (0 for SAREA)*/
541 unsigned long size; /**< Requested physical size (bytes) */
542 enum drm_map_type type; /**< Type of memory to map */
543 enum drm_map_flags flags; /**< Flags */
544 void *handle; /**< User-space: "Handle" to pass to mmap() */
545 /**< Kernel-space: kernel-virtual address */
546 int mtrr; /**< MTRR slot used */
547
548 /* OSOL_drm Begin */
549 ddi_acc_handle_t acc_handle; /**< The data access handle */
550 ddi_umem_cookie_t umem_cookie; /**< For SAREA alloc and free */
551 int callback; /** need callback ops to handle GTT mmap */
552 int gtt_mmap; /** gtt mmap has been setuped */
553 /* OSOL_drm End */
554 } drm_local_map_t;
555
556 /**
557 * Mappings list
558 */
559 struct drm_map_list {
560 struct list_head head; /**< list head */
561 /* OSOL_drm: struct drm_hash_item hash; */
562 struct drm_local_map *map; /**< mapping */
563 uint64_t user_token;
564 struct drm_master *master;
565 struct drm_mm_node *file_offset_node; /**< fake offset */
566 };
567
568 struct drm_ctx_list {
569 struct list_head head; /**< list head */
570 drm_context_t handle; /**< context handle */
571 struct drm_file *tag; /**< associated fd private data */
572 };
573
574 struct drm_history_list {
575 struct list_head head;
576 char info[20]; /**< history info */
577 uint32_t cur_seq; /**< current system seqno */
578 uint32_t last_seq; /**< last seqno */
579 void *ring_ptr; /**< current ring ptr */
580 };
581
582 struct gem_map_list {
583 struct list_head head; /**< list head */
584 devmap_cookie_t dhp;
585 offset_t mapoffset;
586 size_t maplen;
587 };
588
589 /*
590 * This structure defines the drm_mm memory object, which will be used by the
591 * DRM for its buffer objects.
592 */
593 struct drm_gem_object {
594 /* Reference count of this object */
595 struct kref refcount;
596
597 /* Handle count of this object. Each handle also holds a reference */
598 atomic_t handle_count;
599
600 /* Related drm device */
601 struct drm_device *dev;
602
603 /* Mapping info for this object */
604 struct drm_map_list map_list;
605
606 /*
607 * Size of the object, in bytes. Immutable over the object's
608 * lifetime.
609 */
610 size_t size;
611
612 /*
613 * Global name for this object, starts at 1. 0 means unnamed.
614 * Access is covered by the object_name_lock in the related drm_device
615 */
616 int name;
617
618 /*
619 * Memory domains. These monitor which caches contain read/write data
620 * related to the object. When transitioning from one set of domains
621 * to another, the driver is called to ensure that caches are suitably
622 * flushed and invalidated
623 */
624 uint32_t read_domains;
625 uint32_t write_domain;
626
627 /*
628 * While validating an exec operation, the
629 * new read/write domain values are computed here.
630 * They will be transferred to the above values
631 * at the point that any cache flushing occurs
632 */
633 uint32_t pending_read_domains;
634 uint32_t pending_write_domain;
635
636 void *driver_private;
637
638 struct drm_map_list maplist;
639 ddi_dma_handle_t dma_hdl;
640 ddi_acc_handle_t acc_hdl;
641 caddr_t kaddr;
642 size_t real_size; /* real size of memory */
643 pfn_t *pfnarray;
644 caddr_t gtt_map_kaddr;
645
646 struct gfxp_pmem_cookie mempool_cookie;
647
648 struct list_head seg_list;
649
650 struct list_head track_list; /* for i915 mdb */
651 struct list_head his_list;
652 };
653
654 typedef struct drm_lock_data {
655 struct drm_hw_lock *hw_lock; /**< Hardware lock */
656 /** Private of lock holder's file (NULL=kernel) */
657 struct drm_file *file_priv;
658 kcondvar_t lock_cv; /* lock queue - SOLARIS Specific */
659 kmutex_t lock_mutex; /* lock - SOLARIS Specific */
660 unsigned long lock_time; /* Time of last lock in clock ticks */
661 uint32_t kernel_waiters;
662 uint32_t user_waiters;
663 int idle_has_lock;
664 } drm_lock_data_t;
665
666 /*
667 * This structure, in drm_device_t, is always initialized while the device
668 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
669 * when set marks that no further bufs may be allocated until device teardown
670 * occurs (when the last open of the device has closed). The high/low
671 * watermarks of bufs are only touched by the X Server, and thus not
672 * concurrently accessed, so no locking is needed.
673 */
674
675 /**
676 * DMA data.
677 */
678 typedef struct drm_device_dma {
679
680 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
681 int buf_count; /**< total number of buffers */
682 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
683 int seg_count;
684 int page_count; /**< number of pages */
685 unsigned long *pagelist; /**< page list */
686 unsigned long byte_count;
687 enum {
688 _DRM_DMA_USE_AGP = 0x01,
689 _DRM_DMA_USE_SG = 0x02,
690 _DRM_DMA_USE_FB = 0x04,
691 _DRM_DMA_USE_PCI_RO = 0x08
692 } flags;
693
694 } drm_device_dma_t;
695
696 /**
697 * AGP memory entry. Stored as a doubly linked list.
698 */
699 typedef struct drm_agp_mem {
700 unsigned long handle; /**< handle */
701 unsigned long bound; /**< address */
702 int pages;
703 struct list_head head;
704 } drm_agp_mem_t;
705
706 /**
707 * AGP data.
708 *
709 * \sa drm_agp_init() and drm_device::agp.
710 */
711 typedef struct drm_agp_head {
712 agp_info_t agp_info; /**< AGP device information */
713 struct list_head memory;
714 unsigned long mode; /**< AGP mode */
715 int enabled; /**< whether the AGP bus as been enabled */
716 int acquired; /**< whether the AGP device has been acquired */
717 unsigned long base;
718 int mtrr;
719 int cant_use_aperture;
720 unsigned long page_mask;
721 ldi_ident_t agpgart_li;
722 ldi_handle_t agpgart_lh;
723 } drm_agp_head_t;
724
725 typedef struct drm_dma_handle {
726 ddi_dma_handle_t dma_hdl;
727 ddi_acc_handle_t acc_hdl;
728 ddi_dma_cookie_t cookie;
729 uint_t cookie_num;
730 uintptr_t vaddr; /* virtual addr */
731 uintptr_t paddr; /* physical addr */
732 size_t real_sz; /* real size of memory */
733 } drm_dma_handle_t;
734
735 typedef struct drm_sg_mem {
736 unsigned long handle;
737 void *virtual;
738 int pages;
739 dma_addr_t *busaddr;
740
741 ddi_umem_cookie_t *umem_cookie;
742 drm_dma_handle_t *dmah_sg;
743 drm_dma_handle_t *dmah_gart; /* Handle to PCI memory */
744 } drm_sg_mem_t;
745
746 typedef TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig) drm_vbl_sig_list_t;
747 typedef struct drm_vbl_sig {
748 TAILQ_ENTRY(drm_vbl_sig) link;
749 unsigned int sequence;
750 int signo;
751 int pid;
752 } drm_vbl_sig_t;
753
754
755 /* used for clone device */
756 typedef TAILQ_HEAD(drm_cminor_list, drm_cminor) drm_cminor_list_t;
757 typedef struct drm_cminor {
758 TAILQ_ENTRY(drm_cminor) link;
759 drm_file_t *fpriv;
760 int minor;
761 } drm_cminor_t;
762
763 /* location of GART table */
764 #define DRM_ATI_GART_MAIN 1
765 #define DRM_ATI_GART_FB 2
766
767 typedef struct ati_pcigart_info {
768 int gart_table_location;
769 int is_pcie;
770 void *addr;
771 dma_addr_t bus_addr;
772 drm_local_map_t mapping;
773 } drm_ati_pcigart_info;
774
775 /* Size of ringbuffer for vblank timestamps. Just double-buffer
776 * in initial implementation.
777 */
778 #define DRM_VBLANKTIME_RBSIZE 2
779
780 /* Flags and return codes for get_vblank_timestamp() driver function. */
781 #define DRM_CALLED_FROM_VBLIRQ 1
782 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
783 #define DRM_VBLANKTIME_INVBL (1 << 1)
784
785 /* get_scanout_position() return flags */
786 #define DRM_SCANOUTPOS_VALID (1 << 0)
787 #define DRM_SCANOUTPOS_INVBL (1 << 1)
788 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
789
790 /* DRM device structure */
791 struct drm_device;
792
793 struct drm_bus {
794 int bus_type;
795 int (*get_irq)(struct drm_device *dev);
796 const char *(*get_name)(struct drm_device *dev);
797 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
798 int (*set_unique)(struct drm_device *dev, struct drm_master *master,
799 struct drm_unique *unique);
800 int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
801 /* hooks that are for PCI */
802 int (*agp_init)(struct drm_device *dev);
803
804 };
805
806 struct drm_driver {
807 int (*load)(struct drm_device *, unsigned long);
808 int (*firstopen)(struct drm_device *);
809 int (*open)(struct drm_device *, drm_file_t *);
810 void (*preclose)(struct drm_device *, drm_file_t *);
811 void (*postclose)(struct drm_device *, drm_file_t *);
812 void (*lastclose)(struct drm_device *);
813 int (*unload)(struct drm_device *);
814 void (*reclaim_buffers_locked)(struct drm_device *, drm_file_t *);
815 int (*presetup)(struct drm_device *);
816 int (*postsetup)(struct drm_device *);
817 int (*open_helper)(struct drm_device *, drm_file_t *);
818 void (*free_filp_priv)(struct drm_device *, drm_file_t *);
819 void (*release)(struct drm_device *, void *);
820 int (*dma_ioctl)(DRM_IOCTL_ARGS);
821 int (*dma_quiescent)(struct drm_device *);
822 int (*dma_flush_block_and_flush)(struct drm_device *,
823 int, drm_lock_flags_t);
824 int (*dma_flush_unblock)(struct drm_device *, int,
825 drm_lock_flags_t);
826 int (*context_dtor)(struct drm_device *, int);
827 int (*device_is_agp) (struct drm_device *);
828
829 /**
830 * Called by vblank timestamping code.
831 *
832 * Return the current display scanout position from a crtc.
833 *
834 * \param dev DRM device.
835 * \param crtc Id of the crtc to query.
836 * \param *vpos Target location for current vertical scanout position.
837 * \param *hpos Target location for current horizontal scanout position.
838 *
839 * Returns vpos as a positive number while in active scanout area.
840 * Returns vpos as a negative number inside vblank, counting the number
841 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
842 * until start of active scanout / end of vblank."
843 *
844 * \return Flags, or'ed together as follows:
845 *
846 * DRM_SCANOUTPOS_VALID = Query successfull.
847 * DRM_SCANOUTPOS_INVBL = Inside vblank.
848 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
849 * this flag means that returned position may be offset by a constant
850 * but unknown small number of scanlines wrt. real scanout position.
851 *
852 */
853 int (*get_scanout_position) (struct drm_device *dev, int crtc,
854 int *vpos, int *hpos);
855
856 /**
857 * Called by \c drm_get_last_vbltimestamp. Should return a precise
858 * timestamp when the most recent VBLANK interval ended or will end.
859 *
860 * Specifically, the timestamp in @vblank_time should correspond as
861 * closely as possible to the time when the first video scanline of
862 * the video frame after the end of VBLANK will start scanning out,
863 * the time immmediately after end of the VBLANK interval. If the
864 * @crtc is currently inside VBLANK, this will be a time in the future.
865 * If the @crtc is currently scanning out a frame, this will be the
866 * past start time of the current scanout. This is meant to adhere
867 * to the OpenML OML_sync_control extension specification.
868 *
869 * \param dev dev DRM device handle.
870 * \param crtc crtc for which timestamp should be returned.
871 * \param *max_error Maximum allowable timestamp error in nanoseconds.
872 * Implementation should strive to provide timestamp
873 * with an error of at most *max_error nanoseconds.
874 * Returns true upper bound on error for timestamp.
875 * \param *vblank_time Target location for returned vblank timestamp.
876 * \param flags 0 = Defaults, no special treatment needed.
877 * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
878 * irq handler. Some drivers need to apply some workarounds
879 * for gpu-specific vblank irq quirks if flag is set.
880 *
881 * \returns
882 * Zero if timestamping isn't supported in current display mode or a
883 * negative number on failure. A positive status code on success,
884 * which describes how the vblank_time timestamp was computed.
885 */
886 int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
887 int *max_error,
888 struct timeval *vblank_time,
889 unsigned flags);
890
891 void (*irq_preinstall)(struct drm_device *);
892 int (*irq_postinstall)(struct drm_device *);
893 void (*irq_uninstall)(struct drm_device *dev);
894
895 uint_t (*irq_handler)(DRM_IRQ_ARGS);
896 int (*vblank_wait)(struct drm_device *, unsigned int *);
897 int (*vblank_wait2)(struct drm_device *, unsigned int *);
898 /* added for intel minimized vblank */
899 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
900 int (*enable_vblank)(struct drm_device *dev, int crtc);
901 void (*disable_vblank)(struct drm_device *dev, int crtc);
902
903 /* Master routines */
904 int (*master_create)(struct drm_device *dev, struct drm_master *master);
905 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
906 /**
907 * master_set is called whenever the minor master is set.
908 * master_drop is called whenever the minor master is dropped.
909 */
910
911 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
912 bool from_open);
913 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
914 bool from_release);
915
916 void (*entervt)(struct drm_device *dev);
917 void (*leavevt)(struct drm_device *dev);
918 void (*agp_support_detect)(struct drm_device *dev, unsigned long flags);
919
920 /*
921 * Driver-specific constructor for drm_gem_objects, to set up
922 * obj->driver_private.
923 *
924 * Returns 0 on success.
925 */
926 int (*gem_init_object) (struct drm_gem_object *obj);
927 void (*gem_free_object) (struct drm_gem_object *obj);
928
929 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
930 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
931 void (*gem_fault) (struct drm_gem_object *obj);
932
933 /* vga arb irq handler */
934 void (*vgaarb_irq)(struct drm_device *dev, bool state);
935
936 /* dumb alloc support */
937 int (*dumb_create)(struct drm_file *file_priv,
938 struct drm_device *dev,
939 struct drm_mode_create_dumb *args);
940 int (*dumb_map_offset)(struct drm_file *file_priv,
941 struct drm_device *dev, uint32_t handle,
942 uint64_t *offset);
943 int (*dumb_destroy)(struct drm_file *file_priv,
944 struct drm_device *dev,
945 uint32_t handle);
946
947 int major;
948 int minor;
949 int patchlevel;
950 char *name;
951 char *desc;
952 char *date;
953
954 u32 driver_features;
955 drm_ioctl_desc_t *ioctls;
956 int num_ioctls;
957
958 int buf_priv_size;
959
960 unsigned use_agp :1;
961 unsigned require_agp :1;
962 unsigned use_sg :1;
963 unsigned use_dma :1;
964 unsigned use_pci_dma :1;
965 unsigned use_dma_queue :1;
966 unsigned use_irq :1;
967 unsigned use_vbl_irq :1;
968 unsigned use_vbl_irq2 :1;
969 unsigned use_mtrr :1;
970 unsigned use_gem;
971 unsigned use_kms;
972
973 struct drm_pci_id_list *id_table;
974 };
975 #include "drm_crtc.h"
976 struct drm_master {
977
978 struct kref refcount; /* refcount for this master */
979
980 struct list_head head; /**< each minor contains a list of masters */
981 struct drm_minor *minor; /**< link back to minor we are a master for */
982
983 char *unique; /**< Unique identifier: e.g., busid */
984 int unique_len; /**< Length of unique field */
985 int unique_size; /**< amount allocated */
986
987 int blocked; /**< Blocked due to VC switch? */
988
989 /** \name Authentication */
990 /*@{ */
991 drm_magic_head_t magiclist[DRM_HASH_SIZE];
992 /*@} */
993
994 struct drm_lock_data lock; /**< Information on hardware lock */
995
996 void *driver_priv; /**< Private structure for driver to use */
997 };
998
999 struct drm_minor {
1000 int index; /**< Minor device number */
1001 int type; /**< Control or render */
1002 dev_t device;
1003 struct drm_device *dev;
1004 struct drm_master *master; /* currently active master for this node */
1005 struct list_head master_list;
1006 struct drm_mode_group mode_group;
1007
1008 char name[32];
1009 struct idr clone_idr;
1010 void *private;
1011 };
1012
1013 /* mode specified on the command line */
1014 struct drm_cmdline_mode {
1015 bool specified;
1016 bool refresh_specified;
1017 bool bpp_specified;
1018 int xres, yres;
1019 int bpp;
1020 int refresh;
1021 bool rb;
1022 bool interlace;
1023 bool cvt;
1024 bool margins;
1025 enum drm_connector_force force;
1026 };
1027
1028 struct drm_pending_vblank_event {
1029 struct drm_pending_event base;
1030 int pipe;
1031 struct drm_event_vblank event;
1032 };
1033
1034 struct drm_file {
1035 TAILQ_ENTRY(drm_file) link;
1036
1037 int authenticated;
1038 pid_t pid;
1039 uid_t uid;
1040 drm_magic_t magic;
1041 unsigned long ioctl_count;
1042 struct list_head lhead;
1043 struct drm_minor *minor;
1044 unsigned long lock_count;
1045
1046 /** Mapping of mm object handles to object pointers. */
1047 struct idr_list object_idr;
1048 /** Lock for synchronization of access to object_idr. */
1049 spinlock_t table_lock;
1050
1051 void *driver_priv;
1052
1053 int is_master; /* this file private is a master for a minor */
1054 struct drm_master *master; /* master this node is currently associated with
1055 N.B. not always minor->master */
1056
1057 /**
1058 * fbs - List of framebuffers associated with this file.
1059 *
1060 * Protected by fbs_lock. Note that the fbs list holds a reference on
1061 * the fb object to prevent it from untimely disappearing.
1062 */
1063 struct list_head fbs;
1064 struct mutex fbs_lock;
1065
1066 wait_queue_head_t event_wait;
1067 struct list_head event_list;
1068 int event_space;
1069 struct pollhead drm_pollhead;
1070 };
1071
1072 /*
1073 * hardware-specific code needs to initialize mutexes which
1074 * can be used in interrupt context, so they need to know
1075 * the interrupt priority. Interrupt cookie in drm_device
1076 * structure is the intr_block field.
1077 */
1078 #define DRM_INTR_PRI(dev) \
1079 DDI_INTR_PRI((dev)->pdev->intr_block)
1080
1081 struct drm_device {
1082 int if_version; /**< Highest interface version set */
1083
1084 /** \name Locks */
1085 /*@{ */
1086 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
1087 kmutex_t struct_mutex; /* < For others */
1088 /*@} */
1089
1090 /** \name Usage Counters */
1091 /*@{ */
1092 int open_count; /**< Outstanding files open */
1093 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
1094 int buf_use; /**< Buffers in use -- cannot alloc */
1095 atomic_t buf_alloc; /**< Buffer allocation in progress */
1096 /*@} */
1097
1098 /** \name Performance counters */
1099 /*@{ */
1100 unsigned long counters;
1101 enum drm_stat_type types[15];
1102 atomic_t counts[15];
1103 /*@} */
1104
1105 struct list_head filelist;
1106
1107 /** \name Memory management */
1108 /*@{ */
1109 struct list_head maplist; /**< Linked list of regions */
1110 /*@} */
1111
1112 /** \name Context handle management */
1113 /*@{ */
1114 struct list_head ctxlist; /**< Linked list of context handles */
1115 int ctx_count; /**< Number of context handles */
1116 struct mutex ctxlist_mutex; /**< For ctxlist */
1117
1118 struct idr ctx_idr;
1119
1120 /*@} */
1121
1122 /** \name DMA queues (contexts) */
1123 /*@{ */
1124 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
1125 /*@} */
1126
1127 /** \name Context support */
1128 /*@{ */
1129 int irq_enabled; /* True if the irq handler is enabled */
1130 atomic_t context_flag; /* Context swapping flag */
1131 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
1132 int last_context; /* Last current context */
1133 unsigned long last_switch; /**< jiffies at last context switch */
1134 /*@} */
1135
1136 struct workqueue_struct *drm_wq;
1137 struct work_struct work;
1138 /** \name VBLANK IRQ support */
1139 /*@{ */
1140
1141 /*
1142 * At load time, disabling the vblank interrupt won't be allowed since
1143 * old clients may not call the modeset ioctl and therefore misbehave.
1144 * Once the modeset ioctl *has* been called though, we can safely
1145 * disable them when unused.
1146 */
1147 int vblank_disable_allowed;
1148
1149 wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */
1150 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
1151 struct timeval *_vblank_time; /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
1152 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
1153 spinlock_t vbl_lock;
1154 atomic_t *vblank_refcount; /* number of users of vblank interruptsper crtc */
1155 u32 *last_vblank; /* protected by dev->vbl_lock, used */
1156 /* for wraparound handling */
1157 int *vblank_enabled; /* so we don't call enable more than
1158 once per disable */
1159 int *vblank_inmodeset; /* Display driver is setting mode */
1160 u32 *last_vblank_wait; /* Last vblank seqno waited per CRTC */
1161 struct timer_list vblank_disable_timer;
1162
1163 u32 max_vblank_count; /**< size of vblank counter register */
1164
1165 /**
1166 * List of events
1167 */
1168 struct list_head vblank_event_list;
1169 spinlock_t event_lock;
1170
1171 /*@} */
1172
1173 struct drm_agp_head *agp; /**< AGP data */
1174 ulong_t agp_aperbase;
1175
1176 struct device *dev; /**< Device structure */
1177 struct pci_dev *pdev; /**< PCI device structure */
1178 int pci_vendor; /**< PCI vendor id */
1179 int pci_device; /**< PCI device id */
1180
1181 struct drm_sg_mem *sg; /**< Scatter gather memory */
1182 unsigned int num_crtcs; /**< Number of CRTCs on this device */
1183 void *dev_private; /**< device private data */
1184 void *mm_private;
1185 struct drm_driver *driver;
1186 struct drm_local_map *agp_buffer_map;
1187 unsigned int agp_buffer_token;
1188 struct drm_minor *control; /**< Control node for card */
1189 struct drm_minor *primary; /**< render type primary screen head */
1190
1191 struct drm_mode_config mode_config; /**< Current mode config */
1192 struct work_struct output_poll_work;
1193 struct timer_list output_poll_timer;
1194
1195 /* \name GEM information */
1196 /* @{ */
1197 kmutex_t object_name_lock;
1198 struct idr_list object_name_idr;
1199 /* @} */
1200 int switch_power_state;
1201
1202 /* OSOL Begin*/
1203 dev_info_t *devinfo;
1204 struct drm_minor *vgatext;
1205 struct drm_minor *agpmaster;
1206
1207 struct idr map_idr;
1208
1209 /* Locks */
1210 kmutex_t dma_lock; /* protects dev->dma */
1211 kmutex_t irq_lock; /* protects irq condition checks */
1212
1213 kmutex_t page_fault_lock;
1214
1215 kstat_t *asoft_ksp; /* kstat support */
1216
1217 struct list_head gem_objects_list;
1218 spinlock_t track_lock;
1219
1220 uint32_t *old_gtt;
1221 size_t old_gtt_size;
1222 uint32_t *gtt_dump;
1223
1224 /*
1225 * FMA capabilities
1226 */
1227 int drm_fm_cap;
1228 /* OSOL End */
1229 };
1230
1231 #define DRM_SWITCH_POWER_ON 0
1232 #define DRM_SWITCH_POWER_OFF 1
1233 #define DRM_SWITCH_POWER_CHANGING 2
1234
drm_core_check_feature(struct drm_device * dev,int feature)1235 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1236 int feature)
1237 {
1238 return ((dev->driver->driver_features & feature) ? 1 : 0);
1239 }
1240 #if __OS_HAS_AGP
drm_core_has_AGP(struct drm_device * dev)1241 static inline int drm_core_has_AGP(struct drm_device *dev)
1242 {
1243 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1244 }
1245 #else
1246 #define drm_core_has_AGP(dev) (0)
1247 #endif
1248
1249 extern struct idr drm_minors_idr;
1250 extern struct cb_ops drm_cb_ops;
1251
1252 void *drm_alloc(size_t, int);
1253 void *drm_calloc(size_t, size_t, int);
1254 void *drm_realloc(void *, size_t, size_t, int);
1255 void drm_free(void *, size_t, int);
1256 int drm_ioremap(drm_device_t *, drm_local_map_t *);
1257 void drm_ioremapfree(drm_local_map_t *);
1258 void *drm_sun_ioremap(uint64_t paddr, size_t size, uint32_t mode);
1259 void drm_sun_iounmap(void *addr);
1260 void drm_core_ioremap(struct drm_local_map *, struct drm_device *);
1261 void drm_core_ioremapfree(struct drm_local_map *, struct drm_device *);
1262
1263 void drm_pci_free(drm_dma_handle_t *);
1264 void *drm_pci_alloc(drm_device_t *, size_t, size_t, dma_addr_t, int);
1265
1266 int drm_ctxbitmap_init(drm_device_t *);
1267 void drm_ctxbitmap_cleanup(drm_device_t *);
1268 void drm_ctxbitmap_free(drm_device_t *, int);
1269
1270 /* Locking IOCTL support (drm_lock.c) */
1271 int drm_lock_take(struct drm_lock_data *, unsigned int);
1272 int drm_lock_free(struct drm_lock_data *, unsigned int);
1273 int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1274
1275 /* Buffer management support (drm_bufs.c) */
1276 extern int drm_map_handle(struct drm_device *dev, struct drm_map_list *list);
1277 unsigned long drm_get_resource_start(drm_device_t *, unsigned int);
1278 unsigned long drm_get_resource_len(drm_device_t *, unsigned int);
1279 int drm_initmap(drm_device_t *, unsigned long, unsigned long,
1280 unsigned int, int, int);
1281 extern int drm_rmmap(struct drm_device *, struct drm_local_map *);
1282 extern int drm_addmap(struct drm_device *, unsigned long, unsigned long,
1283 enum drm_map_type, enum drm_map_flags, struct drm_local_map **);
1284 int drm_order(unsigned long);
1285 int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
1286
1287 /* DMA support (drm_dma.c) */
1288 int drm_dma_setup(drm_device_t *);
1289 void drm_dma_takedown(drm_device_t *);
1290 void drm_free_buffer(drm_device_t *, drm_buf_t *);
1291 void drm_core_reclaim_buffers(drm_device_t *, drm_file_t *);
1292 #define drm_reclaim_buffers drm_core_reclaim_buffers
1293
1294 /* IRQ support (drm_irq.c) */
1295 int drm_irq_install(drm_device_t *);
1296 int drm_irq_uninstall(drm_device_t *);
1297 uint_t drm_irq_handler(DRM_IRQ_ARGS);
1298 void drm_driver_irq_preinstall(drm_device_t *);
1299 void drm_driver_irq_postinstall(drm_device_t *);
1300 void drm_driver_irq_uninstall(drm_device_t *);
1301 int drm_vblank_wait(drm_device_t *, unsigned int *);
1302 u32 drm_vblank_count(struct drm_device *dev, int crtc);
1303 u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1304 struct timeval *vblanktime);
1305 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1306 struct drm_pending_vblank_event *e);
1307 bool drm_handle_vblank(struct drm_device *dev, int crtc);
1308 int drm_vblank_get(struct drm_device *dev, int crtc);
1309 void drm_vblank_put(struct drm_device *dev, int crtc);
1310 void drm_vblank_off(struct drm_device *dev, int crtc);
1311 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1312 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1313 void drm_vblank_cleanup(struct drm_device *dev);
1314 u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1315 struct timeval *tvblank, unsigned flags);
1316 int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1317 int crtc, int *max_error,
1318 struct timeval *vblank_time,
1319 unsigned flags,
1320 struct drm_crtc *refcrtc);
1321 void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1322
1323 extern struct drm_display_mode *
1324 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
1325 struct drm_cmdline_mode *cmd);
1326
1327 /* Modesetting support */
1328 int drm_modeset_ctl(DRM_IOCTL_ARGS);
1329 void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1330 void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1331 int pci_enable_msi(struct pci_dev *pdev);
1332 void pci_disable_msi(struct pci_dev *pdev);
1333 /* AGP/GART support (drm_agpsupport.h) */
1334 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1335 extern int drm_agp_acquire(struct drm_device *dev);
1336 extern int drm_agp_acquire_ioctl(DRM_IOCTL_ARGS);
1337 extern int drm_agp_release(struct drm_device *dev);
1338 extern int drm_agp_release_ioctl(DRM_IOCTL_ARGS);
1339 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1340 extern int drm_agp_enable_ioctl(DRM_IOCTL_ARGS);
1341 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1342 extern int drm_agp_info_ioctl(DRM_IOCTL_ARGS);
1343 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1344 extern int drm_agp_alloc_ioctl(DRM_IOCTL_ARGS);
1345 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1346 extern int drm_agp_free_ioctl(DRM_IOCTL_ARGS);
1347 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1348 extern int drm_agp_unbind_ioctl(DRM_IOCTL_ARGS);
1349 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1350 extern int drm_agp_bind_ioctl(DRM_IOCTL_ARGS);
1351 extern void *drm_agp_allocate_memory(size_t pages, uint32_t type, struct drm_device *dev);
1352 extern int drm_agp_free_memory(agp_allocate_t *handle, drm_device_t *dev);
1353 extern int drm_agp_bind_memory(unsigned int, uint32_t, drm_device_t *dev);
1354 extern int drm_agp_unbind_memory(unsigned long, drm_device_t *dev);
1355 extern void drm_agp_chipset_flush(struct drm_device *dev);
1356
1357 extern void drm_agp_cleanup(drm_device_t *);
1358 extern int drm_agp_bind_pages(struct drm_device *dev, pfn_t *pages,
1359 unsigned long num_pages, uint32_t gtt_offset, unsigned int agp_type);
1360 extern int drm_agp_unbind_pages(struct drm_device *dev, pfn_t *pages,
1361 unsigned long num_pages, uint32_t gtt_offset, pfn_t scratch, uint32_t type);
1362 extern int drm_agp_rw_gtt(struct drm_device *dev, unsigned long num_pages,
1363 uint32_t gtt_offset, void *gttp, uint32_t type);
1364
1365 /* kstat support (drm_kstats.c) */
1366 int drm_init_kstats(drm_device_t *);
1367 void drm_fini_kstats(drm_device_t *);
1368
1369 /* Scatter Gather Support (drm_scatter.c) */
1370 extern void drm_sg_cleanup(drm_sg_mem_t *);
1371
1372 /* ATI PCIGART support (ati_pcigart.c) */
1373 int drm_ati_pcigart_init(drm_device_t *, drm_ati_pcigart_info *);
1374 int drm_ati_pcigart_cleanup(drm_device_t *, drm_ati_pcigart_info *);
1375
1376 /* Locking IOCTL support (drm_lock.h) */
1377 extern int drm_lock(DRM_IOCTL_ARGS);
1378 extern int drm_unlock(DRM_IOCTL_ARGS);
1379 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1380 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1381 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1382 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1383
1384 int drm_setversion(DRM_IOCTL_ARGS);
1385 struct drm_local_map *drm_getsarea(struct drm_device *dev);
1386 /* Cache management (drm_cache.c) */
1387 void drm_clflush_pages(caddr_t *pages, unsigned long num_pages);
1388
1389 /* Misc. IOCTL support (drm_ioctl.c) */
1390 int drm_irq_by_busid(DRM_IOCTL_ARGS);
1391 int drm_getunique(DRM_IOCTL_ARGS);
1392 int drm_setunique(DRM_IOCTL_ARGS);
1393 int drm_getmap(DRM_IOCTL_ARGS);
1394 int drm_getclient(DRM_IOCTL_ARGS);
1395 int drm_getstats(DRM_IOCTL_ARGS);
1396 int drm_getcap(DRM_IOCTL_ARGS);
1397 int drm_noop(DRM_IOCTL_ARGS);
1398
1399 /* Context IOCTL support (drm_context.c) */
1400 int drm_resctx(DRM_IOCTL_ARGS);
1401 int drm_addctx(DRM_IOCTL_ARGS);
1402 int drm_modctx(DRM_IOCTL_ARGS);
1403 int drm_getctx(DRM_IOCTL_ARGS);
1404 int drm_switchctx(DRM_IOCTL_ARGS);
1405 int drm_newctx(DRM_IOCTL_ARGS);
1406 int drm_rmctx(DRM_IOCTL_ARGS);
1407 int drm_setsareactx(DRM_IOCTL_ARGS);
1408 int drm_getsareactx(DRM_IOCTL_ARGS);
1409
1410 /* Drawable IOCTL support (drm_drawable.c) */
1411 int drm_adddraw(DRM_IOCTL_ARGS);
1412 int drm_rmdraw(DRM_IOCTL_ARGS);
1413 int drm_update_drawable_info(DRM_IOCTL_ARGS);
1414 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1415 drm_drawable_t id);
1416 void drm_drawable_free_all(struct drm_device *dev);
1417
1418
1419 /* Authentication IOCTL support (drm_auth.h) */
1420 int drm_getmagic(DRM_IOCTL_ARGS);
1421 int drm_authmagic(DRM_IOCTL_ARGS);
1422 int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1423
1424 /* Buffer management support (drm_bufs.c) */
1425 int drm_addmap_ioctl(DRM_IOCTL_ARGS);
1426 int drm_rmmap_ioctl(DRM_IOCTL_ARGS);
1427 int drm_addbufs(DRM_IOCTL_ARGS);
1428 int drm_infobufs(DRM_IOCTL_ARGS);
1429 int drm_markbufs(DRM_IOCTL_ARGS);
1430 int drm_freebufs(DRM_IOCTL_ARGS);
1431 int drm_mapbufs(DRM_IOCTL_ARGS);
1432
1433 /* IRQ support (drm_irq.c) */
1434 int drm_control(DRM_IOCTL_ARGS);
1435 int drm_wait_vblank(DRM_IOCTL_ARGS);
1436
1437 /* Scatter Gather Support (drm_scatter.c) */
1438 int drm_sg_alloc_ioctl(DRM_IOCTL_ARGS);
1439 int drm_sg_free(DRM_IOCTL_ARGS);
1440
1441 extern int drm_debug_flag;
1442 extern int mdb_track_enable;
1443
1444 extern struct list_head drm_iomem_list;
1445
1446 #define MDB_TRACK_ENABLE mdb_track_enable
1447
1448 #define TRACE_GEM_OBJ_HISTORY(obj, str) \
1449 do { \
1450 if (MDB_TRACK_ENABLE) { \
1451 int seq_t = 0; \
1452 if (obj->ring) \
1453 seq_t = obj->ring->get_seqno(obj->ring, true); \
1454 drm_gem_object_track(&obj->base, str, \
1455 seq_t, 0, \
1456 (void *)obj->ring); \
1457 } \
1458 } while (*"\0")
1459
1460 /* We add function to support DRM_DEBUG,DRM_ERROR,DRM_INFO */
1461 /* PRINTFLIKE4 */
1462 extern void drm_debug_print(int cmn_err, const char* func, int line, const char *fmt, ...);
1463 /* PRINTFLIKE1 */
1464 extern void drm_debug(const char *fmt, ...);
1465 /* PRINTFLIKE1 */
1466 extern void drm_error(const char *fmt, ...);
1467 /* PRINTFLIKE1 */
1468 extern void drm_info(const char *fmt, ...);
1469
1470 #ifdef DEBUG
1471 #define DRM_DEBUG(...) \
1472 do { \
1473 if (drm_debug_flag & 0x08) \
1474 drm_debug_print( \
1475 CE_NOTE, __func__, __LINE__, ##__VA_ARGS__); \
1476 } while (__lintzero)
1477 #define DRM_DEBUG_KMS(...) \
1478 do { \
1479 if (drm_debug_flag & 0x04) \
1480 drm_debug_print( \
1481 CE_NOTE, __func__, __LINE__, ##__VA_ARGS__); \
1482 } while (__lintzero)
1483 #define DRM_DEBUG_DRIVER(...) \
1484 do { \
1485 if (drm_debug_flag & 0x02) \
1486 drm_debug_print( \
1487 CE_NOTE, __func__, __LINE__, ##__VA_ARGS__); \
1488 } while (__lintzero)
1489 #define DRM_INFO(...) \
1490 do { \
1491 if (drm_debug_flag & 0x01) \
1492 drm_debug_print( \
1493 CE_NOTE, __func__, __LINE__, ##__VA_ARGS__); \
1494 } while (__lintzero)
1495 #else
1496 #define DRM_DEBUG(...) do { } while (__lintzero)
1497 #define DRM_DEBUG_KMS(...) do { } while (__lintzero)
1498 #define DRM_DEBUG_DRIVER(...) do { } while (__lintzero)
1499 #define DRM_INFO(...) do { } while (__lintzero)
1500 #endif
1501
1502 #define DRM_ERROR(...) \
1503 drm_debug_print(CE_WARN, __func__, __LINE__, ##__VA_ARGS__)
1504
1505 #define DRM_LOG_KMS DRM_INFO
1506
1507 extern int drm_lastclose(struct drm_device *dev);
1508
1509 extern int drm_open(struct drm_minor *, int, int, cred_t *);
1510 extern int drm_release(struct drm_file *);
1511 extern ssize_t drm_read(struct drm_file *, struct uio *);
1512 extern short drm_poll(struct drm_file *, short);
1513 extern int drm_init(struct drm_device *, struct drm_driver *);
1514 extern void drm_exit(struct drm_device *);
1515 extern void drm_fm_init(struct drm_device *dev);
1516 extern void drm_fm_fini(struct drm_device *dev);
1517 extern void drm_fm_ereport(struct drm_device *dev, char *detail);
1518 extern int drm_check_dma_handle(struct drm_device *dev, ddi_dma_handle_t handle);
1519 extern int drm_check_acc_handle(struct drm_device *dev, ddi_acc_handle_t handle);
1520 extern int drm_ioctl(dev_t dev_id, struct drm_file *file_priv,
1521 int cmd, intptr_t arg, int mode, cred_t *credp);
1522
1523 extern int drm_put_minor(struct drm_minor **minor_p);
1524
1525 extern int drm_setmaster_ioctl(DRM_IOCTL_ARGS);
1526 extern int drm_dropmaster_ioctl(DRM_IOCTL_ARGS);
1527 extern struct drm_master *drm_master_create(struct drm_minor *minor);
1528 extern struct drm_master *drm_master_get(struct drm_master *master);
1529 extern void drm_master_put(struct drm_master **master);
1530 extern int drm_get_dev(struct drm_device *dev, struct pci_dev *pdev,
1531 struct drm_driver *driver, unsigned long driver_data);
1532 extern void drm_put_dev(struct drm_device *dev);
1533
1534 void drm_master_release(struct drm_device *dev, struct drm_file *fpriv);
1535
1536 extern unsigned int drm_vblank_offdelay;
1537 extern unsigned int drm_timestamp_precision;
1538
1539 /* sysfs support (drm_sysfs.c) */
1540 extern int drm_sysfs_device_add(struct drm_minor *minor);
1541 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1542
1543 /* Graphics Execution Manager library functions (drm_gem.c) */
1544 int drm_gem_init(struct drm_device *dev);
1545 void drm_gem_destroy(struct drm_device *dev);
1546 void drm_gem_object_release(struct drm_gem_object *obj);
1547 void drm_gem_object_free(struct kref *kref);
1548 void drm_gem_object_free_unlocked(struct kref *kref);
1549 struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1550 size_t size);
1551 int drm_gem_object_init(struct drm_device *dev,
1552 struct drm_gem_object *obj, size_t size, int gen);
1553 int drm_gem_private_object_init(struct drm_device *dev,
1554 struct drm_gem_object *obj, size_t size);
1555 void drm_gem_object_handle_free(struct drm_gem_object *obj);
1556
1557 extern void
1558 drm_gem_object_reference(struct drm_gem_object *obj);
1559
1560 extern void
1561 drm_gem_object_unreference(struct drm_gem_object *obj);
1562
1563 extern void
1564 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj);
1565
1566 int drm_gem_handle_create(struct drm_file *file_priv,
1567 struct drm_gem_object *obj,
1568 u32 *handlep);
1569 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1570
1571 extern void
1572 drm_gem_object_handle_reference(struct drm_gem_object *obj);
1573
1574 extern void
1575 drm_gem_object_handle_unreference(struct drm_gem_object *obj);
1576
1577 extern void
1578 drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj);
1579
1580 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1581 struct drm_file *filp,
1582 u32 handle);
1583 int drm_gem_close_ioctl(DRM_IOCTL_ARGS);
1584 int drm_gem_flink_ioctl(DRM_IOCTL_ARGS);
1585 int drm_gem_open_ioctl(DRM_IOCTL_ARGS);
1586 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1587 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1588 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1589 void drm_gem_mmap(struct drm_gem_object *obj, pfn_t pfn);
1590 void drm_gem_release_mmap(struct drm_gem_object *obj);
1591 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1592
1593 extern struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1594 unsigned int token);
1595
1596 #ifdef NEVER
drm_device_is_pcie(struct drm_device * dev)1597 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1598 {
1599 return 0;
1600 }
1601 #endif
1602
1603 void drm_gem_object_track(struct drm_gem_object *obj, const char *name,
1604 uint32_t cur_seq, uint32_t last_seq, void* ptr);
1605
1606 #endif /* _DRMP_H */
1607