2 Copyright 2009-2010, The AROS Development Team. All rights reserved.
7 * This file incorporates work covered by the following copyright and
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * All rights reserved.
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice (including the next
22 * paragraph) shall be included in all copies or substantial portions of the
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
29 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31 * OTHER DEALINGS IN THE SOFTWARE.
39 #include <aros/debug.h>
43 #include "drm_aros_config.h"
44 #include "drm_compat_funcs.h"
45 #include "drm_redefines.h"
53 #define DRM_ERROR(fmt, ...) bug("[" DRM_NAME "(ERROR):%s] " fmt, __func__ , ##__VA_ARGS__)
54 #define DRM_DEBUG(fmt, ...) D(bug("[" DRM_NAME "(DEBUG):%s] " fmt, __func__ , ##__VA_ARGS__))
55 #define DRM_DEBUG_KMS(fmt, ...) D(bug("[" DRM_NAME "(DEBUG):%s] " fmt, __func__ , ##__VA_ARGS__))
56 #define DRM_IMPL(fmt, ...) bug("------IMPLEMENT(%s): " fmt, __func__ , ##__VA_ARGS__)
57 #define DRM_INFO(fmt, ...) bug("[" DRM_NAME "(INFO)] " fmt, ##__VA_ARGS__)
58 #define DRM_DEBUG_DRIVER DRM_DEBUG
62 * DRM_READMEMORYBARRIER() prevents reordering of reads.
63 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
64 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
68 #define DRM_READMEMORYBARRIER() __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
69 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
70 #define DRM_MEMORYBARRIER() __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
72 #error IMPLEMENT momory bariers for non-x86
76 #define DRM_COPY_FROM_USER(to, from, size) copy_from_user(to, from, size)
77 #define DRM_COPY_TO_USER(to , from, size) copy_to_user(to, from, size)
78 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
79 #define DRM_UDELAY(d) udelay(d)
80 #define DRM_CURRENTPID 1
81 #define DRM_IRQ_ARGS void *arg
82 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
83 typedef int irqreturn_t
;
90 struct drm_gem_object
;
92 typedef int drm_ioctl_t(struct drm_device
*dev
, void *data
,
93 struct drm_file
*file_priv
);
96 #define DRM_MASTER 0x2
97 #define DRM_ROOT_ONLY 0x4
98 #define DRM_CONTROL_ALLOW 0x8
99 #define DRM_UNLOCKED 0x10
101 struct drm_ioctl_desc
106 unsigned int cmd_drv
;
110 * Creates a driver or general drm_ioctl_desc array entry for the given
111 * ioctl, for use by drm_ioctl().
113 #define DRM_IOCTL_NR(n) ((n) & 0xff)
114 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
115 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
118 /* Memory management */
121 resource_size_t offset
; /* Requested physical address (0 for SAREA)*/
122 unsigned long size
; /* Requested physical size (bytes) */
123 enum drm_map_type type
; /* Type of memory to map */
124 enum drm_map_flags flags
; /* Flags */
125 void *handle
; /* Memory address */
126 int mtrr
; /* MTRR slot used */
129 typedef struct drm_local_map drm_local_map_t
;
133 struct list_head head
; /* list head */
134 /* FIXME: Commented out fields */
135 // struct drm_hash_item hash;
136 struct drm_local_map
*map
; /* mapping */
138 struct drm_master
*master
;
139 struct drm_mm_node
*file_offset_node
; /* fake offset */
143 unsigned long handle
;
146 #if !defined(__AROS__)
147 struct page
**pagelist
;
154 #define DRM_AGP_KERN struct agp_kern_info
155 #define DRM_AGP_MEM struct agp_memory
160 struct list_head head
;
163 struct drm_agp_head
{
164 DRM_AGP_KERN agp_info
; /* AGP device information */
165 struct list_head memory
;
166 unsigned long mode
; /* AGP mode */
167 struct agp_bridge_data
*bridge
;
168 int enabled
; /* whether the AGP bus as been enabled */
169 int acquired
; /* whether the AGP device has been acquired */
172 int cant_use_aperture
;
173 unsigned long page_mask
;
182 #include "drm_crtc.h"
184 /* Contains a collection of functions common to each drm driver */
186 #define DRIVER_USE_AGP 0x1
187 #define DRIVER_REQUIRE_AGP 0x2
188 #define DRIVER_GEM 0x1000
189 #define DRIVER_MODESET 0x2000
191 /* Size of ringbuffer for vblank timestamps. Just double-buffer
192 * in initial implementation.
194 #define DRM_VBLANKTIME_RBSIZE 2
196 /* Flags and return codes for get_vblank_timestamp() driver function. */
197 #define DRM_CALLED_FROM_VBLIRQ 1
198 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
199 #define DRM_VBLANKTIME_INVBL (1 << 1)
201 /* get_scanout_position() return flags */
202 #define DRM_SCANOUTPOS_VALID (1 << 0)
203 #define DRM_SCANOUTPOS_INVBL (1 << 1)
204 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
211 UWORD SubSystemVendorID
;
212 UWORD SubSystemProductID
;
213 struct drm_pciid
*PciIDs
;
214 OOP_Object
*pciDevice
;
219 struct drm_device
*dev
;
221 int (*load
)(struct drm_device
*, unsigned long);
222 int (*firstopen
)(struct drm_device
*);
223 int (*open
) (struct drm_device
*, struct drm_file
*);
224 void (*preclose
)(struct drm_device
*dev
, struct drm_file
*);
225 void (*postclose
) (struct drm_device
*, struct drm_file
*);
226 void (*lastclose
)(struct drm_device
*);
227 int (*unload
)(struct drm_device
*);
230 irqreturn_t (*irq_handler
)(DRM_IRQ_ARGS
);
231 void (*irq_preinstall
)(struct drm_device
*);
232 int (*irq_postinstall
)(struct drm_device
*);
233 void (*irq_uninstall
)(struct drm_device
*);
236 int (*gem_init_object
) (struct drm_gem_object
*obj
);
237 void (*gem_free_object
) (struct drm_gem_object
*obj
);
238 void (*gem_free_object_unlocked
) (struct drm_gem_object
*obj
);
240 int version_patchlevel
;
241 unsigned int driver_features
;
242 struct drm_ioctl_desc
*ioctls
;
247 struct list_head maplist
; /* Linked list of regions */
249 int irq_enabled
; /* True if irq handler is enabled */
250 int pci_vendor
; /* PCI vendor id */
251 int pci_device
; /* PCI device id */
253 struct drm_agp_head
*agp
; /* AGP data */
255 struct drm_driver
*driver
; /* Driver functions */
256 void *dev_private
; /* Device private data */
257 struct mutex struct_mutex
;
259 struct address_space
*dev_mapping
;
260 struct drm_mode_config mode_config
;
262 /* GEM information */
263 spinlock_t object_name_lock
;
264 struct idr object_name_idr
;
265 uint32_t invalidate_domains
; /* domains pending invalidation */
266 uint32_t flush_domains
; /* domains pending flush */
268 /* AROS specific fields */
270 HIDDT_IRQ_Handler
*IntHandler
;
273 static __inline__
int drm_core_check_feature(struct drm_device
*dev
,
276 return ((dev
->driver
->driver_features
& feature
) ? 1 : 0);
279 typedef struct drm_dma_handle
{
287 struct idr object_idr
;
288 spinlock_t table_lock
;
290 struct list_head fbs
;
293 struct drm_gem_object
{
294 /** Reference count of this object */
295 struct kref refcount
;
297 /** Handle count of this object. Each handle also holds a reference */
298 atomic_t handle_count
; /* number of handles on this object */
300 /** Related drm device */
301 struct drm_device
*dev
;
303 /** File representing the shmem storage */
306 /* Mapping info for this object */
307 struct drm_map_list map_list
;
310 * Size of the object, in bytes. Immutable over the object's
316 * Global name for this object, starts at 1. 0 means unnamed.
317 * Access is covered by the object_name_lock in the related drm_device
322 * Memory domains. These monitor which caches contain read/write data
323 * related to the object. When transitioning from one set of domains
324 * to another, the driver is called to ensure that caches are suitably
325 * flushed and invalidated
327 uint32_t read_domains
;
328 uint32_t write_domain
;
331 * While validating an exec operation, the
332 * new read/write domain values are computed here.
333 * They will be transferred to the above values
334 * at the point that any cache flushing occurs
336 uint32_t pending_read_domains
;
337 uint32_t pending_write_domain
;
339 void *driver_private
;
342 static inline int drm_core_has_AGP(struct drm_device
*dev
)
344 return drm_core_check_feature(dev
, DRIVER_USE_AGP
);
347 static __inline__
int drm_device_is_agp(struct drm_device
*dev
)
349 return dev
->driver
->IsAGP
;
352 static __inline__
int drm_device_is_pcie(struct drm_device
*dev
)
354 return dev
->driver
->IsPCIE
;
357 static __inline__
void *drm_calloc_large(size_t nmemb
, size_t size
)
359 return AllocVec(nmemb
* size
, MEMF_ANY
| MEMF_CLEAR
);
362 static __inline__
void drm_free_large(void *ptr
)
368 int drm_order(unsigned long size
);
369 resource_size_t
drm_get_resource_len(struct drm_device
*dev
,
370 unsigned int resource
);
371 resource_size_t
drm_get_resource_start(struct drm_device
*dev
,
372 unsigned int resource
);
376 void drm_exit(struct drm_driver
*driver
);
377 int drm_init(struct drm_driver
*driver
);
380 int drm_irq_install(struct drm_device
*dev
);
381 int drm_irq_uninstall(struct drm_device
*dev
);
383 int drm_vblank_init(struct drm_device
*dev
, int num_crtcs
);
384 void drm_vblank_cleanup(struct drm_device
*dev
);
385 void drm_vblank_pre_modeset(struct drm_device
*dev
, int crtc
);
386 void drm_vblank_post_modeset(struct drm_device
*dev
, int crtc
);
387 int drm_vblank_get(struct drm_device
*dev
, int crtc
);
388 void drm_vblank_put(struct drm_device
*dev
, int crtc
);
389 void drm_handle_vblank(struct drm_device
*dev
, int crtc
);
390 u32
drm_vblank_count(struct drm_device
*dev
, int crtc
);
393 drm_dma_handle_t
*drm_pci_alloc(struct drm_device
*dev
, size_t size
,
394 size_t align
, dma_addr_t maxaddr
);
395 void drm_pci_free(struct drm_device
* dev
, drm_dma_handle_t
* dmah
);
398 void drm_core_ioremap(struct drm_local_map
*map
, struct drm_device
*dev
);
399 void drm_core_ioremap_wc(struct drm_local_map
*map
, struct drm_device
*dev
);
400 void drm_core_ioremapfree(struct drm_local_map
*map
, struct drm_device
*dev
);
401 int drm_unbind_agp(DRM_AGP_MEM
* handle
);
402 void drm_free_agp(DRM_AGP_MEM
* handle
, int pages
);
404 /* drm_agpsupport.c */
405 struct drm_agp_head
*drm_agp_init(struct drm_device
*dev
);
406 int drm_agp_acquire(struct drm_device
*dev
);
407 int drm_agp_release(struct drm_device
*dev
);
408 int drm_agp_enable(struct drm_device
*dev
, struct drm_agp_mode mode
);
409 int drm_agp_info(struct drm_device
*dev
, struct drm_agp_info
*info
);
410 int drm_agp_free_memory(DRM_AGP_MEM
* handle
);
411 int drm_agp_unbind_memory(DRM_AGP_MEM
* handle
);
412 void drm_agp_chipset_flush(struct drm_device
*dev
);
413 DRM_AGP_MEM
* drm_agp_bind_pages(struct drm_device
*dev
, struct page
**pages
,
414 unsigned long num_pages
, uint32_t gtt_offset
, u32 type
);
417 void drm_clflush_pages(struct page
*pages
[], unsigned long num_pages
);
420 int drm_gem_init(struct drm_device
*dev
);
421 void drm_gem_object_release(struct drm_gem_object
*obj
);
422 void drm_gem_object_free(struct kref
*kref
);
423 void drm_gem_object_free_unlocked(struct kref
*kref
);
424 void drm_gem_object_handle_free(struct drm_gem_object
*obj
);
425 struct drm_gem_object
*drm_gem_object_alloc(struct drm_device
*dev
,
427 int drm_gem_handle_create(struct drm_file
*file_priv
,
428 struct drm_gem_object
*obj
,
431 struct drm_gem_object
*drm_gem_object_lookup(struct drm_device
*dev
,
432 struct drm_file
*filp
,
437 drm_gem_object_reference(struct drm_gem_object
*obj
)
439 kref_get(&obj
->refcount
);
443 drm_gem_object_unreference(struct drm_gem_object
*obj
)
448 kref_put(&obj
->refcount
, drm_gem_object_free
);
452 drm_gem_object_unreference_unlocked(struct drm_gem_object
*obj
)
455 struct drm_device
*dev
= obj
->dev
;
456 mutex_lock(&dev
->struct_mutex
);
457 kref_put(&obj
->refcount
, drm_gem_object_free
);
458 mutex_unlock(&dev
->struct_mutex
);
462 int drm_gem_handle_create(struct drm_file
*file_priv
,
463 struct drm_gem_object
*obj
,
467 drm_gem_object_handle_reference(struct drm_gem_object
*obj
)
469 drm_gem_object_reference(obj
);
470 atomic_inc(&obj
->handle_count
);
474 drm_gem_object_handle_unreference(struct drm_gem_object
*obj
)
479 if (atomic_read(&obj
->handle_count
) == 0)
482 * Must bump handle count first as this may be the last
483 * ref, in which case the object would disappear before we
486 if (atomic_dec_and_test(&obj
->handle_count
))
487 drm_gem_object_handle_free(obj
);
488 drm_gem_object_unreference(obj
);
492 drm_gem_object_handle_unreference_unlocked(struct drm_gem_object
*obj
)
497 if (atomic_read(&obj
->handle_count
) == 0)
501 * Must bump handle count first as this may be the last
502 * ref, in which case the object would disappear before we
506 if (atomic_dec_and_test(&obj
->handle_count
))
507 drm_gem_object_handle_free(obj
);
508 drm_gem_object_unreference_unlocked(obj
);
512 int drm_gem_open_ioctl(struct drm_device
*dev
, void *data
,
513 struct drm_file
*file_priv
);
514 int drm_gem_close_ioctl(struct drm_device
*dev
, void *data
,
515 struct drm_file
*file_priv
);
516 int drm_gem_flink_ioctl(struct drm_device
*dev
, void *data
,
517 struct drm_file
*file_priv
);
520 #define DRM_MTRR_WC 0
521 static inline int drm_mtrr_add(unsigned long offset
, unsigned long size
,
526 static inline int drm_mtrr_del(int handle
, unsigned long offset
,
527 unsigned long size
, unsigned int flags
)
532 #define MTRR_TYPE_WRCOMB 1
534 static inline int mtrr_add(unsigned long base
, unsigned long size
,
535 unsigned int type
, char increment
)