revert between 56095 -> 55830 in arch
[AROS.git] / workbench / hidds / nouveau / drm / drm-aros / drmP.h
blob31ba7a547367f985534fffa804cd40c7c691620e
1 /*
2 Copyright 2009-2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*-
7 * This file incorporates work covered by the following copyright and
8 * permission notice:
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
23 * Software.
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.
35 #if !defined(DRMP_H)
36 #define DRMP_H
38 #define DEBUG 0
39 #include <aros/debug.h>
41 #include <oop/oop.h>
43 #include "drm.h"
44 #include "drm_aros_config.h"
45 #include "drm_compat_funcs.h"
46 #include "drm_redefines.h"
48 #include <errno.h>
49 #include <stdio.h>
50 #include <string.h>
52 #include "drm_mm.h"
54 #define DRM_ERROR(fmt, ...) bug("[" DRM_NAME "(ERROR):%s] " fmt, __func__ , ##__VA_ARGS__)
55 #define DRM_DEBUG(fmt, ...) D(bug("[" DRM_NAME "(DEBUG):%s] " fmt, __func__ , ##__VA_ARGS__))
56 #define DRM_DEBUG_KMS(fmt, ...) D(bug("[" DRM_NAME "(DEBUG):%s] " fmt, __func__ , ##__VA_ARGS__))
57 #define DRM_IMPL(fmt, ...) bug("------IMPLEMENT(%s): " fmt, __func__ , ##__VA_ARGS__)
58 #define DRM_INFO(fmt, ...) bug("[" DRM_NAME "(INFO)] " fmt, ##__VA_ARGS__)
59 #define DRM_DEBUG_DRIVER DRM_DEBUG
61 #define DRM_UT_CORE 0x01
62 #define DRM_UT_DRIVER 0x02
63 #define DRM_UT_KMS 0x04
65 extern unsigned int drm_debug;
68 * DRM_READMEMORYBARRIER() prevents reordering of reads.
69 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
70 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
73 #if defined(__i386__)
74 #define DRM_READMEMORYBARRIER() __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
75 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
76 #define DRM_MEMORYBARRIER() __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
77 #elif defined(__x86_64__)
78 #define DRM_READMEMORYBARRIER() __asm __volatile("lfence":::"memory");
79 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("sfence":::"memory");
80 #define DRM_MEMORYBARRIER() __asm __volatile("mfence":::"memory");
81 #else
82 #error IMPLEMENT momory bariers for non-x86
83 #endif
86 #define DRM_COPY_FROM_USER(to, from, size) copy_from_user(to, from, size)
87 #define DRM_COPY_TO_USER(to , from, size) copy_to_user(to, from, size)
88 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
89 #define DRM_UDELAY(d) udelay(d)
90 #define DRM_CURRENTPID 1
91 #define DRM_IRQ_ARGS void *arg
92 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
93 typedef int irqreturn_t;
94 #define IRQ_NONE 1
95 #define IRQ_HANDLED 0
97 struct drm_file;
98 struct drm_device;
99 struct file;
100 struct drm_gem_object;
102 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
103 struct drm_file *file_priv);
105 #define DRM_AUTH 0x1
106 #define DRM_MASTER 0x2
107 #define DRM_ROOT_ONLY 0x4
108 #define DRM_CONTROL_ALLOW 0x8
109 #define DRM_UNLOCKED 0x10
111 struct drm_ioctl_desc
113 unsigned int cmd;
114 int flags;
115 drm_ioctl_t *func;
116 unsigned int cmd_drv;
120 * Creates a driver or general drm_ioctl_desc array entry for the given
121 * ioctl, for use by drm_ioctl().
123 #define DRM_IOCTL_NR(n) ((n) & 0xff)
124 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
125 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
128 /* Memory management */
129 struct drm_local_map
131 resource_size_t offset; /* Requested physical address (0 for SAREA)*/
132 unsigned long size; /* Requested physical size (bytes) */
133 enum drm_map_type type; /* Type of memory to map */
134 enum drm_map_flags flags; /* Flags */
135 void *handle; /* Memory address */
136 int mtrr; /* MTRR slot used */
139 typedef struct drm_local_map drm_local_map_t;
141 struct drm_map_list
143 struct list_head head; /* list head */
144 /* FIXME: Commented out fields */
145 // struct drm_hash_item hash;
146 struct drm_local_map *map; /* mapping */
147 uint64_t user_token;
148 struct drm_master *master;
149 struct drm_mm_node *file_offset_node; /* fake offset */
152 struct drm_sg_mem {
153 unsigned long handle;
154 void *virtual;
155 int pages;
156 #if !defined(__AROS__)
157 struct page **pagelist;
158 #else
159 void * buffer;
160 #endif
161 dma_addr_t *busaddr;
164 #define DRM_AGP_KERN struct agp_kern_info
165 #define DRM_AGP_MEM struct agp_memory
166 struct drm_agp_mem {
167 DRM_AGP_MEM *memory;
168 unsigned long bound;
169 int pages;
170 struct list_head head;
173 struct drm_agp_head {
174 DRM_AGP_KERN agp_info; /* AGP device information */
175 struct list_head memory;
176 unsigned long mode; /* AGP mode */
177 struct agp_bridge_data *bridge;
178 int enabled; /* whether the AGP bus as been enabled */
179 int acquired; /* whether the AGP device has been acquired */
180 unsigned long base;
181 int agp_mtrr;
182 int cant_use_aperture;
183 unsigned long page_mask;
186 struct drm_pciid
188 UWORD VendorID;
189 UWORD ProductID;
192 #include "drm_crtc.h"
194 /* Contains a collection of functions common to each drm driver */
196 #define DRIVER_USE_AGP 0x1
197 #define DRIVER_REQUIRE_AGP 0x2
198 #define DRIVER_GEM 0x1000
199 #define DRIVER_MODESET 0x2000
201 /* Size of ringbuffer for vblank timestamps. Just double-buffer
202 * in initial implementation.
204 #define DRM_VBLANKTIME_RBSIZE 2
206 /* Flags and return codes for get_vblank_timestamp() driver function. */
207 #define DRM_CALLED_FROM_VBLIRQ 1
208 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
209 #define DRM_VBLANKTIME_INVBL (1 << 1)
211 /* get_scanout_position() return flags */
212 #define DRM_SCANOUTPOS_VALID (1 << 0)
213 #define DRM_SCANOUTPOS_INVBL (1 << 1)
214 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
216 struct drm_driver
218 /* PCI */
219 UWORD VendorID;
220 UWORD ProductID;
221 UWORD SubSystemVendorID;
222 UWORD SubSystemProductID;
223 struct drm_pciid *PciIDs;
224 OOP_Object *pciDevice;
225 BOOL IsAGP;
226 BOOL IsPCIE;
228 /* DRM device */
229 struct drm_device *dev;
231 int (*load)(struct drm_device *, unsigned long);
232 int (*firstopen)(struct drm_device *);
233 int (*open) (struct drm_device *, struct drm_file *);
234 void (*preclose)(struct drm_device *dev, struct drm_file *);
235 void (*postclose) (struct drm_device *, struct drm_file *);
236 void (*lastclose)(struct drm_device *);
237 int (*unload)(struct drm_device *);
239 /* IRQ */
240 irqreturn_t (*irq_handler)(DRM_IRQ_ARGS);
241 void (*irq_preinstall)(struct drm_device *);
242 int (*irq_postinstall)(struct drm_device *);
243 void (*irq_uninstall)(struct drm_device *);
245 /* GEM */
246 int (*gem_init_object) (struct drm_gem_object *obj);
247 void (*gem_free_object) (struct drm_gem_object *obj);
248 void (*gem_free_object_unlocked) (struct drm_gem_object *obj);
249 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
250 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
252 int version_patchlevel;
253 unsigned int driver_features;
254 struct drm_ioctl_desc *ioctls;
257 struct drm_device
259 struct list_head maplist; /* Linked list of regions */
261 int irq_enabled; /* True if irq handler is enabled */
262 int pci_vendor; /* PCI vendor id */
263 int pci_device; /* PCI device id */
265 struct drm_agp_head *agp; /* AGP data */
267 struct drm_driver *driver; /* Driver functions */
268 void *dev_private; /* Device private data */
269 struct mutex struct_mutex;
271 struct address_space *dev_mapping;
272 struct drm_mode_config mode_config;
274 struct pci_dev * pdev;
276 /* GEM information */
277 spinlock_t object_name_lock;
278 struct idr object_name_idr;
279 uint32_t invalidate_domains; /* domains pending invalidation */
280 uint32_t flush_domains; /* domains pending flush */
282 /* AROS specific fields */
283 struct Interrupt IntHandler;
286 static __inline__ int drm_core_check_feature(struct drm_device *dev,
287 int feature)
289 return ((dev->driver->driver_features & feature) ? 1 : 0);
292 typedef struct drm_dma_handle {
293 dma_addr_t busaddr;
294 void *vaddr;
295 size_t size;
296 } drm_dma_handle_t;
298 struct drm_file
300 struct idr object_idr;
301 spinlock_t table_lock;
302 void *driver_priv;
303 struct list_head fbs;
306 struct drm_gem_object {
307 /** Reference count of this object */
308 struct kref refcount;
310 /** Handle count of this object. Each handle also holds a reference */
311 atomic_t handle_count; /* number of handles on this object */
313 /** Related drm device */
314 struct drm_device *dev;
316 /** File representing the shmem storage */
317 struct file *filp;
319 /* Mapping info for this object */
320 struct drm_map_list map_list;
323 * Size of the object, in bytes. Immutable over the object's
324 * lifetime.
326 size_t size;
329 * Global name for this object, starts at 1. 0 means unnamed.
330 * Access is covered by the object_name_lock in the related drm_device
332 int name;
335 * Memory domains. These monitor which caches contain read/write data
336 * related to the object. When transitioning from one set of domains
337 * to another, the driver is called to ensure that caches are suitably
338 * flushed and invalidated
340 uint32_t read_domains;
341 uint32_t write_domain;
344 * While validating an exec operation, the
345 * new read/write domain values are computed here.
346 * They will be transferred to the above values
347 * at the point that any cache flushing occurs
349 uint32_t pending_read_domains;
350 uint32_t pending_write_domain;
352 void *driver_private;
355 static inline int drm_core_has_AGP(struct drm_device *dev)
357 return drm_core_check_feature(dev, DRIVER_USE_AGP);
360 static __inline__ int drm_device_is_agp(struct drm_device *dev)
362 return dev->driver->IsAGP;
365 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
367 return dev->driver->IsPCIE;
370 /* drm_bufs.c */
371 int drm_order(unsigned long size);
373 /* drm_drv.c */
374 void drm_exit(struct drm_driver *driver);
375 int drm_init(struct drm_driver *driver);
377 /* drm_irq.c */
378 int drm_irq_install(struct drm_device *dev);
379 int drm_irq_uninstall(struct drm_device *dev);
381 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
382 void drm_vblank_cleanup(struct drm_device *dev);
383 void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
384 void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
385 int drm_vblank_get(struct drm_device *dev, int crtc);
386 void drm_vblank_put(struct drm_device *dev, int crtc);
387 void drm_handle_vblank(struct drm_device *dev, int crtc);
388 u32 drm_vblank_count(struct drm_device *dev, int crtc);
390 /* drm_memory.c */
391 void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
392 void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
393 void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
394 int drm_unbind_agp(DRM_AGP_MEM * handle);
395 void drm_free_agp(DRM_AGP_MEM * handle, int pages);
397 /* drm_agpsupport.c */
398 struct drm_agp_head *drm_agp_init(struct drm_device *dev);
399 int drm_agp_acquire(struct drm_device *dev);
400 int drm_agp_release(struct drm_device *dev);
401 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
402 int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
403 int drm_agp_free_memory(DRM_AGP_MEM * handle);
404 int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
405 void drm_agp_chipset_flush(struct drm_device *dev);
406 DRM_AGP_MEM * drm_agp_bind_pages(struct drm_device *dev, struct page **pages,
407 unsigned long num_pages, uint32_t gtt_offset, u32 type);
409 /* drm_cache.c */
410 void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
412 /* GEM */
413 int drm_gem_init(struct drm_device *dev);
414 void drm_gem_object_release(struct drm_gem_object *obj);
415 void drm_gem_object_free(struct kref *kref);
416 void drm_gem_object_free_unlocked(struct kref *kref);
417 void drm_gem_object_handle_free(struct drm_gem_object *obj);
418 struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
419 size_t size);
420 int drm_gem_handle_create(struct drm_file *file_priv,
421 struct drm_gem_object *obj,
422 u32 *handlep);
424 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
425 struct drm_file *filp,
426 u32 handle);
428 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
430 static inline void
431 drm_gem_object_reference(struct drm_gem_object *obj)
433 kref_get(&obj->refcount);
436 static inline void
437 drm_gem_object_unreference(struct drm_gem_object *obj)
439 if (obj == NULL)
440 return;
442 kref_put(&obj->refcount, drm_gem_object_free);
445 static inline void
446 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
448 if (obj != NULL) {
449 struct drm_device *dev = obj->dev;
450 mutex_lock(&dev->struct_mutex);
451 kref_put(&obj->refcount, drm_gem_object_free);
452 mutex_unlock(&dev->struct_mutex);
456 int drm_gem_handle_create(struct drm_file *file_priv,
457 struct drm_gem_object *obj,
458 u32 *handlep);
460 static inline void
461 drm_gem_object_handle_reference(struct drm_gem_object *obj)
463 drm_gem_object_reference(obj);
464 atomic_inc(&obj->handle_count);
467 static inline void
468 drm_gem_object_handle_unreference(struct drm_gem_object *obj)
470 if (obj == NULL)
471 return;
473 if (atomic_read(&obj->handle_count) == 0)
474 return;
476 * Must bump handle count first as this may be the last
477 * ref, in which case the object would disappear before we
478 * checked for a name
480 if (atomic_dec_and_test(&obj->handle_count))
481 drm_gem_object_handle_free(obj);
482 drm_gem_object_unreference(obj);
485 static inline void
486 drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
488 if (obj == NULL)
489 return;
491 if (atomic_read(&obj->handle_count) == 0)
492 return;
495 * Must bump handle count first as this may be the last
496 * ref, in which case the object would disappear before we
497 * checked for a name
500 if (atomic_dec_and_test(&obj->handle_count))
501 drm_gem_object_handle_free(obj);
502 drm_gem_object_unreference_unlocked(obj);
505 /* GEM IOCTL */
506 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
507 struct drm_file *file_priv);
508 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
509 struct drm_file *file_priv);
510 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
511 struct drm_file *file_priv);
513 /* MTRR */
514 #define DRM_MTRR_WC 0
515 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
516 unsigned int flags)
518 return -ENODEV;
520 static inline int drm_mtrr_del(int handle, unsigned long offset,
521 unsigned long size, unsigned int flags)
523 return -ENODEV;
526 #define MTRR_TYPE_WRCOMB 1
528 static inline int mtrr_add(unsigned long base, unsigned long size,
529 unsigned int type, char increment)
531 return -ENODEV;
534 static inline int drm_pci_device_is_agp(struct drm_device *dev)
536 return (int)dev->driver->IsAGP;
539 #endif