mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2026-05-22 16:18:14 +02:00
New DRM template architecture, with initial implementation of MGA driver
using core DRM templates. Other drivers to follow.
Note: This is missing the corresponding updates to the MGA 2D driver, so it
will not run yet. These updates will also follow.
This commit is contained in:
parent
4d2a4455b4
commit
4840ecda0b
60 changed files with 23102 additions and 8383 deletions
|
|
@ -49,8 +49,7 @@ r128-objs := r128_drv.o r128_cce.o r128_context.o r128_bufs.o \
|
|||
radeon-objs := radeon_drv.o radeon_cp.o radeon_context.o radeon_bufs.o \
|
||||
radeon_state.o
|
||||
ffb-objs := ffb_drv.o ffb_context.o
|
||||
mga-objs := mga_drv.o mga_dma.o mga_context.o mga_bufs.o \
|
||||
mga_state.o
|
||||
mga-objs := mga_drv.o mga_drm.o mga_dma.o mga_state.o mga_warp.o
|
||||
i810-objs := i810_drv.o i810_dma.o i810_context.o i810_bufs.o
|
||||
|
||||
obj-$(CONFIG_DRM_GAMMA) += gamma.o
|
||||
|
|
@ -62,7 +61,7 @@ obj-$(CONFIG_DRM_MGA) += mga.o
|
|||
obj-$(CONFIG_DRM_I810) += i810.o
|
||||
|
||||
|
||||
# When linking into the kernel, link the library just once.
|
||||
# When linking into the kernel, link the library just once.
|
||||
# If making modules, we include the library into each module
|
||||
|
||||
lib-objs-mod := $(patsubst %.o,%-mod.o,$(lib-objs))
|
||||
|
|
@ -75,7 +74,7 @@ endif
|
|||
|
||||
include $(TOPDIR)/Rules.make
|
||||
|
||||
$(patsubst %.o,%.c,$(lib-objs-mod)):
|
||||
$(patsubst %.o,%.c,$(lib-objs-mod)):
|
||||
@ln -sf $(subst -mod,,$@) $@
|
||||
|
||||
drmlib-mod.a: $(lib-objs-mod)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
*
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef _DRM_P_H_
|
||||
|
|
@ -75,6 +75,32 @@
|
|||
#endif
|
||||
#include "drm.h"
|
||||
|
||||
/* DRM template customization defaults
|
||||
*/
|
||||
#ifndef __HAVE_AGP
|
||||
#define __HAVE_AGP 0
|
||||
#endif
|
||||
#ifndef __HAVE_MTRR
|
||||
#define __HAVE_MTRR 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA
|
||||
#define __HAVE_DMA 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_WAITLIST
|
||||
#define __HAVE_DMA_WAITLIST 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_FREELIST
|
||||
#define __HAVE_DMA_FREELIST 0
|
||||
#endif
|
||||
|
||||
#define __REALLY_HAVE_AGP (__HAVE_AGP && (defined(CONFIG_AGP) || \
|
||||
defined(CONFIG_AGP_MODULE)))
|
||||
#define __REALLY_HAVE_MTRR (__HAVE_MTRR && defined(CONFIG_MTRR))
|
||||
|
||||
|
||||
/* Begin the DRM...
|
||||
*/
|
||||
|
||||
#define DRM_DEBUG_CODE 2 /* Include debugging code (if > 1, then
|
||||
also include looping detection. */
|
||||
#define DRM_DMA_HISTOGRAM 1 /* Make histogram of DMA latency. */
|
||||
|
|
@ -263,12 +289,12 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
|
|||
#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
|
||||
|
||||
#if DRM_DEBUG_CODE
|
||||
#define DRM_DEBUG(fmt, arg...) \
|
||||
do { \
|
||||
if (drm_flags&DRM_FLAG_DEBUG) \
|
||||
printk(KERN_DEBUG \
|
||||
"[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
|
||||
##arg); \
|
||||
#define DRM_DEBUG(fmt, arg...) \
|
||||
do { \
|
||||
if ( DRM(flags) & DRM_FLAG_DEBUG ) \
|
||||
printk(KERN_DEBUG \
|
||||
"[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
|
||||
##arg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define DRM_DEBUG(fmt, arg...) do { } while (0)
|
||||
|
|
@ -284,27 +310,6 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
|
|||
len += sprintf(&buf[len], fmt , ##arg); \
|
||||
if (len > DRM_PROC_LIMIT) { ret; return len; }
|
||||
|
||||
/* Mapping helper macros */
|
||||
#define DRM_IOREMAP(map) \
|
||||
(map)->handle = drm_ioremap( (map)->offset, (map)->size )
|
||||
|
||||
#define DRM_IOREMAPFREE(map) \
|
||||
do { \
|
||||
if ( (map)->handle && (map)->size ) \
|
||||
drm_ioremapfree( (map)->handle, (map)->size ); \
|
||||
} while (0)
|
||||
|
||||
#define DRM_FIND_MAP(map, o) \
|
||||
do { \
|
||||
int i; \
|
||||
for ( i = 0 ; i < dev->map_count ; i++ ) { \
|
||||
if ( dev->maplist[i]->offset == o ) { \
|
||||
map = dev->maplist[i]; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Internal types and structures */
|
||||
#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
|
||||
|
|
@ -314,8 +319,8 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
|
|||
#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
|
||||
#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
|
||||
|
||||
typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
typedef struct drm_ioctl_desc {
|
||||
drm_ioctl_t *func;
|
||||
|
|
@ -501,7 +506,7 @@ typedef struct drm_device_dma {
|
|||
unsigned long *pagelist;
|
||||
unsigned long byte_count;
|
||||
enum {
|
||||
_DRM_DMA_USE_AGP = 0x01
|
||||
_DRM_DMA_USE_AGP = 0x01
|
||||
} flags;
|
||||
|
||||
/* DMA support */
|
||||
|
|
@ -511,7 +516,7 @@ typedef struct drm_device_dma {
|
|||
wait_queue_head_t waiting; /* Processes waiting on free bufs */
|
||||
} drm_device_dma_t;
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
#if __REALLY_HAVE_AGP
|
||||
typedef struct drm_agp_mem {
|
||||
unsigned long handle;
|
||||
agp_memory *memory;
|
||||
|
|
@ -617,7 +622,7 @@ typedef struct drm_device {
|
|||
wait_queue_head_t buf_readers; /* Processes waiting to read */
|
||||
wait_queue_head_t buf_writers; /* Processes waiting to ctx switch */
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
#if __REALLY_HAVE_AGP
|
||||
drm_agp_head_t *agp;
|
||||
#endif
|
||||
unsigned long *ctx_bitmap;
|
||||
|
|
@ -630,227 +635,234 @@ typedef struct drm_device {
|
|||
/* Internal function definitions */
|
||||
|
||||
/* Misc. support (init.c) */
|
||||
extern int drm_flags;
|
||||
extern void drm_parse_options(char *s);
|
||||
extern int drm_cpu_valid(void);
|
||||
extern int DRM(flags);
|
||||
extern void DRM(parse_options)( char *s );
|
||||
extern int DRM(cpu_valid)( void );
|
||||
|
||||
|
||||
/* Device support (fops.c) */
|
||||
extern int drm_open_helper(struct inode *inode, struct file *filp,
|
||||
drm_device_t *dev);
|
||||
extern int drm_flush(struct file *filp);
|
||||
extern int drm_release(struct inode *inode, struct file *filp);
|
||||
extern int drm_fasync(int fd, struct file *filp, int on);
|
||||
extern ssize_t drm_read(struct file *filp, char *buf, size_t count,
|
||||
loff_t *off);
|
||||
extern int drm_write_string(drm_device_t *dev, const char *s);
|
||||
extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
|
||||
extern int DRM(open_helper)(struct inode *inode, struct file *filp,
|
||||
drm_device_t *dev);
|
||||
extern int DRM(flush)(struct file *filp);
|
||||
extern int DRM(release_fuck)(struct inode *inode, struct file *filp);
|
||||
extern int DRM(fasync)(int fd, struct file *filp, int on);
|
||||
extern ssize_t DRM(read)(struct file *filp, char *buf, size_t count,
|
||||
loff_t *off);
|
||||
extern int DRM(write_string)(drm_device_t *dev, const char *s);
|
||||
extern unsigned int DRM(poll)(struct file *filp,
|
||||
struct poll_table_struct *wait);
|
||||
|
||||
/* Mapping support (vm.c) */
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
extern unsigned long drm_vm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long drm_vm_shm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long drm_vm_dma_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
extern struct page *drm_vm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
#endif
|
||||
extern void drm_vm_open(struct vm_area_struct *vma);
|
||||
extern void drm_vm_close(struct vm_area_struct *vma);
|
||||
extern int drm_mmap_dma(struct file *filp,
|
||||
struct vm_area_struct *vma);
|
||||
extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
|
||||
extern void DRM(vm_open)(struct vm_area_struct *vma);
|
||||
extern void DRM(vm_close)(struct vm_area_struct *vma);
|
||||
extern int DRM(mmap_dma)(struct file *filp,
|
||||
struct vm_area_struct *vma);
|
||||
extern int DRM(mmap)(struct file *filp, struct vm_area_struct *vma);
|
||||
|
||||
|
||||
/* Proc support (proc.c) */
|
||||
extern int drm_proc_init(drm_device_t *dev);
|
||||
extern int drm_proc_cleanup(void);
|
||||
extern int DRM(proc_init)(drm_device_t *dev);
|
||||
extern int DRM(proc_cleanup)(void);
|
||||
|
||||
/* Memory management support (memory.c) */
|
||||
extern void drm_mem_init(void);
|
||||
extern int drm_mem_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
extern void *drm_alloc(size_t size, int area);
|
||||
extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
|
||||
int area);
|
||||
extern char *drm_strdup(const char *s, int area);
|
||||
extern void drm_strfree(const char *s, int area);
|
||||
extern void drm_free(void *pt, size_t size, int area);
|
||||
extern unsigned long drm_alloc_pages(int order, int area);
|
||||
extern void drm_free_pages(unsigned long address, int order,
|
||||
int area);
|
||||
extern void *drm_ioremap(unsigned long offset, unsigned long size);
|
||||
extern void drm_ioremapfree(void *pt, unsigned long size);
|
||||
extern void DRM(mem_init)(void);
|
||||
extern int DRM(mem_info)(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
extern void *DRM(alloc)(size_t size, int area);
|
||||
extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
|
||||
int area);
|
||||
extern char *DRM(strdup)(const char *s, int area);
|
||||
extern void DRM(strfree)(const char *s, int area);
|
||||
extern void DRM(free)(void *pt, size_t size, int area);
|
||||
extern unsigned long DRM(alloc_pages)(int order, int area);
|
||||
extern void DRM(free_pages)(unsigned long address, int order,
|
||||
int area);
|
||||
extern void *DRM(ioremap)(unsigned long offset, unsigned long size);
|
||||
extern void DRM(ioremapfree)(void *pt, unsigned long size);
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
extern agp_memory *drm_alloc_agp(int pages, u32 type);
|
||||
extern int drm_free_agp(agp_memory *handle, int pages);
|
||||
extern int drm_bind_agp(agp_memory *handle, unsigned int start);
|
||||
extern int drm_unbind_agp(agp_memory *handle);
|
||||
#if __REALLY_HAVE_AGP
|
||||
extern agp_memory *DRM(alloc_agp)(int pages, u32 type);
|
||||
extern int DRM(free_agp)(agp_memory *handle, int pages);
|
||||
extern int DRM(bind_agp)(agp_memory *handle, unsigned int start);
|
||||
extern int DRM(unbind_agp)(agp_memory *handle);
|
||||
#endif
|
||||
|
||||
|
||||
/* Buffer management support (bufs.c) */
|
||||
extern int drm_order(unsigned long size);
|
||||
extern int drm_addmap(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_addbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_infobufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_markbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_freebufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_mapbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Buffer list management support (lists.c) */
|
||||
extern int drm_waitlist_create(drm_waitlist_t *bl, int count);
|
||||
extern int drm_waitlist_destroy(drm_waitlist_t *bl);
|
||||
extern int drm_waitlist_put(drm_waitlist_t *bl, drm_buf_t *buf);
|
||||
extern drm_buf_t *drm_waitlist_get(drm_waitlist_t *bl);
|
||||
|
||||
extern int drm_freelist_create(drm_freelist_t *bl, int count);
|
||||
extern int drm_freelist_destroy(drm_freelist_t *bl);
|
||||
extern int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl,
|
||||
drm_buf_t *buf);
|
||||
extern drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block);
|
||||
|
||||
/* DMA support (gen_dma.c) */
|
||||
extern void drm_dma_setup(drm_device_t *dev);
|
||||
extern void drm_dma_takedown(drm_device_t *dev);
|
||||
extern void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
|
||||
extern void drm_reclaim_buffers(drm_device_t *dev, pid_t pid);
|
||||
extern int drm_context_switch(drm_device_t *dev, int old, int new);
|
||||
extern int drm_context_switch_complete(drm_device_t *dev, int new);
|
||||
extern void drm_clear_next_buffer(drm_device_t *dev);
|
||||
extern int drm_select_queue(drm_device_t *dev,
|
||||
void (*wrapper)(unsigned long));
|
||||
extern int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *dma);
|
||||
extern int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma);
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
extern int drm_histogram_slot(unsigned long count);
|
||||
extern void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf);
|
||||
#endif
|
||||
|
||||
|
||||
/* Misc. IOCTL support (ioctl.c) */
|
||||
extern int drm_irq_busid(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_getunique(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_setunique(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(irq_busid)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(getunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(setunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Context IOCTL support (context.c) */
|
||||
extern int drm_resctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_addctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_modctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_getctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_switchctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_newctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_rmctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(resctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(addctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(modctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(getctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(switchctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(newctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(rmctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
|
||||
/* Drawable IOCTL support (drawable.c) */
|
||||
extern int drm_adddraw(struct inode *inode, struct file *filp,
|
||||
extern int DRM(adddraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(rmdraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_rmdraw(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Authentication IOCTL support (auth.c) */
|
||||
extern int drm_add_magic(drm_device_t *dev, drm_file_t *priv,
|
||||
drm_magic_t magic);
|
||||
extern int drm_remove_magic(drm_device_t *dev, drm_magic_t magic);
|
||||
extern int drm_getmagic(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_authmagic(struct inode *inode, struct file *filp,
|
||||
extern int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
|
||||
drm_magic_t magic);
|
||||
extern int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
|
||||
extern int DRM(getmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(authmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Locking IOCTL support (lock.c) */
|
||||
extern int drm_block(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_unblock(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_lock_take(__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int drm_lock_transfer(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int drm_lock_free(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int drm_finish(struct inode *inode, struct file *filp,
|
||||
extern int DRM(block)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_flush_unblock(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int drm_flush_block_and_flush(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int drm_notifier(void *priv);
|
||||
extern int DRM(unblock)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(lock_take)(__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int DRM(lock_transfer)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int DRM(lock_free)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int DRM(finish)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(flush_unblock)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int DRM(notifier)(void *priv);
|
||||
|
||||
/* Context Bitmap support (ctxbitmap.c) */
|
||||
extern int drm_ctxbitmap_init(drm_device_t *dev);
|
||||
extern void drm_ctxbitmap_cleanup(drm_device_t *dev);
|
||||
extern int drm_ctxbitmap_next(drm_device_t *dev);
|
||||
extern void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
|
||||
extern int DRM(ctxbitmap_init)( drm_device_t *dev );
|
||||
extern void DRM(ctxbitmap_cleanup)( drm_device_t *dev );
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
|
||||
|
||||
|
||||
/* Buffer management support (bufs.c) */
|
||||
extern int DRM(order)( unsigned long size );
|
||||
extern int DRM(addmap)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(addbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(infobufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(markbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(freebufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(mapbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
|
||||
#if __HAVE_DMA
|
||||
/* DMA support (dma.c) */
|
||||
extern int DRM(dma_setup)(drm_device_t *dev);
|
||||
extern void DRM(dma_takedown)(drm_device_t *dev);
|
||||
extern void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
|
||||
extern void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid);
|
||||
extern int DRM(context_switch)(drm_device_t *dev, int old, int new);
|
||||
extern int DRM(context_switch_complete)(drm_device_t *dev, int new);
|
||||
extern void DRM(clear_next_buffer)(drm_device_t *dev);
|
||||
extern int DRM(select_queue)(drm_device_t *dev,
|
||||
void (*wrapper)(unsigned long));
|
||||
extern int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *dma);
|
||||
#if 0
|
||||
extern int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma);
|
||||
#endif
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
extern int DRM(histogram_slot)(unsigned long count);
|
||||
extern void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Buffer list management support (lists.c) */
|
||||
#if __HAVE_DMA_WAITLIST
|
||||
extern int DRM(waitlist_create)(drm_waitlist_t *bl, int count);
|
||||
extern int DRM(waitlist_destroy)(drm_waitlist_t *bl);
|
||||
extern int DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf);
|
||||
extern drm_buf_t *DRM(waitlist_get)(drm_waitlist_t *bl);
|
||||
#endif
|
||||
#if __HAVE_DMA_FREELIST
|
||||
extern int DRM(freelist_create)(drm_freelist_t *bl, int count);
|
||||
extern int DRM(freelist_destroy)(drm_freelist_t *bl);
|
||||
extern int DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl,
|
||||
drm_buf_t *buf);
|
||||
extern drm_buf_t *DRM(freelist_get)(drm_freelist_t *bl, int block);
|
||||
#endif
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
/* AGP/GART support (agpsupport.c) */
|
||||
extern drm_agp_head_t *drm_agp_init(void);
|
||||
extern void drm_agp_uninit(void);
|
||||
extern int drm_agp_acquire(struct inode *inode, struct file *filp,
|
||||
extern drm_agp_head_t *DRM(agp_init)(void);
|
||||
extern void DRM(agp_uninit)(void);
|
||||
extern int DRM(agp_acquire)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void DRM(agp_do_release)(void);
|
||||
extern int DRM(agp_release)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(agp_enable)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void _drm_agp_release(void);
|
||||
extern int drm_agp_release(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_enable(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_info(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_alloc(struct inode *inode, struct file *filp,
|
||||
extern int DRM(agp_info)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_free(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_unbind(struct inode *inode, struct file *filp,
|
||||
extern int DRM(agp_alloc)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_bind(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern agp_memory *drm_agp_allocate_memory(size_t pages, u32 type);
|
||||
extern int drm_agp_free_memory(agp_memory *handle);
|
||||
extern int drm_agp_bind_memory(agp_memory *handle, off_t start);
|
||||
extern int drm_agp_unbind_memory(agp_memory *handle);
|
||||
extern int DRM(agp_free)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(agp_unbind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(agp_bind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type);
|
||||
extern int DRM(agp_free_memory)(agp_memory *handle);
|
||||
extern int DRM(agp_bind_memory)(agp_memory *handle, off_t start);
|
||||
extern int DRM(agp_unbind_memory)(agp_memory *handle);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* agpsupport.c -- DRM support for AGP/GART backend -*- linux-c -*-
|
||||
/* drm_agpsupport.h -- DRM support for AGP/GART backend -*- linux-c -*-
|
||||
* Created: Mon Dec 13 09:56:45 1999 by faith@precisioninsight.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
|
|
@ -11,26 +11,30 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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.
|
||||
*
|
||||
* Author: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Author:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <linux/module.h>
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020400
|
||||
#include "agpsupport-pre24.h"
|
||||
#else
|
||||
|
|
@ -40,8 +44,8 @@
|
|||
|
||||
static const drm_agp_t *drm_agp = NULL;
|
||||
|
||||
int drm_agp_info(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_info)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -66,8 +70,8 @@ int drm_agp_info(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_agp_acquire(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_acquire)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -79,8 +83,8 @@ int drm_agp_acquire(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_agp_release(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_release)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -89,16 +93,16 @@ int drm_agp_release(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
drm_agp->release();
|
||||
dev->agp->acquired = 0;
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void _drm_agp_release(void)
|
||||
void DRM(agp_do_release)(void)
|
||||
{
|
||||
if (drm_agp->release) drm_agp->release();
|
||||
}
|
||||
|
||||
int drm_agp_enable(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_enable)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -108,7 +112,7 @@ int drm_agp_enable(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
|
||||
if (copy_from_user(&mode, (drm_agp_mode_t *)arg, sizeof(mode)))
|
||||
return -EFAULT;
|
||||
|
||||
|
||||
dev->agp->mode = mode.mode;
|
||||
drm_agp->enable(mode.mode);
|
||||
dev->agp->base = dev->agp->agp_info.aper_base;
|
||||
|
|
@ -116,8 +120,8 @@ int drm_agp_enable(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_alloc)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -126,22 +130,23 @@ int drm_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
agp_memory *memory;
|
||||
unsigned long pages;
|
||||
u32 type;
|
||||
|
||||
if (!dev->agp->acquired) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_buffer_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
|
||||
if (!(entry = DRM(alloc)(sizeof(*entry), DRM_MEM_AGPLISTS)))
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
memset(entry, 0, sizeof(*entry));
|
||||
|
||||
pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
type = (u32) request.type;
|
||||
|
||||
if (!(memory = drm_alloc_agp(pages, type))) {
|
||||
drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
if (!(memory = DRM(alloc_agp)(pages, type))) {
|
||||
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
entry->handle = (unsigned long)memory->memory;
|
||||
entry->memory = memory;
|
||||
entry->bound = 0;
|
||||
|
|
@ -157,15 +162,15 @@ int drm_agp_alloc(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
if (copy_to_user((drm_agp_buffer_t *)arg, &request, sizeof(request))) {
|
||||
dev->agp->memory = entry->next;
|
||||
dev->agp->memory->prev = NULL;
|
||||
drm_free_agp(memory, pages);
|
||||
drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
DRM(free_agp)(memory, pages);
|
||||
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
return -EFAULT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t *dev,
|
||||
unsigned long handle)
|
||||
static drm_agp_mem_t *DRM(agp_lookup_entry)(drm_device_t *dev,
|
||||
unsigned long handle)
|
||||
{
|
||||
drm_agp_mem_t *entry;
|
||||
|
||||
|
|
@ -175,8 +180,8 @@ static drm_agp_mem_t *drm_agp_lookup_entry(drm_device_t *dev,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int drm_agp_unbind(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_unbind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -186,14 +191,14 @@ int drm_agp_unbind(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
if (!dev->agp->acquired) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_binding_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
|
||||
if (!(entry = DRM(agp_lookup_entry)(dev, request.handle)))
|
||||
return -EINVAL;
|
||||
if (!entry->bound) return -EINVAL;
|
||||
return drm_unbind_agp(entry->memory);
|
||||
return DRM(unbind_agp)(entry->memory);
|
||||
}
|
||||
|
||||
int drm_agp_bind(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_bind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -201,56 +206,56 @@ int drm_agp_bind(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
drm_agp_mem_t *entry;
|
||||
int retcode;
|
||||
int page;
|
||||
|
||||
|
||||
if (!dev->agp->acquired || !drm_agp->bind_memory) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_binding_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
|
||||
if (!(entry = DRM(agp_lookup_entry)(dev, request.handle)))
|
||||
return -EINVAL;
|
||||
if (entry->bound) return -EINVAL;
|
||||
page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
if ((retcode = drm_bind_agp(entry->memory, page))) return retcode;
|
||||
if ((retcode = DRM(bind_agp)(entry->memory, page))) return retcode;
|
||||
entry->bound = dev->agp->base + (page << PAGE_SHIFT);
|
||||
DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
|
||||
DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
|
||||
dev->agp->base, entry->bound);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_agp_free(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(agp_free)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_agp_buffer_t request;
|
||||
drm_agp_mem_t *entry;
|
||||
|
||||
|
||||
if (!dev->agp->acquired) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_buffer_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = drm_agp_lookup_entry(dev, request.handle)))
|
||||
if (!(entry = DRM(agp_lookup_entry)(dev, request.handle)))
|
||||
return -EINVAL;
|
||||
if (entry->bound) drm_unbind_agp(entry->memory);
|
||||
|
||||
if (entry->bound) DRM(unbind_agp)(entry->memory);
|
||||
|
||||
if (entry->prev) entry->prev->next = entry->next;
|
||||
else dev->agp->memory = entry->next;
|
||||
if (entry->next) entry->next->prev = entry->prev;
|
||||
drm_free_agp(entry->memory, entry->pages);
|
||||
drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
DRM(free_agp)(entry->memory, entry->pages);
|
||||
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
drm_agp_head_t *drm_agp_init(void)
|
||||
drm_agp_head_t *DRM(agp_init)(void)
|
||||
{
|
||||
drm_agp_head_t *head = NULL;
|
||||
|
||||
drm_agp = DRM_AGP_GET;
|
||||
if (drm_agp) {
|
||||
if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
|
||||
if (!(head = DRM(alloc)(sizeof(*head), DRM_MEM_AGPLISTS)))
|
||||
return NULL;
|
||||
memset((void *)head, 0, sizeof(*head));
|
||||
drm_agp->copy_info(&head->agp_info);
|
||||
if (head->agp_info.chipset == NOT_SUPPORTED) {
|
||||
drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
|
||||
DRM(free)(head, sizeof(*head), DRM_MEM_AGPLISTS);
|
||||
return NULL;
|
||||
}
|
||||
head->memory = NULL;
|
||||
|
|
@ -271,9 +276,9 @@ drm_agp_head_t *drm_agp_init(void)
|
|||
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
case VIA_MVP4: head->chipset = "VIA MVP4"; break;
|
||||
case VIA_APOLLO_KX133: head->chipset = "VIA Apollo KX133";
|
||||
case VIA_APOLLO_KX133: head->chipset = "VIA Apollo KX133";
|
||||
break;
|
||||
case VIA_APOLLO_KT133: head->chipset = "VIA Apollo KT133";
|
||||
case VIA_APOLLO_KT133: head->chipset = "VIA Apollo KT133";
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
|
@ -296,33 +301,35 @@ drm_agp_head_t *drm_agp_init(void)
|
|||
return head;
|
||||
}
|
||||
|
||||
void drm_agp_uninit(void)
|
||||
void DRM(agp_uninit)(void)
|
||||
{
|
||||
DRM_AGP_PUT;
|
||||
drm_agp = NULL;
|
||||
}
|
||||
|
||||
agp_memory *drm_agp_allocate_memory(size_t pages, u32 type)
|
||||
agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
|
||||
{
|
||||
if (!drm_agp->allocate_memory) return NULL;
|
||||
return drm_agp->allocate_memory(pages, type);
|
||||
}
|
||||
|
||||
int drm_agp_free_memory(agp_memory *handle)
|
||||
int DRM(agp_free_memory)(agp_memory *handle)
|
||||
{
|
||||
if (!handle || !drm_agp->free_memory) return 0;
|
||||
drm_agp->free_memory(handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int drm_agp_bind_memory(agp_memory *handle, off_t start)
|
||||
int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
|
||||
{
|
||||
if (!handle || !drm_agp->bind_memory) return -EINVAL;
|
||||
return drm_agp->bind_memory(handle, start);
|
||||
}
|
||||
|
||||
int drm_agp_unbind_memory(agp_memory *handle)
|
||||
int DRM(agp_unbind_memory)(agp_memory *handle)
|
||||
{
|
||||
if (!handle || !drm_agp->unbind_memory) return -EINVAL;
|
||||
return drm_agp->unbind_memory(handle);
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE) */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* auth.c -- IOCTLs for authentication -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@precisioninsight.com
|
||||
/* drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,37 +11,37 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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.
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
*
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
static int drm_hash_magic(drm_magic_t magic)
|
||||
static int DRM(hash_magic)(drm_magic_t magic)
|
||||
{
|
||||
return magic & (DRM_HASH_SIZE-1);
|
||||
}
|
||||
|
||||
static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
|
||||
static drm_file_t *DRM(find_file)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_file_t *retval = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash = drm_hash_magic(magic);
|
||||
int hash = DRM(hash_magic)(magic);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
|
||||
|
|
@ -54,15 +54,15 @@ static drm_file_t *drm_find_file(drm_device_t *dev, drm_magic_t magic)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
|
||||
int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
|
||||
{
|
||||
int hash;
|
||||
drm_magic_entry_t *entry;
|
||||
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
|
||||
hash = drm_hash_magic(magic);
|
||||
entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
|
||||
|
||||
hash = DRM(hash_magic)(magic);
|
||||
entry = DRM(alloc)(sizeof(*entry), DRM_MEM_MAGIC);
|
||||
if (!entry) return -ENOMEM;
|
||||
entry->magic = magic;
|
||||
entry->priv = priv;
|
||||
|
|
@ -77,19 +77,19 @@ int drm_add_magic(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
|
|||
dev->magiclist[hash].tail = entry;
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
|
||||
int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_magic_entry_t *prev = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash;
|
||||
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
hash = drm_hash_magic(magic);
|
||||
|
||||
hash = DRM(hash_magic)(magic);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
|
|
@ -108,13 +108,13 @@ int drm_remove_magic(drm_device_t *dev, drm_magic_t magic)
|
|||
}
|
||||
up(&dev->struct_sem);
|
||||
|
||||
drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int drm_getmagic(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(getmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
static drm_magic_t sequence = 0;
|
||||
static spinlock_t lock = SPIN_LOCK_UNLOCKED;
|
||||
|
|
@ -131,19 +131,19 @@ int drm_getmagic(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
if (!sequence) ++sequence; /* reserve 0 */
|
||||
auth.magic = sequence++;
|
||||
spin_unlock(&lock);
|
||||
} while (drm_find_file(dev, auth.magic));
|
||||
} while (DRM(find_file)(dev, auth.magic));
|
||||
priv->magic = auth.magic;
|
||||
drm_add_magic(dev, priv, auth.magic);
|
||||
DRM(add_magic)(dev, priv, auth.magic);
|
||||
}
|
||||
|
||||
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
if (copy_to_user((drm_auth_t *)arg, &auth, sizeof(auth)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_authmagic(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(authmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -153,9 +153,9 @@ int drm_authmagic(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
if (copy_from_user(&auth, (drm_auth_t *)arg, sizeof(auth)))
|
||||
return -EFAULT;
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
if ((file = drm_find_file(dev, auth.magic))) {
|
||||
if ((file = DRM(find_file)(dev, auth.magic))) {
|
||||
file->authenticated = 1;
|
||||
drm_remove_magic(dev, auth.magic);
|
||||
DRM(remove_magic)(dev, auth.magic);
|
||||
return 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
746
linux-core/drm_bufs.c
Normal file
746
linux-core/drm_bufs.c
Normal file
|
|
@ -0,0 +1,746 @@
|
|||
/* drm_bufs.h -- Generic buffer template -*- linux-c -*-
|
||||
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#ifndef __HAVE_PCI_DMA
|
||||
#define __HAVE_PCI_DMA 0
|
||||
#endif
|
||||
|
||||
#ifndef DRIVER_BUF_PRIV_T
|
||||
#define DRIVER_BUF_PRIV_T u32
|
||||
#endif
|
||||
#ifndef DRIVER_AGP_BUFFER_MAP
|
||||
#define DRIVER_AGP_BUFFER_MAP NULL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compute order. Can be made faster.
|
||||
*/
|
||||
int DRM(order)( unsigned long size )
|
||||
{
|
||||
int order;
|
||||
unsigned long tmp;
|
||||
|
||||
for ( order = 0, tmp = size ; tmp >>= 1 ; ++order );
|
||||
|
||||
if ( size & ~(1 << order) )
|
||||
++order;
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
int DRM(addmap)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_map_t *map;
|
||||
|
||||
if ( !(filp->f_mode & 3) ) return -EACCES; /* Require read/write */
|
||||
|
||||
map = DRM(alloc)( sizeof(*map), DRM_MEM_MAPS );
|
||||
if ( !map )
|
||||
return -ENOMEM;
|
||||
|
||||
if ( copy_from_user( map, (drm_map_t *)arg, sizeof(*map) ) ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "offset = 0x%08lx, size = 0x%08lx, type = %d\n",
|
||||
map->offset, map->size, map->type );
|
||||
if ( (map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK)) ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EINVAL;
|
||||
}
|
||||
map->mtrr = -1;
|
||||
map->handle = 0;
|
||||
|
||||
switch ( map->type ) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#ifndef __sparc__
|
||||
if ( map->offset + map->size < map->offset ||
|
||||
map->offset < virt_to_phys(high_memory) ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_MTRR
|
||||
if ( map->type == _DRM_FRAME_BUFFER ||
|
||||
(map->flags & _DRM_WRITE_COMBINING) ) {
|
||||
map->mtrr = mtrr_add( map->offset, map->size,
|
||||
MTRR_TYPE_WRCOMB, 1 );
|
||||
}
|
||||
#endif
|
||||
map->handle = DRM(ioremap)( map->offset, map->size );
|
||||
break;
|
||||
|
||||
case _DRM_SHM:
|
||||
map->handle = (void *)DRM(alloc_pages)( DRM(order)( map->size )
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA );
|
||||
DRM_DEBUG( "%ld %d %p\n",
|
||||
map->size, DRM(order)( map->size ), map->handle );
|
||||
if ( !map->handle ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
map->offset = (unsigned long)map->handle;
|
||||
if ( map->flags & _DRM_CONTAINS_LOCK ) {
|
||||
dev->lock.hw_lock = map->handle; /* Pointer to lock */
|
||||
}
|
||||
break;
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
case _DRM_AGP:
|
||||
map->offset = map->offset + dev->agp->base;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
down( &dev->struct_sem );
|
||||
if ( dev->maplist ) {
|
||||
++dev->map_count;
|
||||
dev->maplist = DRM(realloc)( dev->maplist,
|
||||
(dev->map_count-1)
|
||||
* sizeof(*dev->maplist),
|
||||
dev->map_count
|
||||
* sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS );
|
||||
} else {
|
||||
dev->map_count = 1;
|
||||
dev->maplist = DRM(alloc)( dev->map_count*sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS );
|
||||
}
|
||||
dev->maplist[dev->map_count-1] = map;
|
||||
up( &dev->struct_sem );
|
||||
|
||||
if ( copy_to_user( (drm_map_t *)arg, map, sizeof(*map) ) )
|
||||
return -EFAULT;
|
||||
if ( map->type != _DRM_SHM ) {
|
||||
if ( copy_to_user( &((drm_map_t *)arg)->handle,
|
||||
&map->offset,
|
||||
sizeof(map->offset) ) )
|
||||
return -EFAULT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
int DRM(addbufs_agp)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
drm_buf_entry_t *entry;
|
||||
drm_buf_t *buf;
|
||||
unsigned long offset;
|
||||
unsigned long agp_offset;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int alignment;
|
||||
int page_order;
|
||||
int total;
|
||||
int byte_count;
|
||||
int i;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = DRM(order)( request.size );
|
||||
size = 1 << order;
|
||||
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN)
|
||||
? PAGE_ALIGN(size) : size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
|
||||
byte_count = 0;
|
||||
agp_offset = dev->agp->base + request.agp_start;
|
||||
|
||||
DRM_DEBUG( "count: %d\n", count );
|
||||
DRM_DEBUG( "order: %d\n", order );
|
||||
DRM_DEBUG( "size: %d\n", size );
|
||||
DRM_DEBUG( "agp_offset: %ld\n", agp_offset );
|
||||
DRM_DEBUG( "alignment: %d\n", alignment );
|
||||
DRM_DEBUG( "page_order: %d\n", page_order );
|
||||
DRM_DEBUG( "total: %d\n", total );
|
||||
|
||||
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
|
||||
if ( dev->queue_count ) return -EBUSY; /* Not while in use */
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( dev->buf_use ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc( &dev->buf_alloc );
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
down( &dev->struct_sem );
|
||||
entry = &dma->bufs[order];
|
||||
if ( entry->buf_count ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
if ( !entry->buflist ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
|
||||
offset = 0;
|
||||
|
||||
while ( entry->buf_count < count ) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
|
||||
buf->offset = (dma->byte_count + offset); /* ******** */
|
||||
buf->address = (void *)(agp_offset + offset);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head( &buf->dma_wait );
|
||||
buf->pid = 0;
|
||||
|
||||
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
|
||||
buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
|
||||
DRM_MEM_BUFS );
|
||||
memset( buf->dev_private, 0, buf->dev_priv_size );
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
DRM_DEBUG( "buffer %d @ %p\n",
|
||||
entry->buf_count, buf->address );
|
||||
|
||||
offset += alignment;
|
||||
entry->buf_count++;
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "byte_count: %d\n", byte_count );
|
||||
|
||||
dma->buflist = DRM(realloc)( dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
dma->buflist[i + dma->buf_count] = &entry->buflist[i];
|
||||
}
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
dma->byte_count += byte_count;
|
||||
|
||||
DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
|
||||
DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
|
||||
|
||||
#if 0
|
||||
/* FIXME: work this mess out...
|
||||
*/
|
||||
DRM(freelist_create)( &entry->freelist, entry->buf_count );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
|
||||
}
|
||||
#endif
|
||||
|
||||
up( &dev->struct_sem );
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
dma->flags = _DRM_DMA_USE_AGP;
|
||||
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return 0;
|
||||
}
|
||||
#endif /* __REALLY_HAVE_AGP */
|
||||
|
||||
#if __HAVE_PCI_DMA
|
||||
int DRM(addbufs_pci)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int total;
|
||||
int page_order;
|
||||
drm_buf_entry_t *entry;
|
||||
unsigned long page;
|
||||
drm_buf_t *buf;
|
||||
int alignment;
|
||||
unsigned long offset;
|
||||
int i;
|
||||
int byte_count;
|
||||
int page_count;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = DRM(order)( request.size );
|
||||
size = 1 << order;
|
||||
|
||||
DRM_DEBUG( "count=%d, size=%d (%d), order=%d, queue_count=%d\n",
|
||||
request.count, request.size, size,
|
||||
order, dev->queue_count );
|
||||
|
||||
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
|
||||
if ( dev->queue_count ) return -EBUSY; /* Not while in use */
|
||||
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN)
|
||||
? PAGE_ALIGN(size) : size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( dev->buf_use ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc( &dev->buf_alloc );
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
down( &dev->struct_sem );
|
||||
entry = &dma->bufs[order];
|
||||
if ( entry->buf_count ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
if ( !entry->buflist ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
|
||||
|
||||
entry->seglist = DRM(alloc)( count * sizeof(*entry->seglist),
|
||||
DRM_MEM_SEGS );
|
||||
if ( !entry->seglist ) {
|
||||
DRM(free)( entry->buflist,
|
||||
count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( entry->seglist, 0, count * sizeof(*entry->seglist) );
|
||||
|
||||
dma->pagelist = DRM(realloc)( dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
(dma->page_count + (count << page_order))
|
||||
* sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM_DEBUG( "pagelist: %d entries\n",
|
||||
dma->page_count + (count << page_order) );
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
byte_count = 0;
|
||||
page_count = 0;
|
||||
|
||||
while ( entry->buf_count < count ) {
|
||||
page = DRM(alloc_pages)( page_order, DRM_MEM_DMA );
|
||||
if ( !page ) break;
|
||||
entry->seglist[entry->seg_count++] = page;
|
||||
for ( i = 0 ; i < (1 << page_order) ; i++ ) {
|
||||
DRM_DEBUG( "page %d @ 0x%08lx\n",
|
||||
dma->page_count + page_count,
|
||||
page + PAGE_SIZE * i );
|
||||
dma->pagelist[dma->page_count + page_count++]
|
||||
= page + PAGE_SIZE * i;
|
||||
}
|
||||
for ( offset = 0 ;
|
||||
offset + size <= total && entry->buf_count < count ;
|
||||
offset += alignment, ++entry->buf_count ) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
buf->offset = (dma->byte_count + byte_count + offset);
|
||||
buf->address = (void *)(page + offset);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head( &buf->dma_wait );
|
||||
buf->pid = 0;
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
DRM_DEBUG( "buffer %d @ %p\n",
|
||||
entry->buf_count, buf->address );
|
||||
}
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
dma->buflist = DRM(realloc)( dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
dma->buflist[i + dma->buf_count] = &entry->buflist[i];
|
||||
}
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
dma->seg_count += entry->seg_count;
|
||||
dma->page_count += entry->seg_count << page_order;
|
||||
dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
|
||||
|
||||
#if 0
|
||||
/* FIXME: work this mess out...
|
||||
*/
|
||||
DRM(freelist_create)( &entry->freelist, entry->buf_count );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
|
||||
}
|
||||
#endif
|
||||
|
||||
up( &dev->struct_sem );
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return 0;
|
||||
}
|
||||
#endif /* __HAVE_PCI_DMA */
|
||||
|
||||
int DRM(addbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_buf_desc_t request;
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
if ( request.flags & _DRM_AGP_BUFFER )
|
||||
return DRM(addbufs_agp)( inode, filp, cmd, arg );
|
||||
else
|
||||
#endif
|
||||
#if __HAVE_PCI_DMA
|
||||
return DRM(addbufs_pci)( inode, filp, cmd, arg );
|
||||
#else
|
||||
return -EINVAL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int DRM(infobufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_info_t request;
|
||||
int i;
|
||||
int count;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( atomic_read( &dev->buf_alloc ) ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
++dev->buf_use; /* Can't allocate more after this call */
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_buf_info_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
|
||||
if ( dma->bufs[i].buf_count ) ++count;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "count = %d\n", count );
|
||||
|
||||
if ( request.count >= count ) {
|
||||
for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
|
||||
if ( dma->bufs[i].buf_count ) {
|
||||
drm_buf_desc_t *to = &request.list[count];
|
||||
drm_buf_entry_t *from = &dma->bufs[i];
|
||||
drm_freelist_t *list = &dma->bufs[i].freelist;
|
||||
if ( copy_to_user( &to->count,
|
||||
&from->buf_count,
|
||||
sizeof(from->buf_count) ) ||
|
||||
copy_to_user( &to->size,
|
||||
&from->buf_size,
|
||||
sizeof(from->buf_size) ) ||
|
||||
copy_to_user( &to->low_mark,
|
||||
&list->low_mark,
|
||||
sizeof(list->low_mark) ) ||
|
||||
copy_to_user( &to->high_mark,
|
||||
&list->high_mark,
|
||||
sizeof(list->high_mark) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d %d %d %d %d\n",
|
||||
i,
|
||||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].buf_size,
|
||||
dma->bufs[i].freelist.low_mark,
|
||||
dma->bufs[i].freelist.high_mark );
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
request.count = count;
|
||||
|
||||
if ( copy_to_user( (drm_buf_info_t *)arg,
|
||||
&request,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(markbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int order;
|
||||
drm_buf_entry_t *entry;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d, %d, %d\n",
|
||||
request.size, request.low_mark, request.high_mark );
|
||||
order = DRM(order)( request.size );
|
||||
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
|
||||
entry = &dma->bufs[order];
|
||||
|
||||
if ( request.low_mark < 0 || request.low_mark > entry->buf_count )
|
||||
return -EINVAL;
|
||||
if ( request.high_mark < 0 || request.high_mark > entry->buf_count )
|
||||
return -EINVAL;
|
||||
|
||||
entry->freelist.low_mark = request.low_mark;
|
||||
entry->freelist.high_mark = request.high_mark;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(freebufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_free_t request;
|
||||
int i;
|
||||
int idx;
|
||||
drm_buf_t *buf;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_buf_free_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", request.count );
|
||||
for ( i = 0 ; i < request.count ; i++ ) {
|
||||
if ( copy_from_user( &idx,
|
||||
&request.list[i],
|
||||
sizeof(idx) ) )
|
||||
return -EFAULT;
|
||||
if ( idx < 0 || idx >= dma->buf_count ) {
|
||||
DRM_ERROR( "Index %d (of %d max)\n",
|
||||
idx, dma->buf_count - 1 );
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = dma->buflist[idx];
|
||||
if ( buf->pid != current->pid ) {
|
||||
DRM_ERROR( "Process %d freeing buffer owned by %d\n",
|
||||
current->pid, buf->pid );
|
||||
return -EINVAL;
|
||||
}
|
||||
DRM(free_buffer)( dev, buf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(mapbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int retcode = 0;
|
||||
const int zero = 0;
|
||||
unsigned long virtual;
|
||||
unsigned long address;
|
||||
drm_buf_map_t request;
|
||||
int i;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( atomic_read( &dev->buf_alloc ) ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
dev->buf_use++; /* Can't allocate more after this call */
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_map_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( request.count >= dma->buf_count ) {
|
||||
if ( __HAVE_AGP && (dma->flags & _DRM_DMA_USE_AGP) ) {
|
||||
DRIVER_DEV_PRIV_T *dev_priv = dev->dev_private;
|
||||
drm_map_t *map;
|
||||
|
||||
map = DRIVER_AGP_BUFFER_MAP;
|
||||
if ( !map ) {
|
||||
retcode = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
down( ¤t->mm->mmap_sem );
|
||||
virtual = do_mmap( filp, 0, map->size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
(unsigned long)map->offset );
|
||||
up( ¤t->mm->mmap_sem );
|
||||
} else {
|
||||
down( ¤t->mm->mmap_sem );
|
||||
virtual = do_mmap( filp, 0, dma->byte_count,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, 0 );
|
||||
up( ¤t->mm->mmap_sem );
|
||||
}
|
||||
if ( virtual > -1024UL ) {
|
||||
/* Real error */
|
||||
retcode = (signed long)virtual;
|
||||
goto done;
|
||||
}
|
||||
request.virtual = (void *)virtual;
|
||||
|
||||
for ( i = 0 ; i < dma->buf_count ; i++ ) {
|
||||
if ( copy_to_user( &request.list[i].idx,
|
||||
&dma->buflist[i]->idx,
|
||||
sizeof(request.list[0].idx) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if ( copy_to_user( &request.list[i].total,
|
||||
&dma->buflist[i]->total,
|
||||
sizeof(request.list[0].total) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if ( copy_to_user( &request.list[i].used,
|
||||
&zero,
|
||||
sizeof(zero) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
address = virtual + dma->buflist[i]->offset; /* *** */
|
||||
if ( copy_to_user( &request.list[i].address,
|
||||
&address,
|
||||
sizeof(address) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
request.count = dma->buf_count;
|
||||
DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode );
|
||||
|
||||
if ( copy_to_user( (drm_buf_map_t *)arg, &request, sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
return retcode;
|
||||
}
|
||||
272
linux-core/drm_context.c
Normal file
272
linux-core/drm_context.c
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
/* drm_context.h -- IOCTLs for generic contexts -*- linux-c -*-
|
||||
* Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
/* ================================================================
|
||||
* Context bitmap support
|
||||
*/
|
||||
|
||||
void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle )
|
||||
{
|
||||
if ( ctx_handle < 0 ) goto failed;
|
||||
|
||||
if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
|
||||
clear_bit( ctx_handle, dev->ctx_bitmap );
|
||||
return;
|
||||
}
|
||||
failed:
|
||||
DRM_ERROR( "Attempt to free invalid context handle: %d\n",
|
||||
ctx_handle );
|
||||
return;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_next)( drm_device_t *dev )
|
||||
{
|
||||
int bit;
|
||||
|
||||
bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
|
||||
if ( bit < DRM_MAX_CTXBITMAP ) {
|
||||
set_bit( bit, dev->ctx_bitmap );
|
||||
DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
|
||||
return bit;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_init)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
|
||||
dev->ctx_bitmap = (unsigned long *) DRM(alloc)( PAGE_SIZE,
|
||||
DRM_MEM_CTXBITMAP );
|
||||
if ( dev->ctx_bitmap == NULL ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
temp = DRM(ctxbitmap_next)( dev );
|
||||
DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(ctxbitmap_cleanup)( drm_device_t *dev )
|
||||
{
|
||||
DRM(free)( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
|
||||
}
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* The actual DRM context handling routines
|
||||
*/
|
||||
|
||||
int DRM(context_switch)( drm_device_t *dev, int old, int new )
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
atomic_inc( &dev->total_ctx );
|
||||
|
||||
if ( test_and_set_bit( 0, &dev->context_flag ) ) {
|
||||
DRM_ERROR( "Reentering -- FIXME\n" );
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG( "Context switch from %d to %d\n", old, new );
|
||||
|
||||
if ( new == dev->last_context ) {
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( DRM(flags) & DRM_FLAG_NOCTX ) {
|
||||
DRM(context_switch_complete)( dev, new );
|
||||
} else {
|
||||
sprintf( buf, "C %d %d\n", old, new );
|
||||
DRM(write_string)( dev, buf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(context_switch_complete)( drm_device_t *dev, int new )
|
||||
{
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
|
||||
DRM_ERROR( "Lock isn't held after context switch\n" );
|
||||
}
|
||||
|
||||
/* If a context switch is ever initiated
|
||||
when the kernel holds the lock, release
|
||||
that lock here. */
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc( &dev->histo.ctx[DRM(histogram_slot)(get_cycles()
|
||||
- dev->ctx_start)] );
|
||||
|
||||
#endif
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
wake_up( &dev->context_wait );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(resctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
if ( copy_from_user( &res, (drm_ctx_res_t *)arg, sizeof(res) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( res.count >= DRM_RESERVED_CONTEXTS ) {
|
||||
memset( &ctx, 0, sizeof(ctx) );
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
ctx.handle = i;
|
||||
if ( copy_to_user( &res.contexts[i],
|
||||
&i, sizeof(i) ) )
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
|
||||
if ( copy_to_user( (drm_ctx_res_t *)arg, &res, sizeof(res) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(addctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
if ( ctx.handle == DRM_KERNEL_CONTEXT ) {
|
||||
/* Skip kernel's context and get a new one. */
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
}
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle == -1 ) {
|
||||
DRM_DEBUG( "Not enough free contexts.\n" );
|
||||
/* Should this return -EBUSY instead? */
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if ( copy_to_user( (drm_ctx_t *)arg, &ctx, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(modctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
/* This does nothing */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t*)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
/* This is 0, because we don't handle any context flags */
|
||||
ctx.flags = 0;
|
||||
|
||||
if ( copy_to_user( (drm_ctx_t*)arg, &ctx, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(switchctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
return DRM(context_switch)( dev, dev->last_context, ctx.handle );
|
||||
}
|
||||
|
||||
int DRM(newctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
DRM(context_switch_complete)( dev, ctx.handle );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle == DRM_KERNEL_CONTEXT + 1 ) {
|
||||
priv->remove_auth_on_close = 1;
|
||||
}
|
||||
if ( ctx.handle != DRM_KERNEL_CONTEXT ) {
|
||||
DRM(ctxbitmap_free)( dev, ctx.handle );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* dma.c -- DMA IOCTL and function support -*- linux-c -*-
|
||||
* Created: Fri Mar 19 14:30:16 1999 by faith@precisioninsight.com
|
||||
/* drm_dma.c -- DMA IOCTL and function support -*- linux-c -*-
|
||||
* Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,22 +11,22 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinuxa.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
|
|
@ -34,23 +34,35 @@
|
|||
|
||||
#include <linux/interrupt.h> /* For task queue support */
|
||||
|
||||
void drm_dma_setup(drm_device_t *dev)
|
||||
#ifndef __HAVE_DMA_WAITQUEUE
|
||||
#define __HAVE_DMA_WAITQUEUE 0
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA
|
||||
|
||||
int DRM(dma_setup)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
dev->dma = drm_alloc(sizeof(*dev->dma), DRM_MEM_DRIVER);
|
||||
memset(dev->dma, 0, sizeof(*dev->dma));
|
||||
for (i = 0; i <= DRM_MAX_ORDER; i++)
|
||||
|
||||
dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER );
|
||||
if ( !dev->dma )
|
||||
return -ENOMEM;
|
||||
|
||||
memset( dev->dma, 0, sizeof(*dev->dma) );
|
||||
|
||||
for ( i = 0 ; i <= DRM_MAX_ORDER ; i++ )
|
||||
memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void drm_dma_takedown(drm_device_t *dev)
|
||||
void DRM(dma_takedown)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i, j;
|
||||
|
||||
if (!dma) return;
|
||||
|
||||
|
||||
/* Clear dma buffers */
|
||||
for (i = 0; i <= DRM_MAX_ORDER; i++) {
|
||||
if (dma->bufs[i].seg_count) {
|
||||
|
|
@ -60,49 +72,51 @@ void drm_dma_takedown(drm_device_t *dev)
|
|||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].seg_count);
|
||||
for (j = 0; j < dma->bufs[i].seg_count; j++) {
|
||||
drm_free_pages(dma->bufs[i].seglist[j],
|
||||
dma->bufs[i].page_order,
|
||||
DRM_MEM_DMA);
|
||||
DRM(free_pages)(dma->bufs[i].seglist[j],
|
||||
dma->bufs[i].page_order,
|
||||
DRM_MEM_DMA);
|
||||
}
|
||||
drm_free(dma->bufs[i].seglist,
|
||||
dma->bufs[i].seg_count
|
||||
* sizeof(*dma->bufs[0].seglist),
|
||||
DRM_MEM_SEGS);
|
||||
DRM(free)(dma->bufs[i].seglist,
|
||||
dma->bufs[i].seg_count
|
||||
* sizeof(*dma->bufs[0].seglist),
|
||||
DRM_MEM_SEGS);
|
||||
}
|
||||
if(dma->bufs[i].buf_count) {
|
||||
for(j = 0; j < dma->bufs[i].buf_count; j++) {
|
||||
if(dma->bufs[i].buflist[j].dev_private) {
|
||||
drm_free(dma->bufs[i].buflist[j].dev_private,
|
||||
dma->bufs[i].buflist[j].dev_priv_size,
|
||||
DRM_MEM_BUFS);
|
||||
DRM(free)(dma->bufs[i].buflist[j].dev_private,
|
||||
dma->bufs[i].buflist[j].dev_priv_size,
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
}
|
||||
drm_free(dma->bufs[i].buflist,
|
||||
dma->bufs[i].buf_count *
|
||||
sizeof(*dma->bufs[0].buflist),
|
||||
DRM_MEM_BUFS);
|
||||
drm_freelist_destroy(&dma->bufs[i].freelist);
|
||||
DRM(free)(dma->bufs[i].buflist,
|
||||
dma->bufs[i].buf_count *
|
||||
sizeof(*dma->bufs[0].buflist),
|
||||
DRM_MEM_BUFS);
|
||||
#if __HAVE_DMA_FREELIST
|
||||
DRM(freelist_destroy)(&dma->bufs[i].freelist);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (dma->buflist) {
|
||||
drm_free(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
DRM(free)(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
|
||||
if (dma->pagelist) {
|
||||
drm_free(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
DRM(free)(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
}
|
||||
drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
|
||||
DRM(free)(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
|
||||
dev->dma = NULL;
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
/* This is slow, but is useful for debugging. */
|
||||
int drm_histogram_slot(unsigned long count)
|
||||
int DRM(histogram_slot)(unsigned long count)
|
||||
{
|
||||
int value = DRM_DMA_HISTOGRAM_INITIAL;
|
||||
int slot;
|
||||
|
|
@ -115,13 +129,13 @@ int drm_histogram_slot(unsigned long count)
|
|||
return DRM_DMA_HISTOGRAM_SLOTS - 1;
|
||||
}
|
||||
|
||||
void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf)
|
||||
void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
cycles_t queued_to_dispatched;
|
||||
cycles_t dispatched_to_completed;
|
||||
cycles_t completed_to_freed;
|
||||
int q2d, d2c, c2f, q2c, q2f;
|
||||
|
||||
|
||||
if (buf->time_queued) {
|
||||
queued_to_dispatched = (buf->time_dispatched
|
||||
- buf->time_queued);
|
||||
|
|
@ -130,21 +144,21 @@ void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf)
|
|||
completed_to_freed = (buf->time_freed
|
||||
- buf->time_completed);
|
||||
|
||||
q2d = drm_histogram_slot(queued_to_dispatched);
|
||||
d2c = drm_histogram_slot(dispatched_to_completed);
|
||||
c2f = drm_histogram_slot(completed_to_freed);
|
||||
q2d = DRM(histogram_slot)(queued_to_dispatched);
|
||||
d2c = DRM(histogram_slot)(dispatched_to_completed);
|
||||
c2f = DRM(histogram_slot)(completed_to_freed);
|
||||
|
||||
q2c = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed);
|
||||
q2f = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed
|
||||
+ completed_to_freed);
|
||||
|
||||
q2c = drm_histogram_slot(queued_to_dispatched
|
||||
+ dispatched_to_completed);
|
||||
q2f = drm_histogram_slot(queued_to_dispatched
|
||||
+ dispatched_to_completed
|
||||
+ completed_to_freed);
|
||||
|
||||
atomic_inc(&dev->histo.total);
|
||||
atomic_inc(&dev->histo.queued_to_dispatched[q2d]);
|
||||
atomic_inc(&dev->histo.dispatched_to_completed[d2c]);
|
||||
atomic_inc(&dev->histo.completed_to_freed[c2f]);
|
||||
|
||||
|
||||
atomic_inc(&dev->histo.queued_to_completed[q2c]);
|
||||
atomic_inc(&dev->histo.queued_to_freed[q2f]);
|
||||
|
||||
|
|
@ -156,12 +170,10 @@ void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf)
|
|||
}
|
||||
#endif
|
||||
|
||||
void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
|
||||
void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
if (!buf) return;
|
||||
|
||||
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
buf->pid = 0;
|
||||
|
|
@ -169,18 +181,23 @@ void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
|
|||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_completed = get_cycles();
|
||||
#endif
|
||||
if (waitqueue_active(&buf->dma_wait)) {
|
||||
|
||||
if ( __HAVE_DMA_WAITQUEUE && waitqueue_active(&buf->dma_wait)) {
|
||||
wake_up_interruptible(&buf->dma_wait);
|
||||
} else {
|
||||
}
|
||||
#if __HAVE_DMA_FREELIST
|
||||
else {
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
/* If processes are waiting, the last one
|
||||
to wake will put the buffer on the free
|
||||
list. If no processes are waiting, we
|
||||
put the buffer on the freelist here. */
|
||||
drm_freelist_put(dev, &dma->bufs[buf->order].freelist, buf);
|
||||
DRM(freelist_put)(dev, &dma->bufs[buf->order].freelist, buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void drm_reclaim_buffers(drm_device_t *dev, pid_t pid)
|
||||
void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i;
|
||||
|
|
@ -190,7 +207,7 @@ void drm_reclaim_buffers(drm_device_t *dev, pid_t pid)
|
|||
if (dma->buflist[i]->pid == pid) {
|
||||
switch (dma->buflist[i]->list) {
|
||||
case DRM_LIST_NONE:
|
||||
drm_free_buffer(dev, dma->buflist[i]);
|
||||
DRM(free_buffer)(dev, dma->buflist[i]);
|
||||
break;
|
||||
case DRM_LIST_WAIT:
|
||||
dma->buflist[i]->list = DRM_LIST_RECLAIM;
|
||||
|
|
@ -203,6 +220,7 @@ void drm_reclaim_buffers(drm_device_t *dev, pid_t pid)
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int drm_context_switch(drm_device_t *dev, int old, int new)
|
||||
{
|
||||
char buf[64];
|
||||
|
|
@ -218,7 +236,7 @@ int drm_context_switch(drm_device_t *dev, int old, int new)
|
|||
#if DRM_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
|
||||
DRM_DEBUG("Context switch from %d to %d\n", old, new);
|
||||
|
||||
if (new >= dev->queue_count) {
|
||||
|
|
@ -230,7 +248,7 @@ int drm_context_switch(drm_device_t *dev, int old, int new)
|
|||
clear_bit(0, &dev->context_flag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
q = dev->queuelist[new];
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
|
|
@ -245,19 +263,19 @@ int drm_context_switch(drm_device_t *dev, int old, int new)
|
|||
sprintf(buf, "C %d %d\n", old, new);
|
||||
drm_write_string(dev, buf);
|
||||
}
|
||||
|
||||
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_context_switch_complete(drm_device_t *dev, int new)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
|
||||
DRM_ERROR("Lock isn't held after context switch\n");
|
||||
}
|
||||
|
|
@ -268,22 +286,26 @@ int drm_context_switch_complete(drm_device_t *dev, int new)
|
|||
DRM_ERROR("Cannot free lock\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.ctx[drm_histogram_slot(get_cycles()
|
||||
- dev->ctx_start)]);
|
||||
|
||||
|
||||
#endif
|
||||
clear_bit(0, &dev->context_flag);
|
||||
wake_up_interruptible(&dev->context_wait);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void drm_clear_next_buffer(drm_device_t *dev)
|
||||
|
||||
|
||||
#if 0
|
||||
void DRM(clear_next_buffer)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
|
||||
dma->next_buffer = NULL;
|
||||
if (dma->next_queue && !DRM_BUFCOUNT(&dma->next_queue->waitlist)) {
|
||||
wake_up_interruptible(&dma->next_queue->flush_queue);
|
||||
|
|
@ -291,8 +313,7 @@ void drm_clear_next_buffer(drm_device_t *dev)
|
|||
dma->next_queue = NULL;
|
||||
}
|
||||
|
||||
|
||||
int drm_select_queue(drm_device_t *dev, void (*wrapper)(unsigned long))
|
||||
int DRM(select_queue)(drm_device_t *dev, void (*wrapper)(unsigned long))
|
||||
{
|
||||
int i;
|
||||
int candidate = -1;
|
||||
|
|
@ -360,7 +381,7 @@ int drm_select_queue(drm_device_t *dev, void (*wrapper)(unsigned long))
|
|||
}
|
||||
|
||||
|
||||
int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *d)
|
||||
int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
|
||||
{
|
||||
int i;
|
||||
drm_queue_t *q;
|
||||
|
|
@ -374,7 +395,7 @@ int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *d)
|
|||
|
||||
if (d->flags & _DRM_DMA_WHILE_LOCKED) {
|
||||
int context = dev->lock.hw_lock->lock;
|
||||
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(context)) {
|
||||
DRM_ERROR("No lock held during \"while locked\""
|
||||
" request\n");
|
||||
|
|
@ -413,7 +434,7 @@ int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *d)
|
|||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue(&q->write_queue, &entry);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < d->send_count; i++) {
|
||||
idx = d->send_indices[i];
|
||||
if (idx < 0 || idx >= dma->buf_count) {
|
||||
|
|
@ -457,27 +478,27 @@ int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *d)
|
|||
buf->waiting = 1;
|
||||
if (atomic_read(&q->use_count) == 1
|
||||
|| atomic_read(&q->finalization)) {
|
||||
drm_free_buffer(dev, buf);
|
||||
DRM(free_buffer)(dev, buf);
|
||||
} else {
|
||||
drm_waitlist_put(&q->waitlist, buf);
|
||||
DRM(waitlist_put)(&q->waitlist, buf);
|
||||
atomic_inc(&q->total_queued);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int drm_dma_get_buffers_of_order(drm_device_t *dev, drm_dma_t *d,
|
||||
int order)
|
||||
static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d,
|
||||
int order)
|
||||
{
|
||||
int i;
|
||||
drm_buf_t *buf;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
|
||||
for (i = d->granted_count; i < d->request_count; i++) {
|
||||
buf = drm_freelist_get(&dma->bufs[order].freelist,
|
||||
d->flags & _DRM_DMA_WAIT);
|
||||
buf = DRM(freelist_get)(&dma->bufs[order].freelist,
|
||||
d->flags & _DRM_DMA_WAIT);
|
||||
if (!buf) break;
|
||||
if (buf->pending || buf->waiting) {
|
||||
DRM_ERROR("Free buffer %d in use by %d (w%d, p%d)\n",
|
||||
|
|
@ -503,16 +524,16 @@ static int drm_dma_get_buffers_of_order(drm_device_t *dev, drm_dma_t *d,
|
|||
}
|
||||
|
||||
|
||||
int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma)
|
||||
int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma)
|
||||
{
|
||||
int order;
|
||||
int retcode = 0;
|
||||
int tmp_order;
|
||||
|
||||
order = drm_order(dma->request_size);
|
||||
|
||||
order = DRM(order)(dma->request_size);
|
||||
|
||||
dma->granted_count = 0;
|
||||
retcode = drm_dma_get_buffers_of_order(dev, dma, order);
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma, order);
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_SMALLER_OK)) {
|
||||
|
|
@ -521,9 +542,9 @@ int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma)
|
|||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order >= DRM_MIN_ORDER;
|
||||
--tmp_order) {
|
||||
|
||||
retcode = drm_dma_get_buffers_of_order(dev, dma,
|
||||
tmp_order);
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -534,10 +555,14 @@ int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma)
|
|||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order <= DRM_MAX_ORDER;
|
||||
++tmp_order) {
|
||||
|
||||
retcode = drm_dma_get_buffers_of_order(dev, dma,
|
||||
tmp_order);
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* drawable.c -- IOCTLs for drawables -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@precisioninsight.com
|
||||
/* drm_drawable.h -- IOCTLs for drawables -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,29 +11,29 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int drm_adddraw(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(adddraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_draw_t draw;
|
||||
|
||||
|
|
@ -44,8 +44,8 @@ int drm_adddraw(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_rmdraw(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(rmdraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
return 0; /* NOOP */
|
||||
}
|
||||
842
linux-core/drm_drv.c
Normal file
842
linux-core/drm_drv.c
Normal file
|
|
@ -0,0 +1,842 @@
|
|||
/* drm_drv.h -- Generic driver template -*- linux-c -*-
|
||||
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
* To use this template, you must at least define the following (samples
|
||||
* given for the MGA driver):
|
||||
*
|
||||
* #define DRIVER_AUTHOR "VA Linux Systems, Inc."
|
||||
*
|
||||
* #define DRIVER_NAME "mga"
|
||||
* #define DRIVER_DESC "Matrox G200/G400"
|
||||
* #define DRIVER_DATE "20001127"
|
||||
*
|
||||
* #define DRIVER_MAJOR 2
|
||||
* #define DRIVER_MINOR 0
|
||||
* #define DRIVER_PATCHLEVEL 2
|
||||
*
|
||||
* #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( mga_ioctls )
|
||||
*
|
||||
* #define DRM(x) mga_##x
|
||||
*/
|
||||
|
||||
#ifndef __MUST_HAVE_AGP
|
||||
#define __MUST_HAVE_AGP 0
|
||||
#endif
|
||||
#ifndef __HAVE_CTX_BITMAP
|
||||
#define __HAVE_CTX_BITMAP 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_IRQ
|
||||
#define __HAVE_DMA_IRQ 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_QUEUE
|
||||
#define __HAVE_DMA_QUEUE 0
|
||||
#endif
|
||||
#ifndef __HAVE_MULTIPLE_DMA_QUEUES
|
||||
#define __HAVE_MULTIPLE_DMA_QUEUES 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_SCHEDULE
|
||||
#define __HAVE_DMA_SCHEDULE 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_FLUSH
|
||||
#define __HAVE_DMA_FLUSH 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_READY
|
||||
#define __HAVE_DMA_READY 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_QUIESCENT
|
||||
#define __HAVE_DMA_QUIESCENT 0
|
||||
#endif
|
||||
#ifndef __HAVE_DRIVER_RELEASE
|
||||
#define __HAVE_DRIVER_RELEASE 0
|
||||
#endif
|
||||
|
||||
#ifndef DRIVER_PREINIT
|
||||
#define DRIVER_PREINIT()
|
||||
#endif
|
||||
#ifndef DRIVER_POSTINIT
|
||||
#define DRIVER_POSTINIT()
|
||||
#endif
|
||||
#ifndef DRIVER_PRETAKEDOWN
|
||||
#define DRIVER_PRETAKEDOWN()
|
||||
#endif
|
||||
|
||||
|
||||
static drm_device_t DRM(device);
|
||||
|
||||
static struct file_operations DRM(fops) = {
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
/* This started being used during 2.4.0-test */
|
||||
owner: THIS_MODULE,
|
||||
#endif
|
||||
open: DRM(open),
|
||||
flush: DRM(flush),
|
||||
release: DRM(release),
|
||||
ioctl: DRM(ioctl),
|
||||
mmap: DRM(mmap),
|
||||
read: DRM(read),
|
||||
fasync: DRM(fasync),
|
||||
poll: DRM(poll),
|
||||
};
|
||||
|
||||
static struct miscdevice DRM(misc) = {
|
||||
minor: MISC_DYNAMIC_MINOR,
|
||||
name: DRIVER_NAME,
|
||||
fops: &DRM(fops),
|
||||
};
|
||||
|
||||
#ifdef MODULE
|
||||
static char *drm_opts = NULL;
|
||||
#endif
|
||||
|
||||
MODULE_AUTHOR( DRIVER_AUTHOR );
|
||||
MODULE_DESCRIPTION( DRIVER_DESC );
|
||||
MODULE_PARM( drm_opts, "s" );
|
||||
|
||||
#ifndef MODULE
|
||||
/* DRM(options) is called by the kernel to parse command-line options
|
||||
* passed via the boot-loader (e.g., LILO). It calls the insmod option
|
||||
* routine, drm_parse_drm.
|
||||
*/
|
||||
|
||||
static int __init DRM(options)( char *str )
|
||||
{
|
||||
DRM(parse_options)( str );
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup( DRIVER_NAME "=", DRM(options) );
|
||||
#endif
|
||||
|
||||
static int DRM(setup)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
atomic_set( &dev->ioctl_count, 0 );
|
||||
atomic_set( &dev->vma_count, 0 );
|
||||
dev->buf_use = 0;
|
||||
atomic_set( &dev->buf_alloc, 0 );
|
||||
|
||||
#if __HAVE_DMA
|
||||
i = DRM(dma_setup)( dev );
|
||||
if ( i < 0 )
|
||||
return i;
|
||||
#endif
|
||||
|
||||
atomic_set( &dev->total_open, 0 );
|
||||
atomic_set( &dev->total_close, 0 );
|
||||
atomic_set( &dev->total_ioctl, 0 );
|
||||
atomic_set( &dev->total_irq, 0 );
|
||||
atomic_set( &dev->total_ctx, 0 );
|
||||
atomic_set( &dev->total_locks, 0 );
|
||||
atomic_set( &dev->total_unlocks, 0 );
|
||||
atomic_set( &dev->total_contends, 0 );
|
||||
atomic_set( &dev->total_sleeps, 0 );
|
||||
|
||||
for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
|
||||
dev->magiclist[i].head = NULL;
|
||||
dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
dev->vmalist = NULL;
|
||||
dev->lock.hw_lock = NULL;
|
||||
init_waitqueue_head( &dev->lock.lock_queue );
|
||||
dev->queue_count = 0;
|
||||
dev->queue_reserved = 0;
|
||||
dev->queue_slots = 0;
|
||||
dev->queuelist = NULL;
|
||||
dev->irq = 0;
|
||||
dev->context_flag = 0;
|
||||
dev->interrupt_flag = 0;
|
||||
dev->dma_flag = 0;
|
||||
dev->last_context = 0;
|
||||
dev->last_switch = 0;
|
||||
dev->last_checked = 0;
|
||||
init_timer( &dev->timer );
|
||||
init_waitqueue_head( &dev->context_wait );
|
||||
|
||||
dev->ctx_start = 0;
|
||||
dev->lck_start = 0;
|
||||
|
||||
dev->buf_rp = dev->buf;
|
||||
dev->buf_wp = dev->buf;
|
||||
dev->buf_end = dev->buf + DRM_BSZ;
|
||||
dev->buf_async = NULL;
|
||||
init_waitqueue_head( &dev->buf_readers );
|
||||
init_waitqueue_head( &dev->buf_writers );
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
/* The kernel's context could be created here, but is now created
|
||||
* in drm_dma_enqueue. This is more resource-efficient for
|
||||
* hardware that does not do DMA, but may mean that
|
||||
* drm_select_queue fails between the time the interrupt is
|
||||
* initialized and the time the queues are initialized.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int DRM(takedown)( drm_device_t *dev )
|
||||
{
|
||||
drm_magic_entry_t *pt, *next;
|
||||
drm_map_t *map;
|
||||
drm_vma_entry_t *vma, *vma_next;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
DRIVER_PRETAKEDOWN();
|
||||
#if __HAVE_DMA_IRQ
|
||||
if ( dev->irq ) DRM(irq_uninstall)( dev );
|
||||
#endif
|
||||
|
||||
down( &dev->struct_sem );
|
||||
del_timer( &dev->timer );
|
||||
|
||||
if ( dev->devname ) {
|
||||
DRM(free)( dev->devname, strlen( dev->devname ) + 1,
|
||||
DRM_MEM_DRIVER );
|
||||
dev->devname = NULL;
|
||||
}
|
||||
|
||||
if ( dev->unique ) {
|
||||
DRM(free)( dev->unique, strlen( dev->unique ) + 1,
|
||||
DRM_MEM_DRIVER );
|
||||
dev->unique = NULL;
|
||||
dev->unique_len = 0;
|
||||
}
|
||||
/* Clear pid list */
|
||||
for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
|
||||
for ( pt = dev->magiclist[i].head ; pt ; pt = next ) {
|
||||
next = pt->next;
|
||||
DRM(free)( pt, sizeof(*pt), DRM_MEM_MAGIC );
|
||||
}
|
||||
dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
/* Clear AGP information */
|
||||
if ( dev->agp ) {
|
||||
drm_agp_mem_t *entry;
|
||||
drm_agp_mem_t *nexte;
|
||||
|
||||
/* Remove AGP resources, but leave dev->agp
|
||||
intact until drv_cleanup is called. */
|
||||
for ( entry = dev->agp->memory ; entry ; entry = nexte ) {
|
||||
nexte = entry->next;
|
||||
if ( entry->bound ) DRM(unbind_agp)( entry->memory );
|
||||
DRM(free_agp)( entry->memory, entry->pages );
|
||||
DRM(free)( entry, sizeof(*entry), DRM_MEM_AGPLISTS );
|
||||
}
|
||||
dev->agp->memory = NULL;
|
||||
|
||||
if ( dev->agp->acquired ) DRM(agp_do_release)();
|
||||
|
||||
dev->agp->acquired = 0;
|
||||
dev->agp->enabled = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clear vma list (only built for debugging) */
|
||||
if ( dev->vmalist ) {
|
||||
for ( vma = dev->vmalist ; vma ; vma = vma_next ) {
|
||||
vma_next = vma->next;
|
||||
DRM(free)( vma, sizeof(*vma), DRM_MEM_VMAS );
|
||||
}
|
||||
dev->vmalist = NULL;
|
||||
}
|
||||
|
||||
/* Clear map area and mtrr information */
|
||||
if ( dev->maplist ) {
|
||||
for ( i = 0 ; i < dev->map_count ; i++ ) {
|
||||
map = dev->maplist[i];
|
||||
switch ( map->type ) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#if __REALLY_HAVE_MTRR
|
||||
if ( map->mtrr >= 0 ) {
|
||||
int retcode;
|
||||
retcode = mtrr_del( map->mtrr,
|
||||
map->offset,
|
||||
map->size );
|
||||
DRM_DEBUG( "mtrr_del=%d\n", retcode );
|
||||
}
|
||||
#endif
|
||||
DRM(ioremapfree)( map->handle, map->size );
|
||||
break;
|
||||
case _DRM_SHM:
|
||||
DRM(free_pages)( (unsigned long)map->handle,
|
||||
DRM(order)( map->size )
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA );
|
||||
break;
|
||||
case _DRM_AGP:
|
||||
/* Do nothing here, because this is all
|
||||
* handled in the AGP/GART driver.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
}
|
||||
DRM(free)( dev->maplist,
|
||||
dev->map_count * sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS );
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
}
|
||||
|
||||
#if HAVE_DMA_QUEUE || HAVE_MULTIPLE_DMA_QUEUES
|
||||
if ( dev->queuelist ) {
|
||||
for ( i = 0 ; i < dev->queue_count ; i++ ) {
|
||||
DRM(waitlist_destroy)( &dev->queuelist[i]->waitlist );
|
||||
if ( dev->queuelist[i] ) {
|
||||
DRM(free)( dev->queuelist[i],
|
||||
sizeof(*dev->queuelist[0]),
|
||||
DRM_MEM_QUEUES );
|
||||
dev->queuelist[i] = NULL;
|
||||
}
|
||||
}
|
||||
DRM(free)( dev->queuelist,
|
||||
dev->queue_slots * sizeof(*dev->queuelist),
|
||||
DRM_MEM_QUEUES );
|
||||
dev->queuelist = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA
|
||||
DRM(dma_takedown)( dev );
|
||||
#endif
|
||||
|
||||
dev->queue_count = 0;
|
||||
if ( dev->lock.hw_lock ) {
|
||||
dev->lock.hw_lock = NULL; /* SHM removed */
|
||||
dev->lock.pid = 0;
|
||||
wake_up_interruptible( &dev->lock.lock_queue );
|
||||
}
|
||||
up( &dev->struct_sem );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* drm_init is called via init_module at module load time, or via
|
||||
* linux/init/main.c (this is not currently supported).
|
||||
*/
|
||||
static int __init drm_init( void )
|
||||
{
|
||||
int retcode;
|
||||
drm_device_t *dev = &DRM(device);
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
memset( (void *)dev, 0, sizeof(*dev) );
|
||||
dev->count_lock = SPIN_LOCK_UNLOCKED;
|
||||
sema_init( &dev->struct_sem, 1 );
|
||||
|
||||
#ifdef MODULE
|
||||
DRM(parse_options)( drm_opts );
|
||||
#endif
|
||||
DRIVER_PREINIT();
|
||||
|
||||
retcode = misc_register( &DRM(misc) );
|
||||
if ( retcode ) {
|
||||
DRM_ERROR( "Cannot register \"%s\"\n", DRIVER_NAME );
|
||||
return retcode;
|
||||
}
|
||||
dev->device = MKDEV( MISC_MAJOR, DRM(misc).minor );
|
||||
dev->name = DRIVER_NAME;
|
||||
|
||||
DRM(mem_init)();
|
||||
DRM(proc_init)( dev );
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
dev->agp = DRM(agp_init)();
|
||||
#if __MUST_HAVE_AGP
|
||||
if ( dev->agp == NULL ) {
|
||||
DRM_ERROR( "Cannot initialize the agpgart module.\n" );
|
||||
DRM(proc_cleanup)();
|
||||
misc_deregister( &DRM(misc) );
|
||||
DRM(takedown)( dev );
|
||||
return -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
#if __REALLY_HAVE_MTRR
|
||||
dev->agp->agp_mtrr = mtrr_add( dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size*1024*1024,
|
||||
MTRR_TYPE_WRCOMB,
|
||||
1 );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __HAVE_CTX_BITMAP
|
||||
retcode = DRM(ctxbitmap_init)( dev );
|
||||
if( retcode ) {
|
||||
DRM_ERROR( "Cannot allocate memory for context bitmap.\n" );
|
||||
DRM(proc_cleanup)();
|
||||
misc_deregister( &DRM(misc) );
|
||||
DRM(takedown)( dev );
|
||||
return retcode;
|
||||
}
|
||||
#endif
|
||||
|
||||
DRIVER_POSTINIT();
|
||||
|
||||
DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d\n",
|
||||
DRIVER_NAME,
|
||||
DRIVER_MAJOR,
|
||||
DRIVER_MINOR,
|
||||
DRIVER_PATCHLEVEL,
|
||||
DRIVER_DATE,
|
||||
DRM(misc).minor );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* drm_cleanup is called via cleanup_module at module unload time.
|
||||
*/
|
||||
static void __exit drm_cleanup( void )
|
||||
{
|
||||
drm_device_t *dev = &DRM(device);
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
DRM(proc_cleanup)();
|
||||
if ( misc_deregister( &DRM(misc) ) ) {
|
||||
DRM_ERROR( "Cannot unload module\n" );
|
||||
} else {
|
||||
DRM_INFO( "Module unloaded\n" );
|
||||
}
|
||||
#if __HAVE_CTX_BITMAP
|
||||
DRM(ctxbitmap_cleanup)( dev );
|
||||
#endif
|
||||
|
||||
#if __REALLY_HAVE_MTRR
|
||||
if ( dev->agp && dev->agp->agp_mtrr ) {
|
||||
int retval;
|
||||
retval = mtrr_del( dev->agp->agp_mtrr,
|
||||
dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size*1024*1024 );
|
||||
DRM_DEBUG( "mtrr_del=%d\n", retval );
|
||||
}
|
||||
#endif
|
||||
|
||||
DRM(takedown)( dev );
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
if ( dev->agp ) {
|
||||
DRM(agp_uninit)();
|
||||
DRM(free)( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS );
|
||||
dev->agp = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
module_init( drm_init );
|
||||
module_exit( drm_cleanup );
|
||||
|
||||
|
||||
int DRM(version)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_version_t version;
|
||||
int len;
|
||||
|
||||
if ( copy_from_user( &version,
|
||||
(drm_version_t *)arg,
|
||||
sizeof(version) ) )
|
||||
return -EFAULT;
|
||||
|
||||
#define DRM_COPY( name, value ) \
|
||||
len = strlen( value ); \
|
||||
if ( len > name##_len ) len = name##_len; \
|
||||
name##_len = strlen( value ); \
|
||||
if ( len && name ) { \
|
||||
if ( copy_to_user( name, value, len ) ) \
|
||||
return -EFAULT; \
|
||||
}
|
||||
|
||||
version.version_major = DRIVER_MAJOR;
|
||||
version.version_minor = DRIVER_MINOR;
|
||||
version.version_patchlevel = DRIVER_PATCHLEVEL;
|
||||
|
||||
DRM_COPY( version.name, DRIVER_NAME );
|
||||
DRM_COPY( version.date, DRIVER_DATE );
|
||||
DRM_COPY( version.desc, DRIVER_DESC );
|
||||
|
||||
if ( copy_to_user( (drm_version_t *)arg,
|
||||
&version,
|
||||
sizeof(version) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(open)( struct inode *inode, struct file *filp )
|
||||
{
|
||||
drm_device_t *dev = &DRM(device);
|
||||
int retcode = 0;
|
||||
|
||||
DRM_DEBUG( "open_count = %d\n", dev->open_count );
|
||||
|
||||
retcode = DRM(open_helper)( inode, filp, dev );
|
||||
if ( !retcode ) {
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_inc( &dev->total_open );
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( !dev->open_count++ ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return DRM(setup)( dev );
|
||||
}
|
||||
spin_unlock( &dev->count_lock );
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int DRM(release)( struct inode *inode, struct file *filp )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev;
|
||||
int retcode = 0;
|
||||
|
||||
lock_kernel();
|
||||
dev = priv->dev;
|
||||
|
||||
DRM_DEBUG( "open_count = %d\n", dev->open_count );
|
||||
|
||||
/* ========================================================
|
||||
* Begin inline drm_release
|
||||
*/
|
||||
|
||||
DRM_DEBUG( "pid = %d, device = 0x%x, open_count = %d\n",
|
||||
current->pid, dev->device, dev->open_count );
|
||||
|
||||
if ( dev->lock.hw_lock &&
|
||||
_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
|
||||
dev->lock.pid == current->pid ) {
|
||||
DRM_ERROR( "Process %d dead, freeing lock for context %d\n",
|
||||
current->pid,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
|
||||
#if __HAVE_DRIVER_RELEASE
|
||||
DRIVER_RELEASE();
|
||||
#endif
|
||||
DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
|
||||
|
||||
/* FIXME: may require heavy-handed reset of
|
||||
hardware at this point, possibly
|
||||
processed via a callback to the X
|
||||
server. */
|
||||
}
|
||||
#if __HAVE_DRIVER_RELEASE
|
||||
else if ( dev->lock.hw_lock ) {
|
||||
/* The lock is required to reclaim buffers */
|
||||
DECLARE_WAITQUEUE( entry, current );
|
||||
add_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if ( !dev->lock.hw_lock ) {
|
||||
/* Device has been unregistered */
|
||||
retcode = -EINTR;
|
||||
break;
|
||||
}
|
||||
if ( DRM(lock_take)( &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT ) ) {
|
||||
dev->lock.pid = priv->pid;
|
||||
dev->lock.lock_time = jiffies;
|
||||
atomic_inc( &dev->total_locks );
|
||||
break; /* Got lock */
|
||||
}
|
||||
/* Contention */
|
||||
atomic_inc( &dev->total_sleeps );
|
||||
schedule();
|
||||
if ( signal_pending( current ) ) {
|
||||
retcode = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
if( !retcode ) {
|
||||
DRIVER_RELEASE();
|
||||
DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT );
|
||||
}
|
||||
}
|
||||
#else
|
||||
DRM(reclaim_buffers)( dev, priv->pid );
|
||||
#endif
|
||||
|
||||
DRM(fasync)( -1, filp, 0 );
|
||||
|
||||
down( &dev->struct_sem );
|
||||
if ( priv->remove_auth_on_close == 1 ) {
|
||||
drm_file_t *temp = dev->file_first;
|
||||
while ( temp ) {
|
||||
temp->authenticated = 0;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
if ( priv->prev ) {
|
||||
priv->prev->next = priv->next;
|
||||
} else {
|
||||
dev->file_first = priv->next;
|
||||
}
|
||||
if ( priv->next ) {
|
||||
priv->next->prev = priv->prev;
|
||||
} else {
|
||||
dev->file_last = priv->prev;
|
||||
}
|
||||
up( &dev->struct_sem );
|
||||
|
||||
DRM(free)( priv, sizeof(*priv), DRM_MEM_FILES );
|
||||
|
||||
/* ========================================================
|
||||
* End inline drm_release
|
||||
*/
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_DEC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_inc( &dev->total_close );
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( !--dev->open_count ) {
|
||||
if ( atomic_read( &dev->ioctl_count ) || dev->blocked ) {
|
||||
DRM_ERROR( "Device busy: %d %d\n",
|
||||
atomic_read( &dev->ioctl_count ),
|
||||
dev->blocked );
|
||||
spin_unlock( &dev->count_lock );
|
||||
unlock_kernel();
|
||||
return -EBUSY;
|
||||
}
|
||||
spin_unlock( &dev->count_lock );
|
||||
unlock_kernel();
|
||||
return DRM(takedown)( dev );
|
||||
}
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
unlock_kernel();
|
||||
return retcode;
|
||||
}
|
||||
|
||||
/* DRM(ioctl) is called whenever a process performs an ioctl on /dev/drm.
|
||||
*/
|
||||
int DRM(ioctl)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ioctl_desc_t *ioctl;
|
||||
drm_ioctl_t *func;
|
||||
int nr = DRM_IOCTL_NR(cmd);
|
||||
int retcode = 0;
|
||||
|
||||
atomic_inc( &dev->ioctl_count );
|
||||
atomic_inc( &dev->total_ioctl );
|
||||
++priv->ioctl_count;
|
||||
|
||||
DRM_DEBUG( "pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%x, auth=%d\n",
|
||||
current->pid, cmd, nr, dev->device, priv->authenticated );
|
||||
|
||||
if ( nr >= DRIVER_IOCTL_COUNT ) {
|
||||
retcode = -EINVAL;
|
||||
} else {
|
||||
ioctl = &DRM(ioctls)[nr];
|
||||
func = ioctl->func;
|
||||
|
||||
if ( !func ) {
|
||||
DRM_DEBUG( "no function\n" );
|
||||
retcode = -EINVAL;
|
||||
} else if ( ( ioctl->root_only && !capable( CAP_SYS_ADMIN ) )||
|
||||
( ioctl->auth_needed && !priv->authenticated ) ) {
|
||||
retcode = -EACCES;
|
||||
} else {
|
||||
retcode = func( inode, filp, cmd, arg );
|
||||
}
|
||||
}
|
||||
|
||||
atomic_dec( &dev->ioctl_count );
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int DRM(lock)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
DECLARE_WAITQUEUE( entry, current );
|
||||
drm_lock_t lock;
|
||||
int ret = 0;
|
||||
#if __HAVE_MULTIPLE_DMA_QUEUES
|
||||
drm_queue_t *q;
|
||||
#endif
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
cycles_t start;
|
||||
|
||||
dev->lck_start = start = get_cycles();
|
||||
#endif
|
||||
|
||||
if ( copy_from_user( &lock, (drm_lock_t *)arg, sizeof(lock) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( lock.context == DRM_KERNEL_CONTEXT ) {
|
||||
DRM_ERROR( "Process %d using kernel context %d\n",
|
||||
current->pid, lock.context );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
|
||||
lock.context, current->pid,
|
||||
dev->lock.hw_lock->lock, lock.flags );
|
||||
|
||||
#if __HAVE_DMA_QUEUE
|
||||
if ( lock.context < 0 )
|
||||
return -EINVAL;
|
||||
#elif __HAVE_MULTIPLE_DMA_QUEUES
|
||||
if ( lock.context < 0 || lock.context >= dev->queue_count )
|
||||
return -EINVAL;
|
||||
q = dev->queuelist[lock.context];
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA_FLUSH
|
||||
ret = drm_flush_block_and_flush( dev, lock.context, lock.flags );
|
||||
#endif
|
||||
if ( !ret ) {
|
||||
/* FIXME: do gamma stuff???
|
||||
*/
|
||||
|
||||
add_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if ( !dev->lock.hw_lock ) {
|
||||
/* Device has been unregistered */
|
||||
ret = -EINTR;
|
||||
break;
|
||||
}
|
||||
if ( DRM(lock_take)( &dev->lock.hw_lock->lock,
|
||||
lock.context ) ) {
|
||||
dev->lock.pid = current->pid;
|
||||
dev->lock.lock_time = jiffies;
|
||||
atomic_inc( &dev->total_locks );
|
||||
#if __HAVE_MULTIPLE_DMA_QUEUES
|
||||
atomic_inc( &q->total_locks );
|
||||
#endif
|
||||
break; /* Got lock */
|
||||
}
|
||||
|
||||
/* Contention */
|
||||
atomic_inc( &dev->total_sleeps );
|
||||
schedule();
|
||||
if ( signal_pending( current ) ) {
|
||||
ret = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_FLUSH
|
||||
DRM(flush_unblock)( dev, lock.context, lock.flags ); /* cleanup phase */
|
||||
#endif
|
||||
|
||||
if ( !ret ) {
|
||||
sigemptyset( &dev->sigmask );
|
||||
sigaddset( &dev->sigmask, SIGSTOP );
|
||||
sigaddset( &dev->sigmask, SIGTSTP );
|
||||
sigaddset( &dev->sigmask, SIGTTIN );
|
||||
sigaddset( &dev->sigmask, SIGTTOU );
|
||||
dev->sigdata.context = lock.context;
|
||||
dev->sigdata.lock = dev->lock.hw_lock;
|
||||
block_all_signals( DRM(notifier),
|
||||
&dev->sigdata, &dev->sigmask );
|
||||
|
||||
#if __HAVE_DMA_READY
|
||||
if ( lock.flags & _DRM_LOCK_READY ) {
|
||||
DRIVER_DMA_READY();
|
||||
}
|
||||
#endif
|
||||
#if __HAVE_DMA_QUIESCENT
|
||||
if ( lock.flags & _DRM_LOCK_QUIESCENT ) {
|
||||
DRIVER_DMA_QUIESCENT();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DRM_DEBUG( "%d %s\n", lock.context, ret ? "interrupted" : "has lock" );
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.lacq[DRM(histogram_slot)(get_cycles()-start)]);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int DRM(unlock)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_lock_t lock;
|
||||
|
||||
if ( copy_from_user( &lock, (drm_lock_t *)arg, sizeof(lock) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( lock.context == DRM_KERNEL_CONTEXT ) {
|
||||
DRM_ERROR( "Process %d using kernel context %d\n",
|
||||
current->pid, lock.context );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
atomic_inc( &dev->total_unlocks );
|
||||
if ( _DRM_LOCK_IS_CONT( dev->lock.hw_lock->lock ) )
|
||||
atomic_inc( &dev->total_contends );
|
||||
|
||||
DRM(lock_transfer)( dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT );
|
||||
#if __HAVE_DMA_SCHEDULE
|
||||
DRM(dma_schedule)( dev, 1 );
|
||||
#endif
|
||||
|
||||
/* FIXME: Do we ever really need to check this???
|
||||
*/
|
||||
if ( 1 /* !dev->context_flag */ ) {
|
||||
if ( DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT ) ) {
|
||||
DRM_ERROR( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
unblock_all_signals();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* fops.c -- File operations for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@precisioninsight.com
|
||||
/* drm_fops.h -- File operations for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,23 +11,23 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Daryll Strauss <daryll@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Daryll Strauss <daryll@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
|
|
@ -36,17 +36,17 @@
|
|||
|
||||
/* drm_open is called whenever a process opens /dev/drm. */
|
||||
|
||||
int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev)
|
||||
int DRM(open_helper)(struct inode *inode, struct file *filp, drm_device_t *dev)
|
||||
{
|
||||
kdev_t minor = MINOR(inode->i_rdev);
|
||||
drm_file_t *priv;
|
||||
|
||||
if (filp->f_flags & O_EXCL) return -EBUSY; /* No exclusive opens */
|
||||
if (!drm_cpu_valid()) return -EINVAL;
|
||||
if (!DRM(cpu_valid)()) return -EINVAL;
|
||||
|
||||
DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
|
||||
|
||||
priv = drm_alloc(sizeof(*priv), DRM_MEM_FILES);
|
||||
priv = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
|
||||
memset(priv, 0, sizeof(*priv));
|
||||
filp->private_data = priv;
|
||||
priv->uid = current->euid;
|
||||
|
|
@ -69,11 +69,11 @@ int drm_open_helper(struct inode *inode, struct file *filp, drm_device_t *dev)
|
|||
dev->file_last = priv;
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_flush(struct file *filp)
|
||||
int DRM(flush)(struct file *filp)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -83,6 +83,7 @@ int drm_flush(struct file *filp)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* drm_release is called whenever a process closes /dev/drm*. Linux calls
|
||||
this only if any mappings have been closed. */
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ int drm_release(struct inode *inode, struct file *filp)
|
|||
drm_lock_free(dev,
|
||||
&dev->lock.hw_lock->lock,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
|
||||
|
||||
|
||||
/* FIXME: may require heavy-handed reset of
|
||||
hardware at this point, possibly
|
||||
processed via a callback to the X
|
||||
|
|
@ -119,18 +120,19 @@ int drm_release(struct inode *inode, struct file *filp)
|
|||
if (priv->next) priv->next->prev = priv->prev;
|
||||
else dev->file_last = priv->prev;
|
||||
up(&dev->struct_sem);
|
||||
|
||||
|
||||
drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int drm_fasync(int fd, struct file *filp, int on)
|
||||
int DRM(fasync)(int fd, struct file *filp, int on)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int retcode;
|
||||
|
||||
|
||||
DRM_DEBUG("fd = %d, device = 0x%x\n", fd, dev->device);
|
||||
retcode = fasync_helper(fd, filp, on, &dev->buf_async);
|
||||
if (retcode < 0) return retcode;
|
||||
|
|
@ -142,7 +144,7 @@ int drm_fasync(int fd, struct file *filp, int on)
|
|||
the circular buffer), is based on Alessandro Rubini's LINUX DEVICE
|
||||
DRIVERS (Cambridge: O'Reilly, 1998), pages 111-113. */
|
||||
|
||||
ssize_t drm_read(struct file *filp, char *buf, size_t count, loff_t *off)
|
||||
ssize_t DRM(read)(struct file *filp, char *buf, size_t count, loff_t *off)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -152,7 +154,7 @@ ssize_t drm_read(struct file *filp, char *buf, size_t count, loff_t *off)
|
|||
int cur;
|
||||
|
||||
DRM_DEBUG("%p, %p\n", dev->buf_rp, dev->buf_wp);
|
||||
|
||||
|
||||
while (dev->buf_rp == dev->buf_wp) {
|
||||
DRM_DEBUG(" sleeping\n");
|
||||
if (filp->f_flags & O_NONBLOCK) {
|
||||
|
|
@ -182,12 +184,12 @@ ssize_t drm_read(struct file *filp, char *buf, size_t count, loff_t *off)
|
|||
if (dev->buf_rp == dev->buf_end) dev->buf_rp = dev->buf;
|
||||
send -= cur;
|
||||
}
|
||||
|
||||
|
||||
wake_up_interruptible(&dev->buf_writers);
|
||||
return DRM_MIN(avail, count);;
|
||||
}
|
||||
|
||||
int drm_write_string(drm_device_t *dev, const char *s)
|
||||
int DRM(write_string)(drm_device_t *dev, const char *s)
|
||||
{
|
||||
int left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
int send = strlen(s);
|
||||
|
|
@ -195,7 +197,7 @@ int drm_write_string(drm_device_t *dev, const char *s)
|
|||
|
||||
DRM_DEBUG("%d left, %d to send (%p, %p)\n",
|
||||
left, send, dev->buf_rp, dev->buf_wp);
|
||||
|
||||
|
||||
if (left == 1 || dev->buf_wp != dev->buf_rp) {
|
||||
DRM_ERROR("Buffer not empty (%d left, wp = %p, rp = %p)\n",
|
||||
left,
|
||||
|
|
@ -239,7 +241,7 @@ int drm_write_string(drm_device_t *dev, const char *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
|
||||
unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* init.c -- Setup/Cleanup for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@precisioninsight.com
|
||||
/* drm_init.h -- Setup/Cleanup for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,48 +11,48 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int drm_flags = 0;
|
||||
int DRM(flags) = 0;
|
||||
|
||||
/* drm_parse_option parses a single option. See description for
|
||||
drm_parse_options for details. */
|
||||
|
||||
static void drm_parse_option(char *s)
|
||||
* drm_parse_options for details.
|
||||
*/
|
||||
static void DRM(parse_option)(char *s)
|
||||
{
|
||||
char *c, *r;
|
||||
|
||||
|
||||
DRM_DEBUG("\"%s\"\n", s);
|
||||
if (!s || !*s) return;
|
||||
for (c = s; *c && *c != ':'; c++); /* find : or \0 */
|
||||
if (*c) r = c + 1; else r = NULL; /* remember remainder */
|
||||
*c = '\0'; /* terminate */
|
||||
if (!strcmp(s, "noctx")) {
|
||||
drm_flags |= DRM_FLAG_NOCTX;
|
||||
DRM(flags) |= DRM_FLAG_NOCTX;
|
||||
DRM_INFO("Server-mediated context switching OFF\n");
|
||||
return;
|
||||
}
|
||||
if (!strcmp(s, "debug")) {
|
||||
drm_flags |= DRM_FLAG_DEBUG;
|
||||
DRM(flags) |= DRM_FLAG_DEBUG;
|
||||
DRM_INFO("Debug messages ON\n");
|
||||
return;
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ static void drm_parse_option(char *s)
|
|||
* drm ::= 'drm=' option_list
|
||||
* option_list ::= option [ ';' option_list ]
|
||||
* option ::= 'device:' major
|
||||
* | 'debug'
|
||||
* | 'debug'
|
||||
* | 'noctx'
|
||||
* major ::= INTEGER
|
||||
*
|
||||
|
|
@ -82,10 +82,10 @@ static void drm_parse_option(char *s)
|
|||
*
|
||||
*/
|
||||
|
||||
void drm_parse_options(char *s)
|
||||
void DRM(parse_options)(char *s)
|
||||
{
|
||||
char *h, *t, *n;
|
||||
|
||||
|
||||
DRM_DEBUG("\"%s\"\n", s ?: "");
|
||||
if (!s || !*s) return;
|
||||
|
||||
|
|
@ -93,21 +93,20 @@ void drm_parse_options(char *s)
|
|||
for (; *t && *t != ';'; t++); /* find ; or \0 */
|
||||
if (*t) n = t + 1; else n = NULL; /* remember next */
|
||||
*t = '\0'; /* terminate */
|
||||
drm_parse_option(h); /* parse */
|
||||
DRM(parse_option)(h); /* parse */
|
||||
}
|
||||
}
|
||||
|
||||
/* drm_cpu_valid returns non-zero if the DRI will run on this CPU, and 0
|
||||
* otherwise. */
|
||||
|
||||
int drm_cpu_valid(void)
|
||||
* otherwise.
|
||||
*/
|
||||
int DRM(cpu_valid)(void)
|
||||
{
|
||||
#if defined(__i386__)
|
||||
if (boot_cpu_data.x86 == 3) return 0; /* No cmpxchg on a 386 */
|
||||
#endif
|
||||
#if defined(__sparc__) && !defined(__sparc_v9__)
|
||||
if (1)
|
||||
return 0; /* No cmpxchg before v9 sparc. */
|
||||
return 0; /* No cmpxchg before v9 sparc. */
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* ioctl.c -- IOCTL processing for DRM -*- linux-c -*-
|
||||
* Created: Fri Jan 8 09:01:26 1999 by faith@precisioninsight.com
|
||||
/* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
|
||||
* Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,29 +11,29 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int drm_irq_busid(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(irq_busid)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_irq_busid_t p;
|
||||
struct pci_dev *dev;
|
||||
|
|
@ -50,8 +50,8 @@ int drm_irq_busid(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_getunique(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(getunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -69,8 +69,8 @@ int drm_getunique(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_setunique(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(setunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -84,15 +84,15 @@ int drm_setunique(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
|
||||
if (!u.unique_len)
|
||||
return -EINVAL;
|
||||
|
||||
|
||||
dev->unique_len = u.unique_len;
|
||||
dev->unique = drm_alloc(u.unique_len + 1, DRM_MEM_DRIVER);
|
||||
dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
|
||||
if (copy_from_user(dev->unique, u.unique, dev->unique_len))
|
||||
return -EFAULT;
|
||||
dev->unique[dev->unique_len] = '\0';
|
||||
|
||||
dev->devname = drm_alloc(strlen(dev->name) + strlen(dev->unique) + 2,
|
||||
DRM_MEM_DRIVER);
|
||||
dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
|
||||
DRM_MEM_DRIVER);
|
||||
sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
|
||||
|
||||
return 0;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* lock.c -- IOCTLs for locking -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@precisioninsight.com
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,42 +11,46 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int drm_block(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
#ifndef HAVE_DMA_QUEUE
|
||||
#define HAVE_DMA_QUEUE 0
|
||||
#endif
|
||||
|
||||
int DRM(block)(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_unblock(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(unblock)(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
|
||||
int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new, prev;
|
||||
|
||||
|
|
@ -74,8 +78,8 @@ int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context)
|
|||
|
||||
/* This takes a lock forcibly and hands it to context. Should ONLY be used
|
||||
inside *_unlock to give lock to kernel before calling *_dma_schedule. */
|
||||
int drm_lock_transfer(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
int DRM(lock_transfer)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new, prev;
|
||||
|
||||
|
|
@ -88,8 +92,8 @@ int drm_lock_transfer(drm_device_t *dev,
|
|||
return 1;
|
||||
}
|
||||
|
||||
int drm_lock_free(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
int DRM(lock_free)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new, prev;
|
||||
pid_t pid = dev->lock.pid;
|
||||
|
|
@ -111,14 +115,14 @@ int drm_lock_free(drm_device_t *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int drm_flush_queue(drm_device_t *dev, int context)
|
||||
static int DRM(flush_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
DECLARE_WAITQUEUE(entry, current);
|
||||
int ret = 0;
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
atomic_inc(&q->block_write);
|
||||
|
|
@ -139,18 +143,18 @@ static int drm_flush_queue(drm_device_t *dev, int context)
|
|||
}
|
||||
atomic_dec(&q->use_count);
|
||||
atomic_inc(&q->total_flushed);
|
||||
|
||||
|
||||
/* NOTE: block_write is still incremented!
|
||||
Use drm_flush_unlock_queue to decrement. */
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int drm_flush_unblock_queue(drm_device_t *dev, int context)
|
||||
static int DRM(flush_unblock_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
if (atomic_read(&q->block_write)) {
|
||||
|
|
@ -162,48 +166,48 @@ static int drm_flush_unblock_queue(drm_device_t *dev, int context)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_flush_block_and_flush(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags)
|
||||
int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = drm_flush_queue(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = drm_flush_queue(dev, context);
|
||||
ret = DRM(flush_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = drm_flush_queue(dev, i);
|
||||
ret = DRM(flush_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int drm_flush_unblock(drm_device_t *dev, int context, drm_lock_flags_t flags)
|
||||
int DRM(flush_unblock)(drm_device_t *dev, int context, drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = drm_flush_unblock_queue(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = drm_flush_unblock_queue(dev, context);
|
||||
ret = DRM(flush_unblock_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_unblock_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = drm_flush_unblock_queue(dev, i);
|
||||
ret = DRM(flush_unblock_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int drm_finish(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
int DRM(finish)(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -214,24 +218,24 @@ int drm_finish(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
|
||||
if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
|
||||
return -EFAULT;
|
||||
ret = drm_flush_block_and_flush(dev, lock.context, lock.flags);
|
||||
drm_flush_unblock(dev, lock.context, lock.flags);
|
||||
ret = DRM(flush_block_and_flush)(dev, lock.context, lock.flags);
|
||||
DRM(flush_unblock)(dev, lock.context, lock.flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If we get here, it means that the process has called DRM_IOCTL_LOCK
|
||||
without calling DRM_IOCTL_UNLOCK.
|
||||
|
||||
|
||||
If the lock is not held, then let the signal proceed as usual.
|
||||
|
||||
|
||||
If the lock is held, then set the contended flag and keep the signal
|
||||
blocked.
|
||||
|
||||
|
||||
|
||||
Return 1 if the signal should be delivered normally.
|
||||
Return 0 if the signal should be blocked. */
|
||||
|
||||
int drm_notifier(void *priv)
|
||||
int DRM(notifier)(void *priv)
|
||||
{
|
||||
drm_sigdata_t *s = (drm_sigdata_t *)priv;
|
||||
unsigned int old, new, prev;
|
||||
|
|
@ -240,7 +244,7 @@ int drm_notifier(void *priv)
|
|||
/* Allow signal delivery if lock isn't held */
|
||||
if (!_DRM_LOCK_IS_HELD(s->lock->lock)
|
||||
|| _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context) return 1;
|
||||
|
||||
|
||||
/* Otherwise, set flag to force call to
|
||||
drmUnlock */
|
||||
do {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* memory.c -- Memory management wrappers for DRM -*- linux-c -*-
|
||||
* Created: Thu Feb 4 14:00:34 1999 by faith@precisioninsight.com
|
||||
/* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
|
||||
* Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,22 +11,22 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
|
|
@ -69,11 +69,11 @@ static drm_mem_stats_t drm_mem_stats[] = {
|
|||
{ NULL, 0, } /* Last entry must be null */
|
||||
};
|
||||
|
||||
void drm_mem_init(void)
|
||||
void DRM(mem_init)(void)
|
||||
{
|
||||
drm_mem_stats_t *mem;
|
||||
struct sysinfo si;
|
||||
|
||||
|
||||
for (mem = drm_mem_stats; mem->name; ++mem) {
|
||||
mem->succeed_count = 0;
|
||||
mem->free_count = 0;
|
||||
|
|
@ -81,7 +81,7 @@ void drm_mem_init(void)
|
|||
mem->bytes_allocated = 0;
|
||||
mem->bytes_freed = 0;
|
||||
}
|
||||
|
||||
|
||||
si_meminfo(&si);
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
/* Changed to page count in 2.3.23 */
|
||||
|
|
@ -94,8 +94,8 @@ void drm_mem_init(void)
|
|||
|
||||
/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
|
||||
|
||||
static int _drm_mem_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
static int _drm_mem_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data)
|
||||
{
|
||||
drm_mem_stats_t *pt;
|
||||
|
||||
|
|
@ -124,30 +124,30 @@ static int _drm_mem_info(char *buf, char **start, off_t offset, int len,
|
|||
(long)pt->bytes_allocated
|
||||
- (long)pt->bytes_freed);
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int drm_mem_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
int DRM(mem_info)(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
ret = _drm_mem_info(buf, start, offset, len, eof, data);
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *drm_alloc(size_t size, int area)
|
||||
void *DRM(alloc)(size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!(pt = kmalloc(size, GFP_KERNEL))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[area].fail_count;
|
||||
|
|
@ -161,43 +161,43 @@ void *drm_alloc(size_t size, int area)
|
|||
return pt;
|
||||
}
|
||||
|
||||
void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
|
||||
void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!(pt = drm_alloc(size, area))) return NULL;
|
||||
|
||||
if (!(pt = DRM(alloc)(size, area))) return NULL;
|
||||
if (oldpt && oldsize) {
|
||||
memcpy(pt, oldpt, oldsize);
|
||||
drm_free(oldpt, oldsize, area);
|
||||
DRM(free)(oldpt, oldsize, area);
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
char *drm_strdup(const char *s, int area)
|
||||
char *DRM(strdup)(const char *s, int area)
|
||||
{
|
||||
char *pt;
|
||||
int length = s ? strlen(s) : 0;
|
||||
|
||||
if (!(pt = drm_alloc(length+1, area))) return NULL;
|
||||
|
||||
if (!(pt = DRM(alloc)(length+1, area))) return NULL;
|
||||
strcpy(pt, s);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void drm_strfree(const char *s, int area)
|
||||
void DRM(strfree)(const char *s, int area)
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
|
||||
if (!s) return;
|
||||
|
||||
|
||||
size = 1 + (s ? strlen(s) : 0);
|
||||
drm_free((void *)s, size, area);
|
||||
DRM(free)((void *)s, size, area);
|
||||
}
|
||||
|
||||
void drm_free(void *pt, size_t size, int area)
|
||||
void DRM(free)(void *pt, size_t size, int area)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
|
||||
if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
|
||||
else kfree(pt);
|
||||
spin_lock(&drm_mem_lock);
|
||||
|
|
@ -211,13 +211,13 @@ void drm_free(void *pt, size_t size, int area)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long drm_alloc_pages(int order, int area)
|
||||
unsigned long DRM(alloc_pages)(int order, int area)
|
||||
{
|
||||
unsigned long address;
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
unsigned long addr;
|
||||
unsigned int sz;
|
||||
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
if ((drm_ram_used >> PAGE_SHIFT)
|
||||
> (DRM_RAM_PERCENT * drm_ram_available) / 100) {
|
||||
|
|
@ -225,7 +225,7 @@ unsigned long drm_alloc_pages(int order, int area)
|
|||
return 0;
|
||||
}
|
||||
spin_unlock(&drm_mem_lock);
|
||||
|
||||
|
||||
address = __get_free_pages(GFP_KERNEL, order);
|
||||
if (!address) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
|
|
@ -238,11 +238,11 @@ unsigned long drm_alloc_pages(int order, int area)
|
|||
drm_mem_stats[area].bytes_allocated += bytes;
|
||||
drm_ram_used += bytes;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
|
||||
|
||||
|
||||
|
||||
/* Zero outside the lock */
|
||||
memset((void *)address, 0, bytes);
|
||||
|
||||
|
||||
/* Reserve */
|
||||
for (addr = address, sz = bytes;
|
||||
sz > 0;
|
||||
|
|
@ -254,18 +254,18 @@ unsigned long drm_alloc_pages(int order, int area)
|
|||
mem_map_reserve(MAP_NR(addr));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
void drm_free_pages(unsigned long address, int order, int area)
|
||||
void DRM(free_pages)(unsigned long address, int order, int area)
|
||||
{
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
unsigned long addr;
|
||||
unsigned int sz;
|
||||
|
||||
|
||||
if (!address) {
|
||||
DRM_MEM_ERROR(area, "Attempt to free address 0\n");
|
||||
} else {
|
||||
|
|
@ -282,7 +282,7 @@ void drm_free_pages(unsigned long address, int order, int area)
|
|||
}
|
||||
free_pages(address, order);
|
||||
}
|
||||
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
free_count = ++drm_mem_stats[area].free_count;
|
||||
alloc_count = drm_mem_stats[area].succeed_count;
|
||||
|
|
@ -296,16 +296,16 @@ void drm_free_pages(unsigned long address, int order, int area)
|
|||
}
|
||||
}
|
||||
|
||||
void *drm_ioremap(unsigned long offset, unsigned long size)
|
||||
void *DRM(ioremap)(unsigned long offset, unsigned long size)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Mapping 0 bytes at 0x%08lx\n", offset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!(pt = ioremap(offset, size))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_MAPPINGS].fail_count;
|
||||
|
|
@ -319,17 +319,17 @@ void *drm_ioremap(unsigned long offset, unsigned long size)
|
|||
return pt;
|
||||
}
|
||||
|
||||
void drm_ioremapfree(void *pt, unsigned long size)
|
||||
void DRM(ioremapfree)(void *pt, unsigned long size)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
|
||||
if (!pt)
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Attempt to free NULL pointer\n");
|
||||
else
|
||||
iounmap(pt);
|
||||
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
drm_mem_stats[DRM_MEM_MAPPINGS].bytes_freed += size;
|
||||
free_count = ++drm_mem_stats[DRM_MEM_MAPPINGS].free_count;
|
||||
|
|
@ -343,7 +343,8 @@ void drm_ioremapfree(void *pt, unsigned long size)
|
|||
}
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
agp_memory *drm_alloc_agp(int pages, u32 type)
|
||||
|
||||
agp_memory *DRM(alloc_agp)(int pages, u32 type)
|
||||
{
|
||||
agp_memory *handle;
|
||||
|
||||
|
|
@ -351,8 +352,8 @@ agp_memory *drm_alloc_agp(int pages, u32 type)
|
|||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((handle = drm_agp_allocate_memory(pages, type))) {
|
||||
|
||||
if ((handle = DRM(agp_allocate_memory)(pages, type))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_TOTALAGP].bytes_allocated
|
||||
|
|
@ -366,7 +367,7 @@ agp_memory *drm_alloc_agp(int pages, u32 type)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int drm_free_agp(agp_memory *handle, int pages)
|
||||
int DRM(free_agp)(agp_memory *handle, int pages)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
|
@ -377,8 +378,8 @@ int drm_free_agp(agp_memory *handle, int pages)
|
|||
"Attempt to free NULL AGP handle\n");
|
||||
return retval;;
|
||||
}
|
||||
|
||||
if (drm_agp_free_memory(handle)) {
|
||||
|
||||
if (DRM(agp_free_memory)(handle)) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
free_count = ++drm_mem_stats[DRM_MEM_TOTALAGP].free_count;
|
||||
alloc_count = drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
|
||||
|
|
@ -395,7 +396,7 @@ int drm_free_agp(agp_memory *handle, int pages)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int drm_bind_agp(agp_memory *handle, unsigned int start)
|
||||
int DRM(bind_agp)(agp_memory *handle, unsigned int start)
|
||||
{
|
||||
int retcode = -EINVAL;
|
||||
|
||||
|
|
@ -405,7 +406,7 @@ int drm_bind_agp(agp_memory *handle, unsigned int start)
|
|||
return retcode;
|
||||
}
|
||||
|
||||
if (!(retcode = drm_agp_bind_memory(handle, start))) {
|
||||
if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_allocated
|
||||
|
|
@ -419,19 +420,19 @@ int drm_bind_agp(agp_memory *handle, unsigned int start)
|
|||
return retcode;
|
||||
}
|
||||
|
||||
int drm_unbind_agp(agp_memory *handle)
|
||||
int DRM(unbind_agp)(agp_memory *handle)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
int retcode = -EINVAL;
|
||||
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to unbind NULL AGP handle\n");
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if ((retcode = drm_agp_unbind_memory(handle))) return retcode;
|
||||
if ((retcode = DRM(agp_unbind_memory)(handle))) return retcode;
|
||||
spin_lock(&drm_mem_lock);
|
||||
free_count = ++drm_mem_stats[DRM_MEM_BOUNDAGP].free_count;
|
||||
alloc_count = drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
|
|
@ -445,4 +446,5 @@ int drm_unbind_agp(agp_memory *handle)
|
|||
}
|
||||
return retcode;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE) */
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* proc.c -- /proc support for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 11 09:48:47 1999 by faith@precisioninsight.com
|
||||
/* drm_proc.h -- /proc support for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,21 +11,22 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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.
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
|
|
@ -59,7 +60,7 @@ struct drm_proc_list {
|
|||
int (*f)(char *, char **, off_t, int, int *, void *);
|
||||
} drm_proc_list[] = {
|
||||
{ "name", drm_name_info },
|
||||
{ "mem", drm_mem_info },
|
||||
{ "mem", DRM(mem_info) },
|
||||
{ "vm", drm_vm_info },
|
||||
{ "clients", drm_clients_info },
|
||||
{ "queues", drm_queues_info },
|
||||
|
|
@ -73,7 +74,7 @@ struct drm_proc_list {
|
|||
};
|
||||
#define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
|
||||
|
||||
int drm_proc_init(drm_device_t *dev)
|
||||
int DRM(proc_init)(drm_device_t *dev)
|
||||
{
|
||||
struct proc_dir_entry *ent;
|
||||
int i, j;
|
||||
|
|
@ -122,10 +123,10 @@ int drm_proc_init(drm_device_t *dev)
|
|||
}
|
||||
|
||||
|
||||
int drm_proc_cleanup(void)
|
||||
int DRM(proc_cleanup)(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
if (drm_root) {
|
||||
if (drm_dev_root) {
|
||||
for (i = 0; i < DRM_PROC_ENTRIES; i++) {
|
||||
|
|
@ -245,7 +246,7 @@ static int _drm_queues_info(char *buf, char **start, off_t offset, int len,
|
|||
atomic_read(&q->total_locks));
|
||||
atomic_dec(&q->use_count);
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
@ -389,7 +390,7 @@ static int _drm_vma_info(char *buf, char **start, off_t offset, int len,
|
|||
vma->vm_flags & VM_LOCKED ? 'l' : '-',
|
||||
vma->vm_flags & VM_IO ? 'i' : '-',
|
||||
VM_OFFSET(vma));
|
||||
|
||||
|
||||
#if defined(__i386__)
|
||||
pgprot = pgprot_val(vma->vm_page_prot);
|
||||
DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
|
||||
|
|
@ -402,7 +403,7 @@ static int _drm_vma_info(char *buf, char **start, off_t offset, int len,
|
|||
pgprot & _PAGE_DIRTY ? 'd' : '-',
|
||||
pgprot & _PAGE_PSE ? 'm' : 'k',
|
||||
pgprot & _PAGE_GLOBAL ? 'g' : 'l' );
|
||||
#endif
|
||||
#endif
|
||||
DRM_PROC_PRINT("\n");
|
||||
#if 0
|
||||
for (i = vma->vm_start; i < vma->vm_end; i += PAGE_SIZE) {
|
||||
|
|
@ -427,7 +428,7 @@ static int _drm_vma_info(char *buf, char **start, off_t offset, int len,
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
@ -467,7 +468,7 @@ static int _drm_histo_info(char *buf, char **start, off_t offset, int len,
|
|||
DRM_PROC_PRINT("ioctl %10u\n", atomic_read(&dev->total_ioctl));
|
||||
DRM_PROC_PRINT("irq %10u\n", atomic_read(&dev->total_irq));
|
||||
DRM_PROC_PRINT("ctx %10u\n", atomic_read(&dev->total_ctx));
|
||||
|
||||
|
||||
DRM_PROC_PRINT("\nlock statistics:\n");
|
||||
DRM_PROC_PRINT("locks %10u\n", atomic_read(&dev->total_locks));
|
||||
DRM_PROC_PRINT("unlocks %10u\n", atomic_read(&dev->total_unlocks));
|
||||
|
|
@ -498,7 +499,7 @@ static int _drm_histo_info(char *buf, char **start, off_t offset, int len,
|
|||
atomic_read(&dma->total_hit));
|
||||
DRM_PROC_PRINT("lost %10u\n",
|
||||
atomic_read(&dma->total_lost));
|
||||
|
||||
|
||||
buffer = dma->next_buffer;
|
||||
if (buffer) {
|
||||
DRM_PROC_PRINT("next_buffer %7d\n", buffer->idx);
|
||||
|
|
@ -512,7 +513,7 @@ static int _drm_histo_info(char *buf, char **start, off_t offset, int len,
|
|||
DRM_PROC_PRINT("this_buffer none\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
DRM_PROC_PRINT("\nvalues:\n");
|
||||
if (dev->lock.hw_lock) {
|
||||
|
|
@ -529,8 +530,8 @@ static int _drm_histo_info(char *buf, char **start, off_t offset, int len,
|
|||
DRM_PROC_PRINT("last_context %10d\n", dev->last_context);
|
||||
DRM_PROC_PRINT("last_switch %10lu\n", dev->last_switch);
|
||||
DRM_PROC_PRINT("last_checked %10d\n", dev->last_checked);
|
||||
|
||||
|
||||
|
||||
|
||||
DRM_PROC_PRINT("\n q2d d2c c2f"
|
||||
" q2c q2f dma sch"
|
||||
" ctx lacq lhld\n\n");
|
||||
|
|
@ -540,14 +541,14 @@ static int _drm_histo_info(char *buf, char **start, off_t offset, int len,
|
|||
i == DRM_DMA_HISTOGRAM_SLOTS - 1 ? ">=" : "< ",
|
||||
i == DRM_DMA_HISTOGRAM_SLOTS - 1
|
||||
? prev_value : slot_value ,
|
||||
|
||||
|
||||
atomic_read(&dev->histo
|
||||
.queued_to_dispatched[i]),
|
||||
atomic_read(&dev->histo
|
||||
.dispatched_to_completed[i]),
|
||||
atomic_read(&dev->histo
|
||||
.completed_to_freed[i]),
|
||||
|
||||
|
||||
atomic_read(&dev->histo
|
||||
.queued_to_completed[i]),
|
||||
atomic_read(&dev->histo
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* vm.c -- Memory mapping for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@precisioninsight.com
|
||||
/* drm_vm.h -- Memory mapping for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,74 +11,74 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
struct vm_operations_struct drm_vm_ops = {
|
||||
nopage: drm_vm_nopage,
|
||||
open: drm_vm_open,
|
||||
close: drm_vm_close,
|
||||
nopage: DRM(vm_nopage),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
struct vm_operations_struct drm_vm_shm_ops = {
|
||||
nopage: drm_vm_shm_nopage,
|
||||
open: drm_vm_open,
|
||||
close: drm_vm_close,
|
||||
nopage: DRM(vm_shm_nopage),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
struct vm_operations_struct drm_vm_shm_lock_ops = {
|
||||
nopage: drm_vm_shm_nopage_lock,
|
||||
open: drm_vm_open,
|
||||
close: drm_vm_close,
|
||||
nopage: DRM(vm_shm_nopage_lock),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
struct vm_operations_struct drm_vm_dma_ops = {
|
||||
nopage: drm_vm_dma_nopage,
|
||||
open: drm_vm_open,
|
||||
close: drm_vm_close,
|
||||
nopage: DRM(vm_dma_nopage),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long drm_vm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
unsigned long DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *drm_vm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
return NOPAGE_SIGBUS; /* Disallow mremap */
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long drm_vm_shm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
unsigned long DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
#if LINUX_VERSION_CODE >= 0x020300
|
||||
|
|
@ -105,14 +105,14 @@ struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
|
|||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
unsigned long DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
struct page *DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
|
|
@ -138,14 +138,14 @@ struct page *drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
|||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long drm_vm_dma_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
unsigned long DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
|
|
@ -172,7 +172,7 @@ struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
|
|||
#endif
|
||||
}
|
||||
|
||||
void drm_vm_open(struct vm_area_struct *vma)
|
||||
void DRM(vm_open)(struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -190,7 +190,7 @@ void drm_vm_open(struct vm_area_struct *vma)
|
|||
|
||||
|
||||
#if DRM_DEBUG_CODE
|
||||
vma_entry = drm_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
|
||||
vma_entry = DRM(alloc)(sizeof(*vma_entry), DRM_MEM_VMAS);
|
||||
if (vma_entry) {
|
||||
down(&dev->struct_sem);
|
||||
vma_entry->vma = vma;
|
||||
|
|
@ -202,7 +202,7 @@ void drm_vm_open(struct vm_area_struct *vma)
|
|||
#endif
|
||||
}
|
||||
|
||||
void drm_vm_close(struct vm_area_struct *vma)
|
||||
void DRM(vm_close)(struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
|
@ -226,7 +226,7 @@ void drm_vm_close(struct vm_area_struct *vma)
|
|||
} else {
|
||||
dev->vmalist = pt->next;
|
||||
}
|
||||
drm_free(pt, sizeof(*pt), DRM_MEM_VMAS);
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_VMAS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -234,13 +234,13 @@ void drm_vm_close(struct vm_area_struct *vma)
|
|||
#endif
|
||||
}
|
||||
|
||||
int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
|
||||
int DRM(mmap_dma)(struct file *filp, struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev;
|
||||
drm_device_dma_t *dma;
|
||||
unsigned long length = vma->vm_end - vma->vm_start;
|
||||
|
||||
|
||||
lock_kernel();
|
||||
dev = priv->dev;
|
||||
dma = dev->dma;
|
||||
|
|
@ -256,28 +256,28 @@ int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
|
|||
|
||||
vma->vm_ops = &drm_vm_dma_ops;
|
||||
vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
|
||||
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020203 /* KERNEL_VERSION(2,2,3) */
|
||||
/* In Linux 2.2.3 and above, this is
|
||||
handled in do_mmap() in mm/mmap.c. */
|
||||
++filp->f_count;
|
||||
#endif
|
||||
vma->vm_file = filp; /* Needed for drm_vm_open() */
|
||||
drm_vm_open(vma);
|
||||
DRM(vm_open)(vma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_mmap(struct file *filp, struct vm_area_struct *vma)
|
||||
int DRM(mmap)(struct file *filp, struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_map_t *map = NULL;
|
||||
int i;
|
||||
|
||||
|
||||
DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
|
||||
vma->vm_start, vma->vm_end, VM_OFFSET(vma));
|
||||
|
||||
if (!VM_OFFSET(vma)) return drm_mmap_dma(filp, vma);
|
||||
if (!VM_OFFSET(vma)) return DRM(mmap_dma)(filp, vma);
|
||||
|
||||
/* A sequential search of a linked list is
|
||||
fine here because: 1) there will only be
|
||||
|
|
@ -290,14 +290,14 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
|
|||
map = dev->maplist[i];
|
||||
if (map->offset == VM_OFFSET(vma)) break;
|
||||
}
|
||||
|
||||
|
||||
if (i >= dev->map_count) return -EINVAL;
|
||||
if (!map || ((map->flags&_DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
|
||||
return -EPERM;
|
||||
|
||||
/* Check for valid size. */
|
||||
if (map->size != vma->vm_end - vma->vm_start) return -EINVAL;
|
||||
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
|
||||
vma->vm_flags &= VM_MAYWRITE;
|
||||
#if defined(__i386__)
|
||||
|
|
@ -365,6 +365,6 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma)
|
|||
++filp->f_count;
|
||||
#endif
|
||||
vma->vm_file = filp; /* Needed for drm_vm_open() */
|
||||
drm_vm_open(vma);
|
||||
DRM(vm_open)(vma);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/* mga_drv.c -- Matrox g200/g400 driver -*- linux-c -*-
|
||||
/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
|
|
@ -19,648 +19,130 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include "mga.h"
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
|
||||
#define MGA_NAME "mga"
|
||||
#define MGA_DESC "Matrox G200/G400"
|
||||
#define MGA_DATE "20000928"
|
||||
#define MGA_MAJOR 2
|
||||
#define MGA_MINOR 1
|
||||
#define MGA_PATCHLEVEL 1
|
||||
#define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc."
|
||||
|
||||
static drm_device_t mga_device;
|
||||
drm_ctx_t mga_res_ctx;
|
||||
#define DRIVER_NAME "mga"
|
||||
#define DRIVER_DESC "Matrox G200/G400"
|
||||
#define DRIVER_DATE "20010110"
|
||||
|
||||
static struct file_operations mga_fops = {
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
/* This started being used during 2.4.0-test */
|
||||
owner: THIS_MODULE,
|
||||
#endif
|
||||
open: mga_open,
|
||||
flush: drm_flush,
|
||||
release: mga_release,
|
||||
ioctl: mga_ioctl,
|
||||
mmap: drm_mmap,
|
||||
read: drm_read,
|
||||
fasync: drm_fasync,
|
||||
poll: drm_poll,
|
||||
};
|
||||
#define DRIVER_MAJOR 3
|
||||
#define DRIVER_MINOR 0
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
static struct miscdevice mga_misc = {
|
||||
minor: MISC_DYNAMIC_MINOR,
|
||||
name: MGA_NAME,
|
||||
fops: &mga_fops,
|
||||
};
|
||||
|
||||
static drm_ioctl_desc_t mga_ioctls[] = {
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { mga_version, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { drm_irq_busid, 0, 1 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { drm_setunique, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { drm_block, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { drm_unblock, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { mga_control, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { drm_authmagic, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { drm_addmap, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { mga_addbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { mga_markbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { mga_infobufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { mga_mapbufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { mga_freebufs, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { mga_addctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { mga_rmctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { mga_modctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { mga_getctx, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { mga_switchctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { mga_newctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { mga_resctx, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { drm_adddraw, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { drm_rmdraw, 1, 1 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { mga_dma, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { mga_lock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { mga_unlock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { drm_finish, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { drm_agp_acquire, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { drm_agp_release, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = { drm_agp_enable, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = { drm_agp_info, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = { drm_agp_alloc, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = { drm_agp_free, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = { drm_agp_bind, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = { drm_agp_unbind, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INIT)] = { mga_dma_init, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_SWAP)] = { mga_swap_bufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_CLEAR)] = { mga_clear_bufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_ILOAD)] = { mga_iload, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_VERTEX)] = { mga_vertex, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_FLUSH)] = { mga_flush_ioctl, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INDICES)] = { mga_indices, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_BLIT)] = { mga_blit, 1, 0 },
|
||||
};
|
||||
|
||||
#define MGA_IOCTL_COUNT DRM_ARRAY_SIZE(mga_ioctls)
|
||||
|
||||
#ifdef MODULE
|
||||
static char *mga = NULL;
|
||||
#endif
|
||||
|
||||
MODULE_AUTHOR("VA Linux Systems, Inc.");
|
||||
MODULE_DESCRIPTION("Matrox G200/G400");
|
||||
MODULE_PARM(mga, "s");
|
||||
|
||||
#ifndef MODULE
|
||||
/* mga_options is called by the kernel to parse command-line options passed
|
||||
* via the boot-loader (e.g., LILO). It calls the insmod option routine,
|
||||
* drm_parse_drm.
|
||||
/* Now that we do this, we can move the DRM(ioctls) array into a
|
||||
* template file and have a DRIVER_IOCTLS block at the end.
|
||||
*/
|
||||
static drm_ioctl_desc_t mga_ioctls[] = {
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { mga_version, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { mga_getunique, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { mga_getmagic, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { mga_irq_busid, 0, 1 },
|
||||
|
||||
static int __init mga_options(char *str)
|
||||
{
|
||||
drm_parse_options(str);
|
||||
return 1;
|
||||
}
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { mga_setunique, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { mga_block, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { mga_unblock, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { mga_control, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { mga_authmagic, 1, 1 },
|
||||
|
||||
__setup("mga=", mga_options);
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { mga_addmap, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { mga_addbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { mga_markbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { mga_infobufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { mga_mapbufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { mga_freebufs, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { mga_addctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { mga_rmctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { mga_modctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { mga_getctx, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { mga_switchctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { mga_newctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { mga_resctx, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { mga_adddraw, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { mga_rmdraw, 1, 1 },
|
||||
#if 0
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { mga_dma, 1, 0 },
|
||||
#endif
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { mga_lock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { mga_unlock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { mga_finish, 1, 0 },
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { mga_agp_acquire, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { mga_agp_release, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = { mga_agp_enable, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = { mga_agp_info, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = { mga_agp_alloc, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = { mga_agp_free, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = { mga_agp_bind, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = { mga_agp_unbind, 1, 1 },
|
||||
#endif
|
||||
|
||||
static int mga_setup(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
atomic_set(&dev->ioctl_count, 0);
|
||||
atomic_set(&dev->vma_count, 0);
|
||||
dev->buf_use = 0;
|
||||
atomic_set(&dev->buf_alloc, 0);
|
||||
|
||||
drm_dma_setup(dev);
|
||||
|
||||
atomic_set(&dev->total_open, 0);
|
||||
atomic_set(&dev->total_close, 0);
|
||||
atomic_set(&dev->total_ioctl, 0);
|
||||
atomic_set(&dev->total_irq, 0);
|
||||
atomic_set(&dev->total_ctx, 0);
|
||||
atomic_set(&dev->total_locks, 0);
|
||||
atomic_set(&dev->total_unlocks, 0);
|
||||
atomic_set(&dev->total_contends, 0);
|
||||
atomic_set(&dev->total_sleeps, 0);
|
||||
|
||||
for (i = 0; i < DRM_HASH_SIZE; i++) {
|
||||
dev->magiclist[i].head = NULL;
|
||||
dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
dev->vmalist = NULL;
|
||||
dev->lock.hw_lock = NULL;
|
||||
init_waitqueue_head(&dev->lock.lock_queue);
|
||||
dev->queue_count = 0;
|
||||
dev->queue_reserved = 0;
|
||||
dev->queue_slots = 0;
|
||||
dev->queuelist = NULL;
|
||||
dev->irq = 0;
|
||||
dev->context_flag = 0;
|
||||
dev->interrupt_flag = 0;
|
||||
dev->dma_flag = 0;
|
||||
dev->last_context = 0;
|
||||
dev->last_switch = 0;
|
||||
dev->last_checked = 0;
|
||||
init_timer(&dev->timer);
|
||||
init_waitqueue_head(&dev->context_wait);
|
||||
|
||||
dev->ctx_start = 0;
|
||||
dev->lck_start = 0;
|
||||
|
||||
dev->buf_rp = dev->buf;
|
||||
dev->buf_wp = dev->buf;
|
||||
dev->buf_end = dev->buf + DRM_BSZ;
|
||||
dev->buf_async = NULL;
|
||||
init_waitqueue_head(&dev->buf_readers);
|
||||
init_waitqueue_head(&dev->buf_writers);
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
/* The kernel's context could be created here, but is now created
|
||||
in drm_dma_enqueue. This is more resource-efficient for
|
||||
hardware that does not do DMA, but may mean that
|
||||
drm_select_queue fails between the time the interrupt is
|
||||
initialized and the time the queues are initialized. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int mga_takedown(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
drm_magic_entry_t *pt, *next;
|
||||
drm_map_t *map;
|
||||
drm_vma_entry_t *vma, *vma_next;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (dev->dev_private) mga_dma_cleanup(dev);
|
||||
if (dev->irq) mga_irq_uninstall(dev);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
del_timer(&dev->timer);
|
||||
|
||||
if (dev->devname) {
|
||||
drm_free(dev->devname, strlen(dev->devname)+1, DRM_MEM_DRIVER);
|
||||
dev->devname = NULL;
|
||||
}
|
||||
|
||||
if (dev->unique) {
|
||||
drm_free(dev->unique, strlen(dev->unique)+1, DRM_MEM_DRIVER);
|
||||
dev->unique = NULL;
|
||||
dev->unique_len = 0;
|
||||
}
|
||||
/* Clear pid list */
|
||||
for (i = 0; i < DRM_HASH_SIZE; i++) {
|
||||
for (pt = dev->magiclist[i].head; pt; pt = next) {
|
||||
next = pt->next;
|
||||
drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
}
|
||||
dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
/* Clear AGP information */
|
||||
if (dev->agp) {
|
||||
drm_agp_mem_t *entry;
|
||||
drm_agp_mem_t *nexte;
|
||||
|
||||
/* Remove AGP resources, but leave dev->agp
|
||||
intact until cleanup is called. */
|
||||
for (entry = dev->agp->memory; entry; entry = nexte) {
|
||||
nexte = entry->next;
|
||||
if (entry->bound) drm_unbind_agp(entry->memory);
|
||||
drm_free_agp(entry->memory, entry->pages);
|
||||
drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
}
|
||||
dev->agp->memory = NULL;
|
||||
|
||||
if (dev->agp->acquired) _drm_agp_release();
|
||||
|
||||
dev->agp->acquired = 0;
|
||||
dev->agp->enabled = 0;
|
||||
}
|
||||
/* Clear vma list (only built for debugging) */
|
||||
if (dev->vmalist) {
|
||||
for (vma = dev->vmalist; vma; vma = vma_next) {
|
||||
vma_next = vma->next;
|
||||
drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
|
||||
}
|
||||
dev->vmalist = NULL;
|
||||
}
|
||||
|
||||
/* Clear map area and mtrr information */
|
||||
if (dev->maplist) {
|
||||
for (i = 0; i < dev->map_count; i++) {
|
||||
map = dev->maplist[i];
|
||||
switch (map->type) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#ifdef CONFIG_MTRR
|
||||
if (map->mtrr >= 0) {
|
||||
int retcode;
|
||||
retcode = mtrr_del(map->mtrr,
|
||||
map->offset,
|
||||
map->size);
|
||||
DRM_DEBUG("mtrr_del = %d\n", retcode);
|
||||
}
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INIT)] = { mga_dma_init, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_FLUSH)] = { mga_dma_flush, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_RESET)] = { mga_dma_reset, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_SWAP)] = { mga_dma_swap, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_CLEAR)] = { mga_dma_clear, 1, 0 },
|
||||
#if 0
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_ILOAD)] = { mga_iload, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_VERTEX)] = { mga_vertex, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INDICES)] = { mga_indices, 1, 0 },
|
||||
#endif
|
||||
drm_ioremapfree(map->handle, map->size);
|
||||
break;
|
||||
case _DRM_SHM:
|
||||
drm_free_pages((unsigned long)map->handle,
|
||||
drm_order(map->size)
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA);
|
||||
break;
|
||||
case _DRM_AGP:
|
||||
break;
|
||||
}
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
}
|
||||
drm_free(dev->maplist,
|
||||
dev->map_count * sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS);
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
}
|
||||
};
|
||||
|
||||
if (dev->queuelist) {
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
drm_waitlist_destroy(&dev->queuelist[i]->waitlist);
|
||||
if (dev->queuelist[i]) {
|
||||
drm_free(dev->queuelist[i],
|
||||
sizeof(*dev->queuelist[0]),
|
||||
DRM_MEM_QUEUES);
|
||||
dev->queuelist[i] = NULL;
|
||||
}
|
||||
}
|
||||
drm_free(dev->queuelist,
|
||||
dev->queue_slots * sizeof(*dev->queuelist),
|
||||
DRM_MEM_QUEUES);
|
||||
dev->queuelist = NULL;
|
||||
}
|
||||
#define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( mga_ioctls )
|
||||
|
||||
drm_dma_takedown(dev);
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
|
||||
dev->queue_count = 0;
|
||||
if (dev->lock.hw_lock) {
|
||||
dev->lock.hw_lock = NULL; /* SHM removed */
|
||||
dev->lock.pid = 0;
|
||||
wake_up_interruptible(&dev->lock.lock_queue);
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
#define __HAVE_MTRR 1
|
||||
|
||||
return 0;
|
||||
}
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* mga_init is called via init_module at module load time, or via
|
||||
* linux/init/main.c (this is not currently supported). */
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
|
||||
static int __init mga_init(void)
|
||||
{
|
||||
int retcode;
|
||||
drm_device_t *dev = &mga_device;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
memset((void *)dev, 0, sizeof(*dev));
|
||||
dev->count_lock = SPIN_LOCK_UNLOCKED;
|
||||
sema_init(&dev->struct_sem, 1);
|
||||
|
||||
#ifdef MODULE
|
||||
drm_parse_options(mga);
|
||||
#endif
|
||||
if ((retcode = misc_register(&mga_misc))) {
|
||||
DRM_ERROR("Cannot register \"%s\"\n", MGA_NAME);
|
||||
return retcode;
|
||||
}
|
||||
dev->device = MKDEV(MISC_MAJOR, mga_misc.minor);
|
||||
dev->name = MGA_NAME;
|
||||
|
||||
drm_mem_init();
|
||||
drm_proc_init(dev);
|
||||
dev->agp = drm_agp_init();
|
||||
if(dev->agp == NULL) {
|
||||
DRM_INFO("The mga drm module requires the agpgart module"
|
||||
" to function correctly\nPlease load the agpgart"
|
||||
" module before you load the mga module\n");
|
||||
drm_proc_cleanup();
|
||||
misc_deregister(&mga_misc);
|
||||
mga_takedown(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
#ifdef CONFIG_MTRR
|
||||
dev->agp->agp_mtrr = mtrr_add(dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size * 1024 * 1024,
|
||||
MTRR_TYPE_WRCOMB,
|
||||
1);
|
||||
#endif
|
||||
if((retcode = drm_ctxbitmap_init(dev))) {
|
||||
DRM_ERROR("Cannot allocate memory for context bitmap.\n");
|
||||
drm_proc_cleanup();
|
||||
misc_deregister(&mga_misc);
|
||||
mga_takedown(dev);
|
||||
return retcode;
|
||||
}
|
||||
|
||||
DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
|
||||
MGA_NAME,
|
||||
MGA_MAJOR,
|
||||
MGA_MINOR,
|
||||
MGA_PATCHLEVEL,
|
||||
MGA_DATE,
|
||||
mga_misc.minor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mga_cleanup is called via cleanup_module at module unload time. */
|
||||
|
||||
static void __exit mga_cleanup(void)
|
||||
{
|
||||
drm_device_t *dev = &mga_device;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
drm_proc_cleanup();
|
||||
if (misc_deregister(&mga_misc)) {
|
||||
DRM_ERROR("Cannot unload module\n");
|
||||
} else {
|
||||
DRM_INFO("Module unloaded\n");
|
||||
}
|
||||
drm_ctxbitmap_cleanup(dev);
|
||||
#ifdef CONFIG_MTRR
|
||||
if(dev->agp && dev->agp->agp_mtrr) {
|
||||
int retval;
|
||||
retval = mtrr_del(dev->agp->agp_mtrr,
|
||||
dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size * 1024*1024);
|
||||
DRM_DEBUG("mtrr_del = %d\n", retval);
|
||||
}
|
||||
#if 0
|
||||
#define __HAVE_DMA_QUEUE 1
|
||||
#define __HAVE_DMA_SCHEDULE 1
|
||||
#endif
|
||||
|
||||
mga_takedown(dev);
|
||||
if (dev->agp) {
|
||||
drm_agp_uninit();
|
||||
drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
|
||||
dev->agp = NULL;
|
||||
}
|
||||
}
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() \
|
||||
do { \
|
||||
drm_mga_private_t *dev_priv = dev->dev_private; \
|
||||
return mga_do_wait_for_idle( dev_priv ); \
|
||||
} while (0)
|
||||
|
||||
module_init(mga_init);
|
||||
module_exit(mga_cleanup);
|
||||
|
||||
|
||||
int mga_version(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_version_t version;
|
||||
int len;
|
||||
|
||||
if (copy_from_user(&version,
|
||||
(drm_version_t *)arg,
|
||||
sizeof(version)))
|
||||
return -EFAULT;
|
||||
|
||||
#define DRM_COPY(name,value) \
|
||||
len = strlen(value); \
|
||||
if (len > name##_len) len = name##_len; \
|
||||
name##_len = strlen(value); \
|
||||
if (len && name) { \
|
||||
if (copy_to_user(name, value, len)) \
|
||||
return -EFAULT; \
|
||||
}
|
||||
|
||||
version.version_major = MGA_MAJOR;
|
||||
version.version_minor = MGA_MINOR;
|
||||
version.version_patchlevel = MGA_PATCHLEVEL;
|
||||
|
||||
DRM_COPY(version.name, MGA_NAME);
|
||||
DRM_COPY(version.date, MGA_DATE);
|
||||
DRM_COPY(version.desc, MGA_DESC);
|
||||
|
||||
if (copy_to_user((drm_version_t *)arg,
|
||||
&version,
|
||||
sizeof(version)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
drm_device_t *dev = &mga_device;
|
||||
int retcode = 0;
|
||||
|
||||
DRM_DEBUG("open_count = %d\n", dev->open_count);
|
||||
if (!(retcode = drm_open_helper(inode, filp, dev))) {
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#if 0
|
||||
#define __HAVE_DRIVER_RELEASE 1
|
||||
#define DRIVER_RELEASE() do { \
|
||||
mga_reclaim_buffers( dev, priv->pid ); \
|
||||
if ( dev->dev_private ) { \
|
||||
drm_mga_private_t *dev_priv = dev->dev_private; \
|
||||
dev_priv->dispatch_status &= MGA_IN_DISPATCH; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
atomic_inc(&dev->total_open);
|
||||
spin_lock(&dev->count_lock);
|
||||
if (!dev->open_count++) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return mga_setup(dev);
|
||||
}
|
||||
spin_unlock(&dev->count_lock);
|
||||
}
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int mga_release(struct inode *inode, struct file *filp)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev;
|
||||
int retcode = 0;
|
||||
#define DRIVER_PRETAKEDOWN() do { \
|
||||
if ( dev->dev_private ) mga_do_cleanup_dma( dev ); \
|
||||
} while (0)
|
||||
|
||||
lock_kernel();
|
||||
dev = priv->dev;
|
||||
DRM_DEBUG("pid = %d, device = 0x%x, open_count = %d\n",
|
||||
current->pid, dev->device, dev->open_count);
|
||||
|
||||
if (dev->lock.hw_lock && _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)
|
||||
&& dev->lock.pid == current->pid) {
|
||||
mga_reclaim_buffers(dev, priv->pid);
|
||||
DRM_INFO("Process %d dead (ctx %d, d_s = 0x%02lx)\n",
|
||||
current->pid,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock),
|
||||
dev->dev_private ?
|
||||
((drm_mga_private_t *)dev->dev_private)
|
||||
->dispatch_status
|
||||
: 0);
|
||||
|
||||
if (dev->dev_private)
|
||||
((drm_mga_private_t *)dev->dev_private)
|
||||
->dispatch_status &= MGA_IN_DISPATCH;
|
||||
|
||||
drm_lock_free(dev,
|
||||
&dev->lock.hw_lock->lock,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
|
||||
} else if (dev->lock.hw_lock) {
|
||||
/* The lock is required to reclaim buffers */
|
||||
DECLARE_WAITQUEUE(entry, current);
|
||||
add_wait_queue(&dev->lock.lock_queue, &entry);
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if (!dev->lock.hw_lock) {
|
||||
/* Device has been unregistered */
|
||||
retcode = -EINTR;
|
||||
break;
|
||||
}
|
||||
if (drm_lock_take(&dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) {
|
||||
dev->lock.pid = priv->pid;
|
||||
dev->lock.lock_time = jiffies;
|
||||
atomic_inc(&dev->total_locks);
|
||||
break; /* Got lock */
|
||||
}
|
||||
/* Contention */
|
||||
atomic_inc(&dev->total_sleeps);
|
||||
schedule();
|
||||
if (signal_pending(current)) {
|
||||
retcode = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue(&dev->lock.lock_queue, &entry);
|
||||
if(!retcode) {
|
||||
mga_reclaim_buffers(dev, priv->pid);
|
||||
if (dev->dev_private)
|
||||
((drm_mga_private_t *)dev->dev_private)
|
||||
->dispatch_status &= MGA_IN_DISPATCH;
|
||||
drm_lock_free(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT);
|
||||
}
|
||||
}
|
||||
drm_fasync(-1, filp, 0);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
if (priv->remove_auth_on_close == 1) {
|
||||
drm_file_t *temp = dev->file_first;
|
||||
while(temp) {
|
||||
temp->authenticated = 0;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
if (priv->prev) priv->prev->next = priv->next;
|
||||
else dev->file_first = priv->next;
|
||||
if (priv->next) priv->next->prev = priv->prev;
|
||||
else dev->file_last = priv->prev;
|
||||
up(&dev->struct_sem);
|
||||
|
||||
drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_DEC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_inc(&dev->total_close);
|
||||
spin_lock(&dev->count_lock);
|
||||
if (!--dev->open_count) {
|
||||
if (atomic_read(&dev->ioctl_count) || dev->blocked) {
|
||||
DRM_ERROR("Device busy: %d %d\n",
|
||||
atomic_read(&dev->ioctl_count),
|
||||
dev->blocked);
|
||||
spin_unlock(&dev->count_lock);
|
||||
unlock_kernel();
|
||||
return -EBUSY;
|
||||
}
|
||||
spin_unlock(&dev->count_lock);
|
||||
unlock_kernel();
|
||||
return mga_takedown(dev);
|
||||
}
|
||||
spin_unlock(&dev->count_lock);
|
||||
unlock_kernel();
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
||||
/* drm_ioctl is called whenever a process performs an ioctl on /dev/drm. */
|
||||
|
||||
int mga_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
int nr = DRM_IOCTL_NR(cmd);
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int retcode = 0;
|
||||
drm_ioctl_desc_t *ioctl;
|
||||
drm_ioctl_t *func;
|
||||
|
||||
atomic_inc(&dev->ioctl_count);
|
||||
atomic_inc(&dev->total_ioctl);
|
||||
++priv->ioctl_count;
|
||||
|
||||
if (nr >= MGA_IOCTL_COUNT) {
|
||||
retcode = -EINVAL;
|
||||
} else {
|
||||
ioctl = &mga_ioctls[nr];
|
||||
func = ioctl->func;
|
||||
|
||||
if (!func) {
|
||||
DRM_DEBUG("no function: pid = %d, cmd = 0x%02x,"
|
||||
" nr = 0x%02x, dev 0x%x, auth = %d\n",
|
||||
current->pid, cmd, nr, dev->device,
|
||||
priv->authenticated);
|
||||
retcode = -EINVAL;
|
||||
} else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN))
|
||||
|| (ioctl->auth_needed && !priv->authenticated)) {
|
||||
retcode = -EACCES;
|
||||
} else {
|
||||
retcode = (func)(inode, filp, cmd, arg);
|
||||
}
|
||||
}
|
||||
|
||||
atomic_dec(&dev->ioctl_count);
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int mga_unlock(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_lock_t lock;
|
||||
|
||||
if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
|
||||
return -EFAULT;
|
||||
|
||||
if (lock.context == DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("Process %d using kernel context %d\n",
|
||||
current->pid, lock.context);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
atomic_inc(&dev->total_unlocks);
|
||||
if (_DRM_LOCK_IS_CONT(dev->lock.hw_lock->lock))
|
||||
atomic_inc(&dev->total_contends);
|
||||
drm_lock_transfer(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
|
||||
mga_dma_schedule(dev, 1);
|
||||
|
||||
if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) DRM_ERROR("\n");
|
||||
|
||||
unblock_all_signals();
|
||||
return 0;
|
||||
}
|
||||
#include "drm_drv.h"
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#define R128_NAME "r128"
|
||||
#define R128_DESC "ATI Rage 128"
|
||||
#define R128_DATE "20010125"
|
||||
#define R128_DATE "20010101"
|
||||
#define R128_MAJOR 2
|
||||
#define R128_MINOR 1
|
||||
#define R128_PATCHLEVEL 4
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ r128-objs := r128_drv.o r128_cce.o r128_context.o r128_bufs.o \
|
|||
radeon-objs := radeon_drv.o radeon_cp.o radeon_context.o radeon_bufs.o \
|
||||
radeon_state.o
|
||||
ffb-objs := ffb_drv.o ffb_context.o
|
||||
mga-objs := mga_drv.o mga_dma.o mga_context.o mga_bufs.o \
|
||||
mga_state.o
|
||||
mga-objs := mga_drv.o mga_drm.o mga_dma.o mga_state.o mga_warp.o
|
||||
i810-objs := i810_drv.o i810_dma.o i810_context.o i810_bufs.o
|
||||
|
||||
obj-$(CONFIG_DRM_GAMMA) += gamma.o
|
||||
|
|
@ -62,7 +61,7 @@ obj-$(CONFIG_DRM_MGA) += mga.o
|
|||
obj-$(CONFIG_DRM_I810) += i810.o
|
||||
|
||||
|
||||
# When linking into the kernel, link the library just once.
|
||||
# When linking into the kernel, link the library just once.
|
||||
# If making modules, we include the library into each module
|
||||
|
||||
lib-objs-mod := $(patsubst %.o,%-mod.o,$(lib-objs))
|
||||
|
|
@ -75,7 +74,7 @@ endif
|
|||
|
||||
include $(TOPDIR)/Rules.make
|
||||
|
||||
$(patsubst %.o,%.c,$(lib-objs-mod)):
|
||||
$(patsubst %.o,%.c,$(lib-objs-mod)):
|
||||
@ln -sf $(subst -mod,,$@) $@
|
||||
|
||||
drmlib-mod.a: $(lib-objs-mod)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
# 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.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ***** NOTE NOTE NOTE NOTE NOTE *****
|
||||
# To override the automatic Linux source tree determination, pass the
|
||||
|
|
@ -47,11 +47,15 @@
|
|||
|
||||
# **** End of SMP/MODVERSIONS detection
|
||||
|
||||
MODS= gamma.o tdfx.o
|
||||
MODS= gamma.o tdfx.o r128.o radeon.o
|
||||
LIBS= libdrm.a
|
||||
|
||||
DRMOBJS= init.o memory.o proc.o auth.o context.o drawable.o bufs.o \
|
||||
lists.o lock.o ioctl.o fops.o vm.o dma.o ctxbitmap.o
|
||||
#DRMHEADERS= drm.h drmP.h compat-pre24.h
|
||||
DRMTEMPLATES= drm_init.h drm_memory.h drm_proc.h drm_auth.h drm_context.h \
|
||||
drm_drawable.h drm_bufs.h drm_lists.h drm_lock.h drm_ioctl.h \
|
||||
drm_fops.h drm_vm.h drm_dma.h
|
||||
DRMHEADERS= drm.h drmP.h compat-pre24.h
|
||||
|
||||
GAMMAOBJS= gamma_drv.o gamma_dma.o
|
||||
|
|
@ -129,17 +133,14 @@ endif
|
|||
ifeq ($(AGP),1)
|
||||
MODCFLAGS += -DCONFIG_AGP -DCONFIG_AGP_MODULE
|
||||
DRMOBJS += agpsupport.o
|
||||
MODS += mga.o r128.o radeon.o
|
||||
MODS += mga.o
|
||||
ifeq ($(MACHINE),i386)
|
||||
MODS += i810.o
|
||||
endif
|
||||
ifeq ($(MACHINE),i686)
|
||||
MODS += i810.o
|
||||
endif
|
||||
|
||||
|
||||
MGAOBJS= mga_drv.o mga_dma.o mga_bufs.o mga_context.o mga_state.o
|
||||
MGAHEADERS= mga_drv.h $(DRMHEADERS)
|
||||
MGAOBJS= mga_drv.o mga_drm.o mga_dma.o mga_state.o mga_warp.o
|
||||
MGAHEADERS= mga_drv.h $(DRMHEADERS) $(DRMTEMPLATES)
|
||||
|
||||
I810OBJS= i810_drv.o i810_dma.o i810_bufs.o i810_context.o
|
||||
I810HEADERS= i810_drv.h $(DRMHEADERS)
|
||||
|
|
@ -219,7 +220,7 @@ sis.o: $(SISOBJS) $(LIBS)
|
|||
ifeq ($(AGP),1)
|
||||
mga_drv.o: mga_drv.c
|
||||
$(CC) $(MODCFLAGS) -DEXPORT_SYMTAB -I$(TREE) -c $< -o $@
|
||||
mga.o: $(MGAOBJS) $(LIBS)
|
||||
mga.o: $(MGAOBJS)
|
||||
$(LD) -r $^ -o $@
|
||||
|
||||
i810_drv.o: i810_drv.c
|
||||
|
|
|
|||
537
linux/bufs.c
537
linux/bufs.c
|
|
@ -1,537 +0,0 @@
|
|||
/* bufs.c -- IOCTLs to manage buffers -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@precisioninsight.com
|
||||
*
|
||||
* Copyright 1999, 2000 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include <linux/config.h>
|
||||
#include "drmP.h"
|
||||
#include "linux/un.h"
|
||||
|
||||
/* Compute order. Can be made faster. */
|
||||
int drm_order(unsigned long size)
|
||||
{
|
||||
int order;
|
||||
unsigned long tmp;
|
||||
|
||||
for (order = 0, tmp = size; tmp >>= 1; ++order);
|
||||
if (size & ~(1 << order)) ++order;
|
||||
return order;
|
||||
}
|
||||
|
||||
int drm_addmap(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_map_t *map;
|
||||
|
||||
if (!(filp->f_mode & 3)) return -EACCES; /* Require read/write */
|
||||
|
||||
map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
|
||||
if (!map) return -ENOMEM;
|
||||
if (copy_from_user(map, (drm_map_t *)arg, sizeof(*map))) {
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n",
|
||||
map->offset, map->size, map->type);
|
||||
if ((map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK))) {
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
return -EINVAL;
|
||||
}
|
||||
map->mtrr = -1;
|
||||
map->handle = 0;
|
||||
|
||||
switch (map->type) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#ifndef __sparc__
|
||||
if (map->offset + map->size < map->offset
|
||||
|| map->offset < virt_to_phys(high_memory)) {
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_MTRR
|
||||
if (map->type == _DRM_FRAME_BUFFER
|
||||
|| (map->flags & _DRM_WRITE_COMBINING)) {
|
||||
map->mtrr = mtrr_add(map->offset, map->size,
|
||||
MTRR_TYPE_WRCOMB, 1);
|
||||
}
|
||||
#endif
|
||||
map->handle = drm_ioremap(map->offset, map->size);
|
||||
break;
|
||||
|
||||
|
||||
case _DRM_SHM:
|
||||
map->handle = (void *)drm_alloc_pages(drm_order(map->size)
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA);
|
||||
DRM_DEBUG("%ld %d %p\n", map->size, drm_order(map->size),
|
||||
map->handle);
|
||||
if (!map->handle) {
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
return -ENOMEM;
|
||||
}
|
||||
map->offset = (unsigned long)map->handle;
|
||||
if (map->flags & _DRM_CONTAINS_LOCK) {
|
||||
dev->lock.hw_lock = map->handle; /* Pointer to lock */
|
||||
}
|
||||
break;
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
case _DRM_AGP:
|
||||
map->offset = map->offset + dev->agp->base;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
down(&dev->struct_sem);
|
||||
if (dev->maplist) {
|
||||
++dev->map_count;
|
||||
dev->maplist = drm_realloc(dev->maplist,
|
||||
(dev->map_count-1)
|
||||
* sizeof(*dev->maplist),
|
||||
dev->map_count
|
||||
* sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS);
|
||||
} else {
|
||||
dev->map_count = 1;
|
||||
dev->maplist = drm_alloc(dev->map_count*sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS);
|
||||
}
|
||||
dev->maplist[dev->map_count-1] = map;
|
||||
up(&dev->struct_sem);
|
||||
|
||||
if (copy_to_user((drm_map_t *)arg, map, sizeof(*map)))
|
||||
return -EFAULT;
|
||||
if (map->type != _DRM_SHM) {
|
||||
if (copy_to_user(&((drm_map_t *)arg)->handle,
|
||||
&map->offset,
|
||||
sizeof(map->offset)))
|
||||
return -EFAULT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_addbufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int total;
|
||||
int page_order;
|
||||
drm_buf_entry_t *entry;
|
||||
unsigned long page;
|
||||
drm_buf_t *buf;
|
||||
int alignment;
|
||||
unsigned long offset;
|
||||
int i;
|
||||
int byte_count;
|
||||
int page_count;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = drm_order(request.size);
|
||||
size = 1 << order;
|
||||
|
||||
DRM_DEBUG("count = %d, size = %d (%d), order = %d, queue_count = %d\n",
|
||||
request.count, request.size, size, order, dev->queue_count);
|
||||
|
||||
if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) return -EINVAL;
|
||||
if (dev->queue_count) return -EBUSY; /* Not while in use */
|
||||
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN) ? PAGE_ALIGN(size):size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
|
||||
spin_lock(&dev->count_lock);
|
||||
if (dev->buf_use) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc(&dev->buf_alloc);
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
entry = &dma->bufs[order];
|
||||
if (entry->buf_count) {
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
if (!entry->buflist) {
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
|
||||
|
||||
entry->seglist = drm_alloc(count * sizeof(*entry->seglist),
|
||||
DRM_MEM_SEGS);
|
||||
if (!entry->seglist) {
|
||||
drm_free(entry->buflist,
|
||||
count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(entry->seglist, 0, count * sizeof(*entry->seglist));
|
||||
|
||||
dma->pagelist = drm_realloc(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
(dma->page_count + (count << page_order))
|
||||
* sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
DRM_DEBUG("pagelist: %d entries\n",
|
||||
dma->page_count + (count << page_order));
|
||||
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
byte_count = 0;
|
||||
page_count = 0;
|
||||
while (entry->buf_count < count) {
|
||||
if (!(page = drm_alloc_pages(page_order, DRM_MEM_DMA))) break;
|
||||
entry->seglist[entry->seg_count++] = page;
|
||||
for (i = 0; i < (1 << page_order); i++) {
|
||||
DRM_DEBUG("page %d @ 0x%08lx\n",
|
||||
dma->page_count + page_count,
|
||||
page + PAGE_SIZE * i);
|
||||
dma->pagelist[dma->page_count + page_count++]
|
||||
= page + PAGE_SIZE * i;
|
||||
}
|
||||
for (offset = 0;
|
||||
offset + size <= total && entry->buf_count < count;
|
||||
offset += alignment, ++entry->buf_count) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
buf->offset = (dma->byte_count + byte_count + offset);
|
||||
buf->address = (void *)(page + offset);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head(&buf->dma_wait);
|
||||
buf->pid = 0;
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
DRM_DEBUG("buffer %d @ %p\n",
|
||||
entry->buf_count, buf->address);
|
||||
}
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
dma->buflist = drm_realloc(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
for (i = dma->buf_count; i < dma->buf_count + entry->buf_count; i++)
|
||||
dma->buflist[i] = &entry->buflist[i - dma->buf_count];
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
dma->seg_count += entry->seg_count;
|
||||
dma->page_count += entry->seg_count << page_order;
|
||||
dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
|
||||
|
||||
drm_freelist_create(&entry->freelist, entry->buf_count);
|
||||
for (i = 0; i < entry->buf_count; i++) {
|
||||
drm_freelist_put(dev, &entry->freelist, &entry->buflist[i]);
|
||||
}
|
||||
|
||||
up(&dev->struct_sem);
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if (copy_to_user((drm_buf_desc_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_infobufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_info_t request;
|
||||
int i;
|
||||
int count;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
spin_lock(&dev->count_lock);
|
||||
if (atomic_read(&dev->buf_alloc)) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
++dev->buf_use; /* Can't allocate more after this call */
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_info_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
for (i = 0, count = 0; i < DRM_MAX_ORDER+1; i++) {
|
||||
if (dma->bufs[i].buf_count) ++count;
|
||||
}
|
||||
|
||||
DRM_DEBUG("count = %d\n", count);
|
||||
|
||||
if (request.count >= count) {
|
||||
for (i = 0, count = 0; i < DRM_MAX_ORDER+1; i++) {
|
||||
if (dma->bufs[i].buf_count) {
|
||||
if (copy_to_user(&request.list[count].count,
|
||||
&dma->bufs[i].buf_count,
|
||||
sizeof(dma->bufs[0]
|
||||
.buf_count)) ||
|
||||
copy_to_user(&request.list[count].size,
|
||||
&dma->bufs[i].buf_size,
|
||||
sizeof(dma->bufs[0].buf_size)) ||
|
||||
copy_to_user(&request.list[count].low_mark,
|
||||
&dma->bufs[i]
|
||||
.freelist.low_mark,
|
||||
sizeof(dma->bufs[0]
|
||||
.freelist.low_mark)) ||
|
||||
copy_to_user(&request.list[count]
|
||||
.high_mark,
|
||||
&dma->bufs[i]
|
||||
.freelist.high_mark,
|
||||
sizeof(dma->bufs[0]
|
||||
.freelist.high_mark)))
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG("%d %d %d %d %d\n",
|
||||
i,
|
||||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].buf_size,
|
||||
dma->bufs[i].freelist.low_mark,
|
||||
dma->bufs[i].freelist.high_mark);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
request.count = count;
|
||||
|
||||
if (copy_to_user((drm_buf_info_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_markbufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int order;
|
||||
drm_buf_entry_t *entry;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG("%d, %d, %d\n",
|
||||
request.size, request.low_mark, request.high_mark);
|
||||
order = drm_order(request.size);
|
||||
if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) return -EINVAL;
|
||||
entry = &dma->bufs[order];
|
||||
|
||||
if (request.low_mark < 0 || request.low_mark > entry->buf_count)
|
||||
return -EINVAL;
|
||||
if (request.high_mark < 0 || request.high_mark > entry->buf_count)
|
||||
return -EINVAL;
|
||||
|
||||
entry->freelist.low_mark = request.low_mark;
|
||||
entry->freelist.high_mark = request.high_mark;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_freebufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_free_t request;
|
||||
int i;
|
||||
int idx;
|
||||
drm_buf_t *buf;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_free_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG("%d\n", request.count);
|
||||
for (i = 0; i < request.count; i++) {
|
||||
if (copy_from_user(&idx,
|
||||
&request.list[i],
|
||||
sizeof(idx)))
|
||||
return -EFAULT;
|
||||
if (idx < 0 || idx >= dma->buf_count) {
|
||||
DRM_ERROR("Index %d (of %d max)\n",
|
||||
idx, dma->buf_count - 1);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = dma->buflist[idx];
|
||||
if (buf->pid != current->pid) {
|
||||
DRM_ERROR("Process %d freeing buffer owned by %d\n",
|
||||
current->pid, buf->pid);
|
||||
return -EINVAL;
|
||||
}
|
||||
drm_free_buffer(dev, buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_mapbufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int retcode = 0;
|
||||
const int zero = 0;
|
||||
unsigned long virtual;
|
||||
unsigned long address;
|
||||
drm_buf_map_t request;
|
||||
int i;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
spin_lock(&dev->count_lock);
|
||||
if (atomic_read(&dev->buf_alloc)) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
++dev->buf_use; /* Can't allocate more after this call */
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_map_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
if (request.count >= dma->buf_count) {
|
||||
down(¤t->mm->mmap_sem);
|
||||
virtual = do_mmap(filp, 0, dma->byte_count,
|
||||
PROT_READ|PROT_WRITE, MAP_SHARED, 0);
|
||||
up(¤t->mm->mmap_sem);
|
||||
if (virtual > -1024UL) {
|
||||
/* Real error */
|
||||
retcode = (signed long)virtual;
|
||||
goto done;
|
||||
}
|
||||
request.virtual = (void *)virtual;
|
||||
|
||||
for (i = 0; i < dma->buf_count; i++) {
|
||||
if (copy_to_user(&request.list[i].idx,
|
||||
&dma->buflist[i]->idx,
|
||||
sizeof(request.list[0].idx))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if (copy_to_user(&request.list[i].total,
|
||||
&dma->buflist[i]->total,
|
||||
sizeof(request.list[0].total))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if (copy_to_user(&request.list[i].used,
|
||||
&zero,
|
||||
sizeof(zero))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
address = virtual + dma->buflist[i]->offset;
|
||||
if (copy_to_user(&request.list[i].address,
|
||||
&address,
|
||||
sizeof(address))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
request.count = dma->buf_count;
|
||||
DRM_DEBUG("%d buffers, retcode = %d\n", request.count, retcode);
|
||||
|
||||
if (copy_to_user((drm_buf_map_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/* ctxbitmap.c -- Context bitmap management -*- linux-c -*-
|
||||
* Created: Thu Jan 6 03:56:42 2000 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* Copyright 2000 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.
|
||||
*
|
||||
* Author: Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle)
|
||||
{
|
||||
if (ctx_handle < 0) goto failed;
|
||||
|
||||
if (ctx_handle < DRM_MAX_CTXBITMAP) {
|
||||
clear_bit(ctx_handle, dev->ctx_bitmap);
|
||||
return;
|
||||
}
|
||||
failed:
|
||||
DRM_ERROR("Attempt to free invalid context handle: %d\n",
|
||||
ctx_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
int drm_ctxbitmap_next(drm_device_t *dev)
|
||||
{
|
||||
int bit;
|
||||
|
||||
bit = find_first_zero_bit(dev->ctx_bitmap, DRM_MAX_CTXBITMAP);
|
||||
if (bit < DRM_MAX_CTXBITMAP) {
|
||||
set_bit(bit, dev->ctx_bitmap);
|
||||
DRM_DEBUG("drm_ctxbitmap_next bit : %d\n", bit);
|
||||
return bit;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int drm_ctxbitmap_init(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
|
||||
dev->ctx_bitmap = (unsigned long *) drm_alloc(PAGE_SIZE,
|
||||
DRM_MEM_CTXBITMAP);
|
||||
if(dev->ctx_bitmap == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset((void *) dev->ctx_bitmap, 0, PAGE_SIZE);
|
||||
for(i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
|
||||
temp = drm_ctxbitmap_next(dev);
|
||||
DRM_DEBUG("drm_ctxbitmap_init : %d\n", temp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void drm_ctxbitmap_cleanup(drm_device_t *dev)
|
||||
{
|
||||
drm_free((void *)dev->ctx_bitmap, PAGE_SIZE,
|
||||
DRM_MEM_CTXBITMAP);
|
||||
}
|
||||
|
||||
36
linux/drm.h
36
linux/drm.h
|
|
@ -72,12 +72,20 @@ typedef unsigned int drm_magic_t;
|
|||
* XF86DRIClipRectRec in the server as well */
|
||||
|
||||
typedef struct drm_clip_rect {
|
||||
unsigned short x1;
|
||||
unsigned short y1;
|
||||
unsigned short x2;
|
||||
unsigned short y2;
|
||||
unsigned short x1;
|
||||
unsigned short y1;
|
||||
unsigned short x2;
|
||||
unsigned short y2;
|
||||
} drm_clip_rect_t;
|
||||
|
||||
typedef struct drm_tex_region {
|
||||
unsigned char next;
|
||||
unsigned char prev;
|
||||
unsigned char in_use;
|
||||
unsigned char padding;
|
||||
unsigned int age;
|
||||
} drm_tex_region_t;
|
||||
|
||||
/* Seperate include files for the i810/mga/r128 specific structures */
|
||||
#include "mga_drm.h"
|
||||
#include "i810_drm.h"
|
||||
|
|
@ -345,17 +353,19 @@ typedef struct drm_agp_info {
|
|||
#define DRM_IOCTL_AGP_BIND DRM_IOW( 0x36, drm_agp_binding_t)
|
||||
#define DRM_IOCTL_AGP_UNBIND DRM_IOW( 0x37, drm_agp_binding_t)
|
||||
|
||||
/* Mga specific ioctls */
|
||||
/* MGA specific ioctls */
|
||||
#define DRM_IOCTL_MGA_INIT DRM_IOW( 0x40, drm_mga_init_t)
|
||||
#define DRM_IOCTL_MGA_SWAP DRM_IOW( 0x41, drm_mga_swap_t)
|
||||
#define DRM_IOCTL_MGA_CLEAR DRM_IOW( 0x42, drm_mga_clear_t)
|
||||
#define DRM_IOCTL_MGA_ILOAD DRM_IOW( 0x43, drm_mga_iload_t)
|
||||
#define DRM_IOCTL_MGA_VERTEX DRM_IOW( 0x44, drm_mga_vertex_t)
|
||||
#define DRM_IOCTL_MGA_FLUSH DRM_IOW( 0x45, drm_lock_t )
|
||||
#define DRM_IOCTL_MGA_INDICES DRM_IOW( 0x46, drm_mga_indices_t)
|
||||
#define DRM_IOCTL_MGA_BLIT DRM_IOW( 0x47, drm_mga_blit_t)
|
||||
#define DRM_IOCTL_MGA_FLUSH DRM_IOW( 0x41, drm_lock_t)
|
||||
#define DRM_IOCTL_MGA_RESET DRM_IO( 0x42)
|
||||
#define DRM_IOCTL_MGA_SWAP DRM_IO( 0x43)
|
||||
#define DRM_IOCTL_MGA_CLEAR DRM_IOW( 0x44, drm_mga_clear_t)
|
||||
|
||||
/* I810 specific ioctls */
|
||||
#define DRM_IOCTL_MGA_ILOAD DRM_IOW( 0x45, drm_mga_iload_t)
|
||||
#define DRM_IOCTL_MGA_VERTEX DRM_IOW( 0x46, drm_mga_vertex_t)
|
||||
#define DRM_IOCTL_MGA_INDICES DRM_IOW( 0x47, drm_mga_indices_t)
|
||||
#define DRM_IOCTL_MGA_BLIT DRM_IOW( 0x48, drm_mga_blit_t)
|
||||
|
||||
/* i810 specific ioctls */
|
||||
#define DRM_IOCTL_I810_INIT DRM_IOW( 0x40, drm_i810_init_t)
|
||||
#define DRM_IOCTL_I810_VERTEX DRM_IOW( 0x41, drm_i810_vertex_t)
|
||||
#define DRM_IOCTL_I810_CLEAR DRM_IOW( 0x42, drm_i810_clear_t)
|
||||
|
|
|
|||
442
linux/drmP.h
442
linux/drmP.h
|
|
@ -25,8 +25,8 @@
|
|||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
*
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef _DRM_P_H_
|
||||
|
|
@ -75,6 +75,32 @@
|
|||
#endif
|
||||
#include "drm.h"
|
||||
|
||||
/* DRM template customization defaults
|
||||
*/
|
||||
#ifndef __HAVE_AGP
|
||||
#define __HAVE_AGP 0
|
||||
#endif
|
||||
#ifndef __HAVE_MTRR
|
||||
#define __HAVE_MTRR 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA
|
||||
#define __HAVE_DMA 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_WAITLIST
|
||||
#define __HAVE_DMA_WAITLIST 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_FREELIST
|
||||
#define __HAVE_DMA_FREELIST 0
|
||||
#endif
|
||||
|
||||
#define __REALLY_HAVE_AGP (__HAVE_AGP && (defined(CONFIG_AGP) || \
|
||||
defined(CONFIG_AGP_MODULE)))
|
||||
#define __REALLY_HAVE_MTRR (__HAVE_MTRR && defined(CONFIG_MTRR))
|
||||
|
||||
|
||||
/* Begin the DRM...
|
||||
*/
|
||||
|
||||
#define DRM_DEBUG_CODE 2 /* Include debugging code (if > 1, then
|
||||
also include looping detection. */
|
||||
#define DRM_DMA_HISTOGRAM 1 /* Make histogram of DMA latency. */
|
||||
|
|
@ -263,12 +289,12 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
|
|||
#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
|
||||
|
||||
#if DRM_DEBUG_CODE
|
||||
#define DRM_DEBUG(fmt, arg...) \
|
||||
do { \
|
||||
if (drm_flags&DRM_FLAG_DEBUG) \
|
||||
printk(KERN_DEBUG \
|
||||
"[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
|
||||
##arg); \
|
||||
#define DRM_DEBUG(fmt, arg...) \
|
||||
do { \
|
||||
if ( DRM(flags) & DRM_FLAG_DEBUG ) \
|
||||
printk(KERN_DEBUG \
|
||||
"[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
|
||||
##arg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define DRM_DEBUG(fmt, arg...) do { } while (0)
|
||||
|
|
@ -284,27 +310,6 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
|
|||
len += sprintf(&buf[len], fmt , ##arg); \
|
||||
if (len > DRM_PROC_LIMIT) { ret; return len; }
|
||||
|
||||
/* Mapping helper macros */
|
||||
#define DRM_IOREMAP(map) \
|
||||
(map)->handle = drm_ioremap( (map)->offset, (map)->size )
|
||||
|
||||
#define DRM_IOREMAPFREE(map) \
|
||||
do { \
|
||||
if ( (map)->handle && (map)->size ) \
|
||||
drm_ioremapfree( (map)->handle, (map)->size ); \
|
||||
} while (0)
|
||||
|
||||
#define DRM_FIND_MAP(map, o) \
|
||||
do { \
|
||||
int i; \
|
||||
for ( i = 0 ; i < dev->map_count ; i++ ) { \
|
||||
if ( dev->maplist[i]->offset == o ) { \
|
||||
map = dev->maplist[i]; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Internal types and structures */
|
||||
#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
|
||||
|
|
@ -314,8 +319,8 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
|
|||
#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
|
||||
#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
|
||||
|
||||
typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
typedef struct drm_ioctl_desc {
|
||||
drm_ioctl_t *func;
|
||||
|
|
@ -501,7 +506,7 @@ typedef struct drm_device_dma {
|
|||
unsigned long *pagelist;
|
||||
unsigned long byte_count;
|
||||
enum {
|
||||
_DRM_DMA_USE_AGP = 0x01
|
||||
_DRM_DMA_USE_AGP = 0x01
|
||||
} flags;
|
||||
|
||||
/* DMA support */
|
||||
|
|
@ -511,7 +516,7 @@ typedef struct drm_device_dma {
|
|||
wait_queue_head_t waiting; /* Processes waiting on free bufs */
|
||||
} drm_device_dma_t;
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
#if __REALLY_HAVE_AGP
|
||||
typedef struct drm_agp_mem {
|
||||
unsigned long handle;
|
||||
agp_memory *memory;
|
||||
|
|
@ -617,7 +622,7 @@ typedef struct drm_device {
|
|||
wait_queue_head_t buf_readers; /* Processes waiting to read */
|
||||
wait_queue_head_t buf_writers; /* Processes waiting to ctx switch */
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
#if __REALLY_HAVE_AGP
|
||||
drm_agp_head_t *agp;
|
||||
#endif
|
||||
unsigned long *ctx_bitmap;
|
||||
|
|
@ -630,227 +635,234 @@ typedef struct drm_device {
|
|||
/* Internal function definitions */
|
||||
|
||||
/* Misc. support (init.c) */
|
||||
extern int drm_flags;
|
||||
extern void drm_parse_options(char *s);
|
||||
extern int drm_cpu_valid(void);
|
||||
extern int DRM(flags);
|
||||
extern void DRM(parse_options)( char *s );
|
||||
extern int DRM(cpu_valid)( void );
|
||||
|
||||
|
||||
/* Device support (fops.c) */
|
||||
extern int drm_open_helper(struct inode *inode, struct file *filp,
|
||||
drm_device_t *dev);
|
||||
extern int drm_flush(struct file *filp);
|
||||
extern int drm_release(struct inode *inode, struct file *filp);
|
||||
extern int drm_fasync(int fd, struct file *filp, int on);
|
||||
extern ssize_t drm_read(struct file *filp, char *buf, size_t count,
|
||||
loff_t *off);
|
||||
extern int drm_write_string(drm_device_t *dev, const char *s);
|
||||
extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
|
||||
extern int DRM(open_helper)(struct inode *inode, struct file *filp,
|
||||
drm_device_t *dev);
|
||||
extern int DRM(flush)(struct file *filp);
|
||||
extern int DRM(release_fuck)(struct inode *inode, struct file *filp);
|
||||
extern int DRM(fasync)(int fd, struct file *filp, int on);
|
||||
extern ssize_t DRM(read)(struct file *filp, char *buf, size_t count,
|
||||
loff_t *off);
|
||||
extern int DRM(write_string)(drm_device_t *dev, const char *s);
|
||||
extern unsigned int DRM(poll)(struct file *filp,
|
||||
struct poll_table_struct *wait);
|
||||
|
||||
/* Mapping support (vm.c) */
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
extern unsigned long drm_vm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long drm_vm_shm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long drm_vm_dma_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern unsigned long DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
extern struct page *drm_vm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
extern struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access);
|
||||
#endif
|
||||
extern void drm_vm_open(struct vm_area_struct *vma);
|
||||
extern void drm_vm_close(struct vm_area_struct *vma);
|
||||
extern int drm_mmap_dma(struct file *filp,
|
||||
struct vm_area_struct *vma);
|
||||
extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
|
||||
extern void DRM(vm_open)(struct vm_area_struct *vma);
|
||||
extern void DRM(vm_close)(struct vm_area_struct *vma);
|
||||
extern int DRM(mmap_dma)(struct file *filp,
|
||||
struct vm_area_struct *vma);
|
||||
extern int DRM(mmap)(struct file *filp, struct vm_area_struct *vma);
|
||||
|
||||
|
||||
/* Proc support (proc.c) */
|
||||
extern int drm_proc_init(drm_device_t *dev);
|
||||
extern int drm_proc_cleanup(void);
|
||||
extern int DRM(proc_init)(drm_device_t *dev);
|
||||
extern int DRM(proc_cleanup)(void);
|
||||
|
||||
/* Memory management support (memory.c) */
|
||||
extern void drm_mem_init(void);
|
||||
extern int drm_mem_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
extern void *drm_alloc(size_t size, int area);
|
||||
extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
|
||||
int area);
|
||||
extern char *drm_strdup(const char *s, int area);
|
||||
extern void drm_strfree(const char *s, int area);
|
||||
extern void drm_free(void *pt, size_t size, int area);
|
||||
extern unsigned long drm_alloc_pages(int order, int area);
|
||||
extern void drm_free_pages(unsigned long address, int order,
|
||||
int area);
|
||||
extern void *drm_ioremap(unsigned long offset, unsigned long size);
|
||||
extern void drm_ioremapfree(void *pt, unsigned long size);
|
||||
extern void DRM(mem_init)(void);
|
||||
extern int DRM(mem_info)(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
extern void *DRM(alloc)(size_t size, int area);
|
||||
extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
|
||||
int area);
|
||||
extern char *DRM(strdup)(const char *s, int area);
|
||||
extern void DRM(strfree)(const char *s, int area);
|
||||
extern void DRM(free)(void *pt, size_t size, int area);
|
||||
extern unsigned long DRM(alloc_pages)(int order, int area);
|
||||
extern void DRM(free_pages)(unsigned long address, int order,
|
||||
int area);
|
||||
extern void *DRM(ioremap)(unsigned long offset, unsigned long size);
|
||||
extern void DRM(ioremapfree)(void *pt, unsigned long size);
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
extern agp_memory *drm_alloc_agp(int pages, u32 type);
|
||||
extern int drm_free_agp(agp_memory *handle, int pages);
|
||||
extern int drm_bind_agp(agp_memory *handle, unsigned int start);
|
||||
extern int drm_unbind_agp(agp_memory *handle);
|
||||
#if __REALLY_HAVE_AGP
|
||||
extern agp_memory *DRM(alloc_agp)(int pages, u32 type);
|
||||
extern int DRM(free_agp)(agp_memory *handle, int pages);
|
||||
extern int DRM(bind_agp)(agp_memory *handle, unsigned int start);
|
||||
extern int DRM(unbind_agp)(agp_memory *handle);
|
||||
#endif
|
||||
|
||||
|
||||
/* Buffer management support (bufs.c) */
|
||||
extern int drm_order(unsigned long size);
|
||||
extern int drm_addmap(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_addbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_infobufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_markbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_freebufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_mapbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Buffer list management support (lists.c) */
|
||||
extern int drm_waitlist_create(drm_waitlist_t *bl, int count);
|
||||
extern int drm_waitlist_destroy(drm_waitlist_t *bl);
|
||||
extern int drm_waitlist_put(drm_waitlist_t *bl, drm_buf_t *buf);
|
||||
extern drm_buf_t *drm_waitlist_get(drm_waitlist_t *bl);
|
||||
|
||||
extern int drm_freelist_create(drm_freelist_t *bl, int count);
|
||||
extern int drm_freelist_destroy(drm_freelist_t *bl);
|
||||
extern int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl,
|
||||
drm_buf_t *buf);
|
||||
extern drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block);
|
||||
|
||||
/* DMA support (gen_dma.c) */
|
||||
extern void drm_dma_setup(drm_device_t *dev);
|
||||
extern void drm_dma_takedown(drm_device_t *dev);
|
||||
extern void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
|
||||
extern void drm_reclaim_buffers(drm_device_t *dev, pid_t pid);
|
||||
extern int drm_context_switch(drm_device_t *dev, int old, int new);
|
||||
extern int drm_context_switch_complete(drm_device_t *dev, int new);
|
||||
extern void drm_clear_next_buffer(drm_device_t *dev);
|
||||
extern int drm_select_queue(drm_device_t *dev,
|
||||
void (*wrapper)(unsigned long));
|
||||
extern int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *dma);
|
||||
extern int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma);
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
extern int drm_histogram_slot(unsigned long count);
|
||||
extern void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf);
|
||||
#endif
|
||||
|
||||
|
||||
/* Misc. IOCTL support (ioctl.c) */
|
||||
extern int drm_irq_busid(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_getunique(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_setunique(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(irq_busid)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(getunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(setunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Context IOCTL support (context.c) */
|
||||
extern int drm_resctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_addctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_modctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_getctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_switchctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_newctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_rmctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(resctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(addctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(modctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(getctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(switchctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(newctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(rmctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
|
||||
/* Drawable IOCTL support (drawable.c) */
|
||||
extern int drm_adddraw(struct inode *inode, struct file *filp,
|
||||
extern int DRM(adddraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(rmdraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_rmdraw(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Authentication IOCTL support (auth.c) */
|
||||
extern int drm_add_magic(drm_device_t *dev, drm_file_t *priv,
|
||||
drm_magic_t magic);
|
||||
extern int drm_remove_magic(drm_device_t *dev, drm_magic_t magic);
|
||||
extern int drm_getmagic(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_authmagic(struct inode *inode, struct file *filp,
|
||||
extern int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
|
||||
drm_magic_t magic);
|
||||
extern int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
|
||||
extern int DRM(getmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(authmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
||||
|
||||
/* Locking IOCTL support (lock.c) */
|
||||
extern int drm_block(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_unblock(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_lock_take(__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int drm_lock_transfer(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int drm_lock_free(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int drm_finish(struct inode *inode, struct file *filp,
|
||||
extern int DRM(block)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_flush_unblock(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int drm_flush_block_and_flush(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int drm_notifier(void *priv);
|
||||
extern int DRM(unblock)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(lock_take)(__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int DRM(lock_transfer)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int DRM(lock_free)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock,
|
||||
unsigned int context);
|
||||
extern int DRM(finish)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(flush_unblock)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags);
|
||||
extern int DRM(notifier)(void *priv);
|
||||
|
||||
/* Context Bitmap support (ctxbitmap.c) */
|
||||
extern int drm_ctxbitmap_init(drm_device_t *dev);
|
||||
extern void drm_ctxbitmap_cleanup(drm_device_t *dev);
|
||||
extern int drm_ctxbitmap_next(drm_device_t *dev);
|
||||
extern void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
|
||||
extern int DRM(ctxbitmap_init)( drm_device_t *dev );
|
||||
extern void DRM(ctxbitmap_cleanup)( drm_device_t *dev );
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
|
||||
|
||||
|
||||
/* Buffer management support (bufs.c) */
|
||||
extern int DRM(order)( unsigned long size );
|
||||
extern int DRM(addmap)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(addbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(infobufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(markbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(freebufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int DRM(mapbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
|
||||
#if __HAVE_DMA
|
||||
/* DMA support (dma.c) */
|
||||
extern int DRM(dma_setup)(drm_device_t *dev);
|
||||
extern void DRM(dma_takedown)(drm_device_t *dev);
|
||||
extern void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
|
||||
extern void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid);
|
||||
extern int DRM(context_switch)(drm_device_t *dev, int old, int new);
|
||||
extern int DRM(context_switch_complete)(drm_device_t *dev, int new);
|
||||
extern void DRM(clear_next_buffer)(drm_device_t *dev);
|
||||
extern int DRM(select_queue)(drm_device_t *dev,
|
||||
void (*wrapper)(unsigned long));
|
||||
extern int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *dma);
|
||||
#if 0
|
||||
extern int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma);
|
||||
#endif
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
extern int DRM(histogram_slot)(unsigned long count);
|
||||
extern void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Buffer list management support (lists.c) */
|
||||
#if __HAVE_DMA_WAITLIST
|
||||
extern int DRM(waitlist_create)(drm_waitlist_t *bl, int count);
|
||||
extern int DRM(waitlist_destroy)(drm_waitlist_t *bl);
|
||||
extern int DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf);
|
||||
extern drm_buf_t *DRM(waitlist_get)(drm_waitlist_t *bl);
|
||||
#endif
|
||||
#if __HAVE_DMA_FREELIST
|
||||
extern int DRM(freelist_create)(drm_freelist_t *bl, int count);
|
||||
extern int DRM(freelist_destroy)(drm_freelist_t *bl);
|
||||
extern int DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl,
|
||||
drm_buf_t *buf);
|
||||
extern drm_buf_t *DRM(freelist_get)(drm_freelist_t *bl, int block);
|
||||
#endif
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
/* AGP/GART support (agpsupport.c) */
|
||||
extern drm_agp_head_t *drm_agp_init(void);
|
||||
extern void drm_agp_uninit(void);
|
||||
extern int drm_agp_acquire(struct inode *inode, struct file *filp,
|
||||
extern drm_agp_head_t *DRM(agp_init)(void);
|
||||
extern void DRM(agp_uninit)(void);
|
||||
extern int DRM(agp_acquire)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void DRM(agp_do_release)(void);
|
||||
extern int DRM(agp_release)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(agp_enable)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern void _drm_agp_release(void);
|
||||
extern int drm_agp_release(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_enable(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_info(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_alloc(struct inode *inode, struct file *filp,
|
||||
extern int DRM(agp_info)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_free(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_unbind(struct inode *inode, struct file *filp,
|
||||
extern int DRM(agp_alloc)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int drm_agp_bind(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern agp_memory *drm_agp_allocate_memory(size_t pages, u32 type);
|
||||
extern int drm_agp_free_memory(agp_memory *handle);
|
||||
extern int drm_agp_bind_memory(agp_memory *handle, off_t start);
|
||||
extern int drm_agp_unbind_memory(agp_memory *handle);
|
||||
extern int DRM(agp_free)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(agp_unbind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int DRM(agp_bind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type);
|
||||
extern int DRM(agp_free_memory)(agp_memory *handle);
|
||||
extern int DRM(agp_bind_memory)(agp_memory *handle, off_t start);
|
||||
extern int DRM(agp_unbind_memory)(agp_memory *handle);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
335
linux/drm_agpsupport.h
Normal file
335
linux/drm_agpsupport.h
Normal file
|
|
@ -0,0 +1,335 @@
|
|||
/* drm_agpsupport.h -- DRM support for AGP/GART backend -*- linux-c -*-
|
||||
* Created: Mon Dec 13 09:56:45 1999 by faith@precisioninsight.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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.
|
||||
*
|
||||
* Author:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <linux/module.h>
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020400
|
||||
#include "agpsupport-pre24.h"
|
||||
#else
|
||||
#define DRM_AGP_GET (drm_agp_t *)inter_module_get("drm_agp")
|
||||
#define DRM_AGP_PUT inter_module_put("drm_agp")
|
||||
#endif
|
||||
|
||||
static const drm_agp_t *drm_agp = NULL;
|
||||
|
||||
int DRM(agp_info)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
agp_kern_info *kern;
|
||||
drm_agp_info_t info;
|
||||
|
||||
if (!dev->agp->acquired || !drm_agp->copy_info) return -EINVAL;
|
||||
|
||||
kern = &dev->agp->agp_info;
|
||||
info.agp_version_major = kern->version.major;
|
||||
info.agp_version_minor = kern->version.minor;
|
||||
info.mode = kern->mode;
|
||||
info.aperture_base = kern->aper_base;
|
||||
info.aperture_size = kern->aper_size * 1024 * 1024;
|
||||
info.memory_allowed = kern->max_memory << PAGE_SHIFT;
|
||||
info.memory_used = kern->current_memory << PAGE_SHIFT;
|
||||
info.id_vendor = kern->device->vendor;
|
||||
info.id_device = kern->device->device;
|
||||
|
||||
if (copy_to_user((drm_agp_info_t *)arg, &info, sizeof(info)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(agp_acquire)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int retcode;
|
||||
|
||||
if (dev->agp->acquired || !drm_agp->acquire) return -EINVAL;
|
||||
if ((retcode = drm_agp->acquire())) return retcode;
|
||||
dev->agp->acquired = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(agp_release)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
||||
if (!dev->agp->acquired || !drm_agp->release) return -EINVAL;
|
||||
drm_agp->release();
|
||||
dev->agp->acquired = 0;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void DRM(agp_do_release)(void)
|
||||
{
|
||||
if (drm_agp->release) drm_agp->release();
|
||||
}
|
||||
|
||||
int DRM(agp_enable)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_agp_mode_t mode;
|
||||
|
||||
if (!dev->agp->acquired || !drm_agp->enable) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&mode, (drm_agp_mode_t *)arg, sizeof(mode)))
|
||||
return -EFAULT;
|
||||
|
||||
dev->agp->mode = mode.mode;
|
||||
drm_agp->enable(mode.mode);
|
||||
dev->agp->base = dev->agp->agp_info.aper_base;
|
||||
dev->agp->enabled = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(agp_alloc)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_agp_buffer_t request;
|
||||
drm_agp_mem_t *entry;
|
||||
agp_memory *memory;
|
||||
unsigned long pages;
|
||||
u32 type;
|
||||
|
||||
if (!dev->agp->acquired) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_buffer_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = DRM(alloc)(sizeof(*entry), DRM_MEM_AGPLISTS)))
|
||||
return -ENOMEM;
|
||||
|
||||
memset(entry, 0, sizeof(*entry));
|
||||
|
||||
pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
type = (u32) request.type;
|
||||
|
||||
if (!(memory = DRM(alloc_agp)(pages, type))) {
|
||||
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
entry->handle = (unsigned long)memory->memory;
|
||||
entry->memory = memory;
|
||||
entry->bound = 0;
|
||||
entry->pages = pages;
|
||||
entry->prev = NULL;
|
||||
entry->next = dev->agp->memory;
|
||||
if (dev->agp->memory) dev->agp->memory->prev = entry;
|
||||
dev->agp->memory = entry;
|
||||
|
||||
request.handle = entry->handle;
|
||||
request.physical = memory->physical;
|
||||
|
||||
if (copy_to_user((drm_agp_buffer_t *)arg, &request, sizeof(request))) {
|
||||
dev->agp->memory = entry->next;
|
||||
dev->agp->memory->prev = NULL;
|
||||
DRM(free_agp)(memory, pages);
|
||||
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
return -EFAULT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static drm_agp_mem_t *DRM(agp_lookup_entry)(drm_device_t *dev,
|
||||
unsigned long handle)
|
||||
{
|
||||
drm_agp_mem_t *entry;
|
||||
|
||||
for (entry = dev->agp->memory; entry; entry = entry->next) {
|
||||
if (entry->handle == handle) return entry;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DRM(agp_unbind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_agp_binding_t request;
|
||||
drm_agp_mem_t *entry;
|
||||
|
||||
if (!dev->agp->acquired) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_binding_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = DRM(agp_lookup_entry)(dev, request.handle)))
|
||||
return -EINVAL;
|
||||
if (!entry->bound) return -EINVAL;
|
||||
return DRM(unbind_agp)(entry->memory);
|
||||
}
|
||||
|
||||
int DRM(agp_bind)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_agp_binding_t request;
|
||||
drm_agp_mem_t *entry;
|
||||
int retcode;
|
||||
int page;
|
||||
|
||||
if (!dev->agp->acquired || !drm_agp->bind_memory) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_binding_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = DRM(agp_lookup_entry)(dev, request.handle)))
|
||||
return -EINVAL;
|
||||
if (entry->bound) return -EINVAL;
|
||||
page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
if ((retcode = DRM(bind_agp)(entry->memory, page))) return retcode;
|
||||
entry->bound = dev->agp->base + (page << PAGE_SHIFT);
|
||||
DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
|
||||
dev->agp->base, entry->bound);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(agp_free)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_agp_buffer_t request;
|
||||
drm_agp_mem_t *entry;
|
||||
|
||||
if (!dev->agp->acquired) return -EINVAL;
|
||||
if (copy_from_user(&request, (drm_agp_buffer_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
if (!(entry = DRM(agp_lookup_entry)(dev, request.handle)))
|
||||
return -EINVAL;
|
||||
if (entry->bound) DRM(unbind_agp)(entry->memory);
|
||||
|
||||
if (entry->prev) entry->prev->next = entry->next;
|
||||
else dev->agp->memory = entry->next;
|
||||
if (entry->next) entry->next->prev = entry->prev;
|
||||
DRM(free_agp)(entry->memory, entry->pages);
|
||||
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
drm_agp_head_t *DRM(agp_init)(void)
|
||||
{
|
||||
drm_agp_head_t *head = NULL;
|
||||
|
||||
drm_agp = DRM_AGP_GET;
|
||||
if (drm_agp) {
|
||||
if (!(head = DRM(alloc)(sizeof(*head), DRM_MEM_AGPLISTS)))
|
||||
return NULL;
|
||||
memset((void *)head, 0, sizeof(*head));
|
||||
drm_agp->copy_info(&head->agp_info);
|
||||
if (head->agp_info.chipset == NOT_SUPPORTED) {
|
||||
DRM(free)(head, sizeof(*head), DRM_MEM_AGPLISTS);
|
||||
return NULL;
|
||||
}
|
||||
head->memory = NULL;
|
||||
switch (head->agp_info.chipset) {
|
||||
case INTEL_GENERIC: head->chipset = "Intel"; break;
|
||||
case INTEL_LX: head->chipset = "Intel 440LX"; break;
|
||||
case INTEL_BX: head->chipset = "Intel 440BX"; break;
|
||||
case INTEL_GX: head->chipset = "Intel 440GX"; break;
|
||||
case INTEL_I810: head->chipset = "Intel i810"; break;
|
||||
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
case INTEL_I840: head->chipset = "Intel i840"; break;
|
||||
#endif
|
||||
|
||||
case VIA_GENERIC: head->chipset = "VIA"; break;
|
||||
case VIA_VP3: head->chipset = "VIA VP3"; break;
|
||||
case VIA_MVP3: head->chipset = "VIA MVP3"; break;
|
||||
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
case VIA_MVP4: head->chipset = "VIA MVP4"; break;
|
||||
case VIA_APOLLO_KX133: head->chipset = "VIA Apollo KX133";
|
||||
break;
|
||||
case VIA_APOLLO_KT133: head->chipset = "VIA Apollo KT133";
|
||||
break;
|
||||
#endif
|
||||
|
||||
case VIA_APOLLO_PRO: head->chipset = "VIA Apollo Pro";
|
||||
break;
|
||||
case SIS_GENERIC: head->chipset = "SiS"; break;
|
||||
case AMD_GENERIC: head->chipset = "AMD"; break;
|
||||
case AMD_IRONGATE: head->chipset = "AMD Irongate"; break;
|
||||
case ALI_GENERIC: head->chipset = "ALi"; break;
|
||||
case ALI_M1541: head->chipset = "ALi M1541"; break;
|
||||
default: head->chipset = "Unknown"; break;
|
||||
}
|
||||
DRM_INFO("AGP %d.%d on %s @ 0x%08lx %ZuMB\n",
|
||||
head->agp_info.version.major,
|
||||
head->agp_info.version.minor,
|
||||
head->chipset,
|
||||
head->agp_info.aper_base,
|
||||
head->agp_info.aper_size);
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
void DRM(agp_uninit)(void)
|
||||
{
|
||||
DRM_AGP_PUT;
|
||||
drm_agp = NULL;
|
||||
}
|
||||
|
||||
agp_memory *DRM(agp_allocate_memory)(size_t pages, u32 type)
|
||||
{
|
||||
if (!drm_agp->allocate_memory) return NULL;
|
||||
return drm_agp->allocate_memory(pages, type);
|
||||
}
|
||||
|
||||
int DRM(agp_free_memory)(agp_memory *handle)
|
||||
{
|
||||
if (!handle || !drm_agp->free_memory) return 0;
|
||||
drm_agp->free_memory(handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DRM(agp_bind_memory)(agp_memory *handle, off_t start)
|
||||
{
|
||||
if (!handle || !drm_agp->bind_memory) return -EINVAL;
|
||||
return drm_agp->bind_memory(handle, start);
|
||||
}
|
||||
|
||||
int DRM(agp_unbind_memory)(agp_memory *handle)
|
||||
{
|
||||
if (!handle || !drm_agp->unbind_memory) return -EINVAL;
|
||||
return drm_agp->unbind_memory(handle);
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE) */
|
||||
162
linux/drm_auth.h
Normal file
162
linux/drm_auth.h
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/* drm_auth.h -- IOCTLs for authentication -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
static int DRM(hash_magic)(drm_magic_t magic)
|
||||
{
|
||||
return magic & (DRM_HASH_SIZE-1);
|
||||
}
|
||||
|
||||
static drm_file_t *DRM(find_file)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_file_t *retval = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash = DRM(hash_magic)(magic);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
retval = pt->priv;
|
||||
break;
|
||||
}
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic)
|
||||
{
|
||||
int hash;
|
||||
drm_magic_entry_t *entry;
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
|
||||
hash = DRM(hash_magic)(magic);
|
||||
entry = DRM(alloc)(sizeof(*entry), DRM_MEM_MAGIC);
|
||||
if (!entry) return -ENOMEM;
|
||||
entry->magic = magic;
|
||||
entry->priv = priv;
|
||||
entry->next = NULL;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
if (dev->magiclist[hash].tail) {
|
||||
dev->magiclist[hash].tail->next = entry;
|
||||
dev->magiclist[hash].tail = entry;
|
||||
} else {
|
||||
dev->magiclist[hash].head = entry;
|
||||
dev->magiclist[hash].tail = entry;
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic)
|
||||
{
|
||||
drm_magic_entry_t *prev = NULL;
|
||||
drm_magic_entry_t *pt;
|
||||
int hash;
|
||||
|
||||
DRM_DEBUG("%d\n", magic);
|
||||
hash = DRM(hash_magic)(magic);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
|
||||
if (pt->magic == magic) {
|
||||
if (dev->magiclist[hash].head == pt) {
|
||||
dev->magiclist[hash].head = pt->next;
|
||||
}
|
||||
if (dev->magiclist[hash].tail == pt) {
|
||||
dev->magiclist[hash].tail = prev;
|
||||
}
|
||||
if (prev) {
|
||||
prev->next = pt->next;
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int DRM(getmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
static drm_magic_t sequence = 0;
|
||||
static spinlock_t lock = SPIN_LOCK_UNLOCKED;
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_auth_t auth;
|
||||
|
||||
/* Find unique magic */
|
||||
if (priv->magic) {
|
||||
auth.magic = priv->magic;
|
||||
} else {
|
||||
do {
|
||||
spin_lock(&lock);
|
||||
if (!sequence) ++sequence; /* reserve 0 */
|
||||
auth.magic = sequence++;
|
||||
spin_unlock(&lock);
|
||||
} while (DRM(find_file)(dev, auth.magic));
|
||||
priv->magic = auth.magic;
|
||||
DRM(add_magic)(dev, priv, auth.magic);
|
||||
}
|
||||
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
if (copy_to_user((drm_auth_t *)arg, &auth, sizeof(auth)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(authmagic)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_auth_t auth;
|
||||
drm_file_t *file;
|
||||
|
||||
if (copy_from_user(&auth, (drm_auth_t *)arg, sizeof(auth)))
|
||||
return -EFAULT;
|
||||
DRM_DEBUG("%u\n", auth.magic);
|
||||
if ((file = DRM(find_file)(dev, auth.magic))) {
|
||||
file->authenticated = 1;
|
||||
DRM(remove_magic)(dev, auth.magic);
|
||||
return 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
746
linux/drm_bufs.h
Normal file
746
linux/drm_bufs.h
Normal file
|
|
@ -0,0 +1,746 @@
|
|||
/* drm_bufs.h -- Generic buffer template -*- linux-c -*-
|
||||
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#ifndef __HAVE_PCI_DMA
|
||||
#define __HAVE_PCI_DMA 0
|
||||
#endif
|
||||
|
||||
#ifndef DRIVER_BUF_PRIV_T
|
||||
#define DRIVER_BUF_PRIV_T u32
|
||||
#endif
|
||||
#ifndef DRIVER_AGP_BUFFER_MAP
|
||||
#define DRIVER_AGP_BUFFER_MAP NULL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compute order. Can be made faster.
|
||||
*/
|
||||
int DRM(order)( unsigned long size )
|
||||
{
|
||||
int order;
|
||||
unsigned long tmp;
|
||||
|
||||
for ( order = 0, tmp = size ; tmp >>= 1 ; ++order );
|
||||
|
||||
if ( size & ~(1 << order) )
|
||||
++order;
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
int DRM(addmap)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_map_t *map;
|
||||
|
||||
if ( !(filp->f_mode & 3) ) return -EACCES; /* Require read/write */
|
||||
|
||||
map = DRM(alloc)( sizeof(*map), DRM_MEM_MAPS );
|
||||
if ( !map )
|
||||
return -ENOMEM;
|
||||
|
||||
if ( copy_from_user( map, (drm_map_t *)arg, sizeof(*map) ) ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "offset = 0x%08lx, size = 0x%08lx, type = %d\n",
|
||||
map->offset, map->size, map->type );
|
||||
if ( (map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK)) ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EINVAL;
|
||||
}
|
||||
map->mtrr = -1;
|
||||
map->handle = 0;
|
||||
|
||||
switch ( map->type ) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#ifndef __sparc__
|
||||
if ( map->offset + map->size < map->offset ||
|
||||
map->offset < virt_to_phys(high_memory) ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_MTRR
|
||||
if ( map->type == _DRM_FRAME_BUFFER ||
|
||||
(map->flags & _DRM_WRITE_COMBINING) ) {
|
||||
map->mtrr = mtrr_add( map->offset, map->size,
|
||||
MTRR_TYPE_WRCOMB, 1 );
|
||||
}
|
||||
#endif
|
||||
map->handle = DRM(ioremap)( map->offset, map->size );
|
||||
break;
|
||||
|
||||
case _DRM_SHM:
|
||||
map->handle = (void *)DRM(alloc_pages)( DRM(order)( map->size )
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA );
|
||||
DRM_DEBUG( "%ld %d %p\n",
|
||||
map->size, DRM(order)( map->size ), map->handle );
|
||||
if ( !map->handle ) {
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -ENOMEM;
|
||||
}
|
||||
map->offset = (unsigned long)map->handle;
|
||||
if ( map->flags & _DRM_CONTAINS_LOCK ) {
|
||||
dev->lock.hw_lock = map->handle; /* Pointer to lock */
|
||||
}
|
||||
break;
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
case _DRM_AGP:
|
||||
map->offset = map->offset + dev->agp->base;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
down( &dev->struct_sem );
|
||||
if ( dev->maplist ) {
|
||||
++dev->map_count;
|
||||
dev->maplist = DRM(realloc)( dev->maplist,
|
||||
(dev->map_count-1)
|
||||
* sizeof(*dev->maplist),
|
||||
dev->map_count
|
||||
* sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS );
|
||||
} else {
|
||||
dev->map_count = 1;
|
||||
dev->maplist = DRM(alloc)( dev->map_count*sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS );
|
||||
}
|
||||
dev->maplist[dev->map_count-1] = map;
|
||||
up( &dev->struct_sem );
|
||||
|
||||
if ( copy_to_user( (drm_map_t *)arg, map, sizeof(*map) ) )
|
||||
return -EFAULT;
|
||||
if ( map->type != _DRM_SHM ) {
|
||||
if ( copy_to_user( &((drm_map_t *)arg)->handle,
|
||||
&map->offset,
|
||||
sizeof(map->offset) ) )
|
||||
return -EFAULT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
int DRM(addbufs_agp)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
drm_buf_entry_t *entry;
|
||||
drm_buf_t *buf;
|
||||
unsigned long offset;
|
||||
unsigned long agp_offset;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int alignment;
|
||||
int page_order;
|
||||
int total;
|
||||
int byte_count;
|
||||
int i;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = DRM(order)( request.size );
|
||||
size = 1 << order;
|
||||
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN)
|
||||
? PAGE_ALIGN(size) : size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
|
||||
byte_count = 0;
|
||||
agp_offset = dev->agp->base + request.agp_start;
|
||||
|
||||
DRM_DEBUG( "count: %d\n", count );
|
||||
DRM_DEBUG( "order: %d\n", order );
|
||||
DRM_DEBUG( "size: %d\n", size );
|
||||
DRM_DEBUG( "agp_offset: %ld\n", agp_offset );
|
||||
DRM_DEBUG( "alignment: %d\n", alignment );
|
||||
DRM_DEBUG( "page_order: %d\n", page_order );
|
||||
DRM_DEBUG( "total: %d\n", total );
|
||||
|
||||
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
|
||||
if ( dev->queue_count ) return -EBUSY; /* Not while in use */
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( dev->buf_use ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc( &dev->buf_alloc );
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
down( &dev->struct_sem );
|
||||
entry = &dma->bufs[order];
|
||||
if ( entry->buf_count ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
if ( !entry->buflist ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
|
||||
offset = 0;
|
||||
|
||||
while ( entry->buf_count < count ) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
|
||||
buf->offset = (dma->byte_count + offset); /* ******** */
|
||||
buf->address = (void *)(agp_offset + offset);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head( &buf->dma_wait );
|
||||
buf->pid = 0;
|
||||
|
||||
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
|
||||
buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
|
||||
DRM_MEM_BUFS );
|
||||
memset( buf->dev_private, 0, buf->dev_priv_size );
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
DRM_DEBUG( "buffer %d @ %p\n",
|
||||
entry->buf_count, buf->address );
|
||||
|
||||
offset += alignment;
|
||||
entry->buf_count++;
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "byte_count: %d\n", byte_count );
|
||||
|
||||
dma->buflist = DRM(realloc)( dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
dma->buflist[i + dma->buf_count] = &entry->buflist[i];
|
||||
}
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
dma->byte_count += byte_count;
|
||||
|
||||
DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
|
||||
DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
|
||||
|
||||
#if 0
|
||||
/* FIXME: work this mess out...
|
||||
*/
|
||||
DRM(freelist_create)( &entry->freelist, entry->buf_count );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
|
||||
}
|
||||
#endif
|
||||
|
||||
up( &dev->struct_sem );
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
dma->flags = _DRM_DMA_USE_AGP;
|
||||
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return 0;
|
||||
}
|
||||
#endif /* __REALLY_HAVE_AGP */
|
||||
|
||||
#if __HAVE_PCI_DMA
|
||||
int DRM(addbufs_pci)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int total;
|
||||
int page_order;
|
||||
drm_buf_entry_t *entry;
|
||||
unsigned long page;
|
||||
drm_buf_t *buf;
|
||||
int alignment;
|
||||
unsigned long offset;
|
||||
int i;
|
||||
int byte_count;
|
||||
int page_count;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = DRM(order)( request.size );
|
||||
size = 1 << order;
|
||||
|
||||
DRM_DEBUG( "count=%d, size=%d (%d), order=%d, queue_count=%d\n",
|
||||
request.count, request.size, size,
|
||||
order, dev->queue_count );
|
||||
|
||||
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
|
||||
if ( dev->queue_count ) return -EBUSY; /* Not while in use */
|
||||
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN)
|
||||
? PAGE_ALIGN(size) : size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( dev->buf_use ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc( &dev->buf_alloc );
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
down( &dev->struct_sem );
|
||||
entry = &dma->bufs[order];
|
||||
if ( entry->buf_count ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
if ( !entry->buflist ) {
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
|
||||
|
||||
entry->seglist = DRM(alloc)( count * sizeof(*entry->seglist),
|
||||
DRM_MEM_SEGS );
|
||||
if ( !entry->seglist ) {
|
||||
DRM(free)( entry->buflist,
|
||||
count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
up( &dev->struct_sem );
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( entry->seglist, 0, count * sizeof(*entry->seglist) );
|
||||
|
||||
dma->pagelist = DRM(realloc)( dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
(dma->page_count + (count << page_order))
|
||||
* sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES );
|
||||
DRM_DEBUG( "pagelist: %d entries\n",
|
||||
dma->page_count + (count << page_order) );
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
byte_count = 0;
|
||||
page_count = 0;
|
||||
|
||||
while ( entry->buf_count < count ) {
|
||||
page = DRM(alloc_pages)( page_order, DRM_MEM_DMA );
|
||||
if ( !page ) break;
|
||||
entry->seglist[entry->seg_count++] = page;
|
||||
for ( i = 0 ; i < (1 << page_order) ; i++ ) {
|
||||
DRM_DEBUG( "page %d @ 0x%08lx\n",
|
||||
dma->page_count + page_count,
|
||||
page + PAGE_SIZE * i );
|
||||
dma->pagelist[dma->page_count + page_count++]
|
||||
= page + PAGE_SIZE * i;
|
||||
}
|
||||
for ( offset = 0 ;
|
||||
offset + size <= total && entry->buf_count < count ;
|
||||
offset += alignment, ++entry->buf_count ) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
buf->offset = (dma->byte_count + byte_count + offset);
|
||||
buf->address = (void *)(page + offset);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head( &buf->dma_wait );
|
||||
buf->pid = 0;
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
DRM_DEBUG( "buffer %d @ %p\n",
|
||||
entry->buf_count, buf->address );
|
||||
}
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
dma->buflist = DRM(realloc)( dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
dma->buflist[i + dma->buf_count] = &entry->buflist[i];
|
||||
}
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
dma->seg_count += entry->seg_count;
|
||||
dma->page_count += entry->seg_count << page_order;
|
||||
dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
|
||||
|
||||
#if 0
|
||||
/* FIXME: work this mess out...
|
||||
*/
|
||||
DRM(freelist_create)( &entry->freelist, entry->buf_count );
|
||||
for ( i = 0 ; i < entry->buf_count ; i++ ) {
|
||||
DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
|
||||
}
|
||||
#endif
|
||||
|
||||
up( &dev->struct_sem );
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
atomic_dec( &dev->buf_alloc );
|
||||
return 0;
|
||||
}
|
||||
#endif /* __HAVE_PCI_DMA */
|
||||
|
||||
int DRM(addbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_buf_desc_t request;
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
if ( request.flags & _DRM_AGP_BUFFER )
|
||||
return DRM(addbufs_agp)( inode, filp, cmd, arg );
|
||||
else
|
||||
#endif
|
||||
#if __HAVE_PCI_DMA
|
||||
return DRM(addbufs_pci)( inode, filp, cmd, arg );
|
||||
#else
|
||||
return -EINVAL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int DRM(infobufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_info_t request;
|
||||
int i;
|
||||
int count;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( atomic_read( &dev->buf_alloc ) ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
++dev->buf_use; /* Can't allocate more after this call */
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_buf_info_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
|
||||
if ( dma->bufs[i].buf_count ) ++count;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "count = %d\n", count );
|
||||
|
||||
if ( request.count >= count ) {
|
||||
for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
|
||||
if ( dma->bufs[i].buf_count ) {
|
||||
drm_buf_desc_t *to = &request.list[count];
|
||||
drm_buf_entry_t *from = &dma->bufs[i];
|
||||
drm_freelist_t *list = &dma->bufs[i].freelist;
|
||||
if ( copy_to_user( &to->count,
|
||||
&from->buf_count,
|
||||
sizeof(from->buf_count) ) ||
|
||||
copy_to_user( &to->size,
|
||||
&from->buf_size,
|
||||
sizeof(from->buf_size) ) ||
|
||||
copy_to_user( &to->low_mark,
|
||||
&list->low_mark,
|
||||
sizeof(list->low_mark) ) ||
|
||||
copy_to_user( &to->high_mark,
|
||||
&list->high_mark,
|
||||
sizeof(list->high_mark) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d %d %d %d %d\n",
|
||||
i,
|
||||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].buf_size,
|
||||
dma->bufs[i].freelist.low_mark,
|
||||
dma->bufs[i].freelist.high_mark );
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
request.count = count;
|
||||
|
||||
if ( copy_to_user( (drm_buf_info_t *)arg,
|
||||
&request,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(markbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int order;
|
||||
drm_buf_entry_t *entry;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d, %d, %d\n",
|
||||
request.size, request.low_mark, request.high_mark );
|
||||
order = DRM(order)( request.size );
|
||||
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL;
|
||||
entry = &dma->bufs[order];
|
||||
|
||||
if ( request.low_mark < 0 || request.low_mark > entry->buf_count )
|
||||
return -EINVAL;
|
||||
if ( request.high_mark < 0 || request.high_mark > entry->buf_count )
|
||||
return -EINVAL;
|
||||
|
||||
entry->freelist.low_mark = request.low_mark;
|
||||
entry->freelist.high_mark = request.high_mark;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(freebufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_free_t request;
|
||||
int i;
|
||||
int idx;
|
||||
drm_buf_t *buf;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
if ( copy_from_user( &request,
|
||||
(drm_buf_free_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", request.count );
|
||||
for ( i = 0 ; i < request.count ; i++ ) {
|
||||
if ( copy_from_user( &idx,
|
||||
&request.list[i],
|
||||
sizeof(idx) ) )
|
||||
return -EFAULT;
|
||||
if ( idx < 0 || idx >= dma->buf_count ) {
|
||||
DRM_ERROR( "Index %d (of %d max)\n",
|
||||
idx, dma->buf_count - 1 );
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = dma->buflist[idx];
|
||||
if ( buf->pid != current->pid ) {
|
||||
DRM_ERROR( "Process %d freeing buffer owned by %d\n",
|
||||
current->pid, buf->pid );
|
||||
return -EINVAL;
|
||||
}
|
||||
DRM(free_buffer)( dev, buf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(mapbufs)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int retcode = 0;
|
||||
const int zero = 0;
|
||||
unsigned long virtual;
|
||||
unsigned long address;
|
||||
drm_buf_map_t request;
|
||||
int i;
|
||||
|
||||
if ( !dma ) return -EINVAL;
|
||||
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( atomic_read( &dev->buf_alloc ) ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return -EBUSY;
|
||||
}
|
||||
dev->buf_use++; /* Can't allocate more after this call */
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
if ( copy_from_user( &request, (drm_buf_map_t *)arg,
|
||||
sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( request.count >= dma->buf_count ) {
|
||||
if ( __HAVE_AGP && (dma->flags & _DRM_DMA_USE_AGP) ) {
|
||||
DRIVER_DEV_PRIV_T *dev_priv = dev->dev_private;
|
||||
drm_map_t *map;
|
||||
|
||||
map = DRIVER_AGP_BUFFER_MAP;
|
||||
if ( !map ) {
|
||||
retcode = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
down( ¤t->mm->mmap_sem );
|
||||
virtual = do_mmap( filp, 0, map->size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
(unsigned long)map->offset );
|
||||
up( ¤t->mm->mmap_sem );
|
||||
} else {
|
||||
down( ¤t->mm->mmap_sem );
|
||||
virtual = do_mmap( filp, 0, dma->byte_count,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, 0 );
|
||||
up( ¤t->mm->mmap_sem );
|
||||
}
|
||||
if ( virtual > -1024UL ) {
|
||||
/* Real error */
|
||||
retcode = (signed long)virtual;
|
||||
goto done;
|
||||
}
|
||||
request.virtual = (void *)virtual;
|
||||
|
||||
for ( i = 0 ; i < dma->buf_count ; i++ ) {
|
||||
if ( copy_to_user( &request.list[i].idx,
|
||||
&dma->buflist[i]->idx,
|
||||
sizeof(request.list[0].idx) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if ( copy_to_user( &request.list[i].total,
|
||||
&dma->buflist[i]->total,
|
||||
sizeof(request.list[0].total) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if ( copy_to_user( &request.list[i].used,
|
||||
&zero,
|
||||
sizeof(zero) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
address = virtual + dma->buflist[i]->offset; /* *** */
|
||||
if ( copy_to_user( &request.list[i].address,
|
||||
&address,
|
||||
sizeof(address) ) ) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
request.count = dma->buf_count;
|
||||
DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode );
|
||||
|
||||
if ( copy_to_user( (drm_buf_map_t *)arg, &request, sizeof(request) ) )
|
||||
return -EFAULT;
|
||||
|
||||
return retcode;
|
||||
}
|
||||
272
linux/drm_context.h
Normal file
272
linux/drm_context.h
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
/* drm_context.h -- IOCTLs for generic contexts -*- linux-c -*-
|
||||
* Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
/* ================================================================
|
||||
* Context bitmap support
|
||||
*/
|
||||
|
||||
void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle )
|
||||
{
|
||||
if ( ctx_handle < 0 ) goto failed;
|
||||
|
||||
if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
|
||||
clear_bit( ctx_handle, dev->ctx_bitmap );
|
||||
return;
|
||||
}
|
||||
failed:
|
||||
DRM_ERROR( "Attempt to free invalid context handle: %d\n",
|
||||
ctx_handle );
|
||||
return;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_next)( drm_device_t *dev )
|
||||
{
|
||||
int bit;
|
||||
|
||||
bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
|
||||
if ( bit < DRM_MAX_CTXBITMAP ) {
|
||||
set_bit( bit, dev->ctx_bitmap );
|
||||
DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
|
||||
return bit;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int DRM(ctxbitmap_init)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
int temp;
|
||||
|
||||
dev->ctx_bitmap = (unsigned long *) DRM(alloc)( PAGE_SIZE,
|
||||
DRM_MEM_CTXBITMAP );
|
||||
if ( dev->ctx_bitmap == NULL ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
temp = DRM(ctxbitmap_next)( dev );
|
||||
DRM_DEBUG( "drm_ctxbitmap_init : %d\n", temp );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(ctxbitmap_cleanup)( drm_device_t *dev )
|
||||
{
|
||||
DRM(free)( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
|
||||
}
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* The actual DRM context handling routines
|
||||
*/
|
||||
|
||||
int DRM(context_switch)( drm_device_t *dev, int old, int new )
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
atomic_inc( &dev->total_ctx );
|
||||
|
||||
if ( test_and_set_bit( 0, &dev->context_flag ) ) {
|
||||
DRM_ERROR( "Reentering -- FIXME\n" );
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG( "Context switch from %d to %d\n", old, new );
|
||||
|
||||
if ( new == dev->last_context ) {
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( DRM(flags) & DRM_FLAG_NOCTX ) {
|
||||
DRM(context_switch_complete)( dev, new );
|
||||
} else {
|
||||
sprintf( buf, "C %d %d\n", old, new );
|
||||
DRM(write_string)( dev, buf );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(context_switch_complete)( drm_device_t *dev, int new )
|
||||
{
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) ) {
|
||||
DRM_ERROR( "Lock isn't held after context switch\n" );
|
||||
}
|
||||
|
||||
/* If a context switch is ever initiated
|
||||
when the kernel holds the lock, release
|
||||
that lock here. */
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc( &dev->histo.ctx[DRM(histogram_slot)(get_cycles()
|
||||
- dev->ctx_start)] );
|
||||
|
||||
#endif
|
||||
clear_bit( 0, &dev->context_flag );
|
||||
wake_up( &dev->context_wait );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(resctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
if ( copy_from_user( &res, (drm_ctx_res_t *)arg, sizeof(res) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( res.count >= DRM_RESERVED_CONTEXTS ) {
|
||||
memset( &ctx, 0, sizeof(ctx) );
|
||||
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
|
||||
ctx.handle = i;
|
||||
if ( copy_to_user( &res.contexts[i],
|
||||
&i, sizeof(i) ) )
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
|
||||
if ( copy_to_user( (drm_ctx_res_t *)arg, &res, sizeof(res) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(addctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
if ( ctx.handle == DRM_KERNEL_CONTEXT ) {
|
||||
/* Skip kernel's context and get a new one. */
|
||||
ctx.handle = DRM(ctxbitmap_next)( dev );
|
||||
}
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle == -1 ) {
|
||||
DRM_DEBUG( "Not enough free contexts.\n" );
|
||||
/* Should this return -EBUSY instead? */
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if ( copy_to_user( (drm_ctx_t *)arg, &ctx, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(modctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
/* This does nothing */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t*)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
/* This is 0, because we don't handle any context flags */
|
||||
ctx.flags = 0;
|
||||
|
||||
if ( copy_to_user( (drm_ctx_t*)arg, &ctx, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(switchctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
return DRM(context_switch)( dev, dev->last_context, ctx.handle );
|
||||
}
|
||||
|
||||
int DRM(newctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
DRM(context_switch_complete)( dev, ctx.handle );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmctx)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) )
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG( "%d\n", ctx.handle );
|
||||
if ( ctx.handle == DRM_KERNEL_CONTEXT + 1 ) {
|
||||
priv->remove_auth_on_close = 1;
|
||||
}
|
||||
if ( ctx.handle != DRM_KERNEL_CONTEXT ) {
|
||||
DRM(ctxbitmap_free)( dev, ctx.handle );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
568
linux/drm_dma.h
Normal file
568
linux/drm_dma.h
Normal file
|
|
@ -0,0 +1,568 @@
|
|||
/* drm_dma.c -- DMA IOCTL and function support -*- linux-c -*-
|
||||
* Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#include <linux/interrupt.h> /* For task queue support */
|
||||
|
||||
#ifndef __HAVE_DMA_WAITQUEUE
|
||||
#define __HAVE_DMA_WAITQUEUE 0
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA
|
||||
|
||||
int DRM(dma_setup)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER );
|
||||
if ( !dev->dma )
|
||||
return -ENOMEM;
|
||||
|
||||
memset( dev->dma, 0, sizeof(*dev->dma) );
|
||||
|
||||
for ( i = 0 ; i <= DRM_MAX_ORDER ; i++ )
|
||||
memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DRM(dma_takedown)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i, j;
|
||||
|
||||
if (!dma) return;
|
||||
|
||||
/* Clear dma buffers */
|
||||
for (i = 0; i <= DRM_MAX_ORDER; i++) {
|
||||
if (dma->bufs[i].seg_count) {
|
||||
DRM_DEBUG("order %d: buf_count = %d,"
|
||||
" seg_count = %d\n",
|
||||
i,
|
||||
dma->bufs[i].buf_count,
|
||||
dma->bufs[i].seg_count);
|
||||
for (j = 0; j < dma->bufs[i].seg_count; j++) {
|
||||
DRM(free_pages)(dma->bufs[i].seglist[j],
|
||||
dma->bufs[i].page_order,
|
||||
DRM_MEM_DMA);
|
||||
}
|
||||
DRM(free)(dma->bufs[i].seglist,
|
||||
dma->bufs[i].seg_count
|
||||
* sizeof(*dma->bufs[0].seglist),
|
||||
DRM_MEM_SEGS);
|
||||
}
|
||||
if(dma->bufs[i].buf_count) {
|
||||
for(j = 0; j < dma->bufs[i].buf_count; j++) {
|
||||
if(dma->bufs[i].buflist[j].dev_private) {
|
||||
DRM(free)(dma->bufs[i].buflist[j].dev_private,
|
||||
dma->bufs[i].buflist[j].dev_priv_size,
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
}
|
||||
DRM(free)(dma->bufs[i].buflist,
|
||||
dma->bufs[i].buf_count *
|
||||
sizeof(*dma->bufs[0].buflist),
|
||||
DRM_MEM_BUFS);
|
||||
#if __HAVE_DMA_FREELIST
|
||||
DRM(freelist_destroy)(&dma->bufs[i].freelist);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (dma->buflist) {
|
||||
DRM(free)(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
}
|
||||
|
||||
if (dma->pagelist) {
|
||||
DRM(free)(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
}
|
||||
DRM(free)(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
|
||||
dev->dma = NULL;
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
/* This is slow, but is useful for debugging. */
|
||||
int DRM(histogram_slot)(unsigned long count)
|
||||
{
|
||||
int value = DRM_DMA_HISTOGRAM_INITIAL;
|
||||
int slot;
|
||||
|
||||
for (slot = 0;
|
||||
slot < DRM_DMA_HISTOGRAM_SLOTS;
|
||||
++slot, value = DRM_DMA_HISTOGRAM_NEXT(value)) {
|
||||
if (count < value) return slot;
|
||||
}
|
||||
return DRM_DMA_HISTOGRAM_SLOTS - 1;
|
||||
}
|
||||
|
||||
void DRM(histogram_compute)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
cycles_t queued_to_dispatched;
|
||||
cycles_t dispatched_to_completed;
|
||||
cycles_t completed_to_freed;
|
||||
int q2d, d2c, c2f, q2c, q2f;
|
||||
|
||||
if (buf->time_queued) {
|
||||
queued_to_dispatched = (buf->time_dispatched
|
||||
- buf->time_queued);
|
||||
dispatched_to_completed = (buf->time_completed
|
||||
- buf->time_dispatched);
|
||||
completed_to_freed = (buf->time_freed
|
||||
- buf->time_completed);
|
||||
|
||||
q2d = DRM(histogram_slot)(queued_to_dispatched);
|
||||
d2c = DRM(histogram_slot)(dispatched_to_completed);
|
||||
c2f = DRM(histogram_slot)(completed_to_freed);
|
||||
|
||||
q2c = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed);
|
||||
q2f = DRM(histogram_slot)(queued_to_dispatched
|
||||
+ dispatched_to_completed
|
||||
+ completed_to_freed);
|
||||
|
||||
atomic_inc(&dev->histo.total);
|
||||
atomic_inc(&dev->histo.queued_to_dispatched[q2d]);
|
||||
atomic_inc(&dev->histo.dispatched_to_completed[d2c]);
|
||||
atomic_inc(&dev->histo.completed_to_freed[c2f]);
|
||||
|
||||
atomic_inc(&dev->histo.queued_to_completed[q2c]);
|
||||
atomic_inc(&dev->histo.queued_to_freed[q2f]);
|
||||
|
||||
}
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
|
||||
{
|
||||
if (!buf) return;
|
||||
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
buf->pid = 0;
|
||||
buf->used = 0;
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_completed = get_cycles();
|
||||
#endif
|
||||
|
||||
if ( __HAVE_DMA_WAITQUEUE && waitqueue_active(&buf->dma_wait)) {
|
||||
wake_up_interruptible(&buf->dma_wait);
|
||||
}
|
||||
#if __HAVE_DMA_FREELIST
|
||||
else {
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
/* If processes are waiting, the last one
|
||||
to wake will put the buffer on the free
|
||||
list. If no processes are waiting, we
|
||||
put the buffer on the freelist here. */
|
||||
DRM(freelist_put)(dev, &dma->bufs[buf->order].freelist, buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i;
|
||||
|
||||
if (!dma) return;
|
||||
for (i = 0; i < dma->buf_count; i++) {
|
||||
if (dma->buflist[i]->pid == pid) {
|
||||
switch (dma->buflist[i]->list) {
|
||||
case DRM_LIST_NONE:
|
||||
DRM(free_buffer)(dev, dma->buflist[i]);
|
||||
break;
|
||||
case DRM_LIST_WAIT:
|
||||
dma->buflist[i]->list = DRM_LIST_RECLAIM;
|
||||
break;
|
||||
default:
|
||||
/* Buffer already on hardware. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int drm_context_switch(drm_device_t *dev, int old, int new)
|
||||
{
|
||||
char buf[64];
|
||||
drm_queue_t *q;
|
||||
|
||||
atomic_inc(&dev->total_ctx);
|
||||
|
||||
if (test_and_set_bit(0, &dev->context_flag)) {
|
||||
DRM_ERROR("Reentering -- FIXME\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG("Context switch from %d to %d\n", old, new);
|
||||
|
||||
if (new >= dev->queue_count) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (new == dev->last_context) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
q = dev->queuelist[new];
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) == 1) {
|
||||
atomic_dec(&q->use_count);
|
||||
clear_bit(0, &dev->context_flag);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (drm_flags & DRM_FLAG_NOCTX) {
|
||||
drm_context_switch_complete(dev, new);
|
||||
} else {
|
||||
sprintf(buf, "C %d %d\n", old, new);
|
||||
drm_write_string(dev, buf);
|
||||
}
|
||||
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_context_switch_complete(drm_device_t *dev, int new)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
|
||||
DRM_ERROR("Lock isn't held after context switch\n");
|
||||
}
|
||||
|
||||
if (!dma || !(dma->next_buffer && dma->next_buffer->while_locked)) {
|
||||
if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) {
|
||||
DRM_ERROR("Cannot free lock\n");
|
||||
}
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.ctx[drm_histogram_slot(get_cycles()
|
||||
- dev->ctx_start)]);
|
||||
|
||||
#endif
|
||||
clear_bit(0, &dev->context_flag);
|
||||
wake_up_interruptible(&dev->context_wait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void DRM(clear_next_buffer)(drm_device_t *dev)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
dma->next_buffer = NULL;
|
||||
if (dma->next_queue && !DRM_BUFCOUNT(&dma->next_queue->waitlist)) {
|
||||
wake_up_interruptible(&dma->next_queue->flush_queue);
|
||||
}
|
||||
dma->next_queue = NULL;
|
||||
}
|
||||
|
||||
int DRM(select_queue)(drm_device_t *dev, void (*wrapper)(unsigned long))
|
||||
{
|
||||
int i;
|
||||
int candidate = -1;
|
||||
int j = jiffies;
|
||||
|
||||
if (!dev) {
|
||||
DRM_ERROR("No device\n");
|
||||
return -1;
|
||||
}
|
||||
if (!dev->queuelist || !dev->queuelist[DRM_KERNEL_CONTEXT]) {
|
||||
/* This only happens between the time the
|
||||
interrupt is initialized and the time
|
||||
the queues are initialized. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Doing "while locked" DMA? */
|
||||
if (DRM_WAITCOUNT(dev, DRM_KERNEL_CONTEXT)) {
|
||||
return DRM_KERNEL_CONTEXT;
|
||||
}
|
||||
|
||||
/* If there are buffers on the last_context
|
||||
queue, and we have not been executing
|
||||
this context very long, continue to
|
||||
execute this context. */
|
||||
if (dev->last_switch <= j
|
||||
&& dev->last_switch + DRM_TIME_SLICE > j
|
||||
&& DRM_WAITCOUNT(dev, dev->last_context)) {
|
||||
return dev->last_context;
|
||||
}
|
||||
|
||||
/* Otherwise, find a candidate */
|
||||
for (i = dev->last_checked + 1; i < dev->queue_count; i++) {
|
||||
if (DRM_WAITCOUNT(dev, i)) {
|
||||
candidate = dev->last_checked = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (candidate < 0) {
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
if (DRM_WAITCOUNT(dev, i)) {
|
||||
candidate = dev->last_checked = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wrapper
|
||||
&& candidate >= 0
|
||||
&& candidate != dev->last_context
|
||||
&& dev->last_switch <= j
|
||||
&& dev->last_switch + DRM_TIME_SLICE > j) {
|
||||
if (dev->timer.expires != dev->last_switch + DRM_TIME_SLICE) {
|
||||
del_timer(&dev->timer);
|
||||
dev->timer.function = wrapper;
|
||||
dev->timer.data = (unsigned long)dev;
|
||||
dev->timer.expires = dev->last_switch+DRM_TIME_SLICE;
|
||||
add_timer(&dev->timer);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return candidate;
|
||||
}
|
||||
|
||||
|
||||
int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
|
||||
{
|
||||
int i;
|
||||
drm_queue_t *q;
|
||||
drm_buf_t *buf;
|
||||
int idx;
|
||||
int while_locked = 0;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
DECLARE_WAITQUEUE(entry, current);
|
||||
|
||||
DRM_DEBUG("%d\n", d->send_count);
|
||||
|
||||
if (d->flags & _DRM_DMA_WHILE_LOCKED) {
|
||||
int context = dev->lock.hw_lock->lock;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(context)) {
|
||||
DRM_ERROR("No lock held during \"while locked\""
|
||||
" request\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (d->context != _DRM_LOCKING_CONTEXT(context)
|
||||
&& _DRM_LOCKING_CONTEXT(context) != DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("Lock held by %d while %d makes"
|
||||
" \"while locked\" request\n",
|
||||
_DRM_LOCKING_CONTEXT(context),
|
||||
d->context);
|
||||
return -EINVAL;
|
||||
}
|
||||
q = dev->queuelist[DRM_KERNEL_CONTEXT];
|
||||
while_locked = 1;
|
||||
} else {
|
||||
q = dev->queuelist[d->context];
|
||||
}
|
||||
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->block_write)) {
|
||||
add_wait_queue(&q->write_queue, &entry);
|
||||
atomic_inc(&q->block_count);
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if (!atomic_read(&q->block_write)) break;
|
||||
schedule();
|
||||
if (signal_pending(current)) {
|
||||
atomic_dec(&q->use_count);
|
||||
remove_wait_queue(&q->write_queue, &entry);
|
||||
return -EINTR;
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->block_count);
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue(&q->write_queue, &entry);
|
||||
}
|
||||
|
||||
for (i = 0; i < d->send_count; i++) {
|
||||
idx = d->send_indices[i];
|
||||
if (idx < 0 || idx >= dma->buf_count) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Index %d (of %d max)\n",
|
||||
d->send_indices[i], dma->buf_count - 1);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = dma->buflist[ idx ];
|
||||
if (buf->pid != current->pid) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Process %d using buffer owned by %d\n",
|
||||
current->pid, buf->pid);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (buf->list != DRM_LIST_NONE) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Process %d using buffer %d on list %d\n",
|
||||
current->pid, buf->idx, buf->list);
|
||||
}
|
||||
buf->used = d->send_sizes[i];
|
||||
buf->while_locked = while_locked;
|
||||
buf->context = d->context;
|
||||
if (!buf->used) {
|
||||
DRM_ERROR("Queueing 0 length buffer\n");
|
||||
}
|
||||
if (buf->pending) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Queueing pending buffer:"
|
||||
" buffer %d, offset %d\n",
|
||||
d->send_indices[i], i);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (buf->waiting) {
|
||||
atomic_dec(&q->use_count);
|
||||
DRM_ERROR("Queueing waiting buffer:"
|
||||
" buffer %d, offset %d\n",
|
||||
d->send_indices[i], i);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf->waiting = 1;
|
||||
if (atomic_read(&q->use_count) == 1
|
||||
|| atomic_read(&q->finalization)) {
|
||||
DRM(free_buffer)(dev, buf);
|
||||
} else {
|
||||
DRM(waitlist_put)(&q->waitlist, buf);
|
||||
atomic_inc(&q->total_queued);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d,
|
||||
int order)
|
||||
{
|
||||
int i;
|
||||
drm_buf_t *buf;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
for (i = d->granted_count; i < d->request_count; i++) {
|
||||
buf = DRM(freelist_get)(&dma->bufs[order].freelist,
|
||||
d->flags & _DRM_DMA_WAIT);
|
||||
if (!buf) break;
|
||||
if (buf->pending || buf->waiting) {
|
||||
DRM_ERROR("Free buffer %d in use by %d (w%d, p%d)\n",
|
||||
buf->idx,
|
||||
buf->pid,
|
||||
buf->waiting,
|
||||
buf->pending);
|
||||
}
|
||||
buf->pid = current->pid;
|
||||
if (copy_to_user(&d->request_indices[i],
|
||||
&buf->idx,
|
||||
sizeof(buf->idx)))
|
||||
return -EFAULT;
|
||||
|
||||
if (copy_to_user(&d->request_sizes[i],
|
||||
&buf->total,
|
||||
sizeof(buf->total)))
|
||||
return -EFAULT;
|
||||
|
||||
++d->granted_count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma)
|
||||
{
|
||||
int order;
|
||||
int retcode = 0;
|
||||
int tmp_order;
|
||||
|
||||
order = DRM(order)(dma->request_size);
|
||||
|
||||
dma->granted_count = 0;
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma, order);
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_SMALLER_OK)) {
|
||||
for (tmp_order = order - 1;
|
||||
!retcode
|
||||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order >= DRM_MIN_ORDER;
|
||||
--tmp_order) {
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
|
||||
if (dma->granted_count < dma->request_count
|
||||
&& (dma->flags & _DRM_DMA_LARGER_OK)) {
|
||||
for (tmp_order = order + 1;
|
||||
!retcode
|
||||
&& dma->granted_count < dma->request_count
|
||||
&& tmp_order <= DRM_MAX_ORDER;
|
||||
++tmp_order) {
|
||||
|
||||
retcode = DRM(dma_get_buffers_of_order)(dev, dma,
|
||||
tmp_order);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
51
linux/drm_drawable.h
Normal file
51
linux/drm_drawable.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* drm_drawable.h -- IOCTLs for drawables -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(adddraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_draw_t draw;
|
||||
|
||||
draw.handle = 0; /* NOOP */
|
||||
DRM_DEBUG("%d\n", draw.handle);
|
||||
if (copy_to_user((drm_draw_t *)arg, &draw, sizeof(draw)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(rmdraw)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
return 0; /* NOOP */
|
||||
}
|
||||
842
linux/drm_drv.h
Normal file
842
linux/drm_drv.h
Normal file
|
|
@ -0,0 +1,842 @@
|
|||
/* drm_drv.h -- Generic driver template -*- linux-c -*-
|
||||
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
||||
*
|
||||
* Copyright 1999, 2000 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
* To use this template, you must at least define the following (samples
|
||||
* given for the MGA driver):
|
||||
*
|
||||
* #define DRIVER_AUTHOR "VA Linux Systems, Inc."
|
||||
*
|
||||
* #define DRIVER_NAME "mga"
|
||||
* #define DRIVER_DESC "Matrox G200/G400"
|
||||
* #define DRIVER_DATE "20001127"
|
||||
*
|
||||
* #define DRIVER_MAJOR 2
|
||||
* #define DRIVER_MINOR 0
|
||||
* #define DRIVER_PATCHLEVEL 2
|
||||
*
|
||||
* #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( mga_ioctls )
|
||||
*
|
||||
* #define DRM(x) mga_##x
|
||||
*/
|
||||
|
||||
#ifndef __MUST_HAVE_AGP
|
||||
#define __MUST_HAVE_AGP 0
|
||||
#endif
|
||||
#ifndef __HAVE_CTX_BITMAP
|
||||
#define __HAVE_CTX_BITMAP 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_IRQ
|
||||
#define __HAVE_DMA_IRQ 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_QUEUE
|
||||
#define __HAVE_DMA_QUEUE 0
|
||||
#endif
|
||||
#ifndef __HAVE_MULTIPLE_DMA_QUEUES
|
||||
#define __HAVE_MULTIPLE_DMA_QUEUES 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_SCHEDULE
|
||||
#define __HAVE_DMA_SCHEDULE 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_FLUSH
|
||||
#define __HAVE_DMA_FLUSH 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_READY
|
||||
#define __HAVE_DMA_READY 0
|
||||
#endif
|
||||
#ifndef __HAVE_DMA_QUIESCENT
|
||||
#define __HAVE_DMA_QUIESCENT 0
|
||||
#endif
|
||||
#ifndef __HAVE_DRIVER_RELEASE
|
||||
#define __HAVE_DRIVER_RELEASE 0
|
||||
#endif
|
||||
|
||||
#ifndef DRIVER_PREINIT
|
||||
#define DRIVER_PREINIT()
|
||||
#endif
|
||||
#ifndef DRIVER_POSTINIT
|
||||
#define DRIVER_POSTINIT()
|
||||
#endif
|
||||
#ifndef DRIVER_PRETAKEDOWN
|
||||
#define DRIVER_PRETAKEDOWN()
|
||||
#endif
|
||||
|
||||
|
||||
static drm_device_t DRM(device);
|
||||
|
||||
static struct file_operations DRM(fops) = {
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
/* This started being used during 2.4.0-test */
|
||||
owner: THIS_MODULE,
|
||||
#endif
|
||||
open: DRM(open),
|
||||
flush: DRM(flush),
|
||||
release: DRM(release),
|
||||
ioctl: DRM(ioctl),
|
||||
mmap: DRM(mmap),
|
||||
read: DRM(read),
|
||||
fasync: DRM(fasync),
|
||||
poll: DRM(poll),
|
||||
};
|
||||
|
||||
static struct miscdevice DRM(misc) = {
|
||||
minor: MISC_DYNAMIC_MINOR,
|
||||
name: DRIVER_NAME,
|
||||
fops: &DRM(fops),
|
||||
};
|
||||
|
||||
#ifdef MODULE
|
||||
static char *drm_opts = NULL;
|
||||
#endif
|
||||
|
||||
MODULE_AUTHOR( DRIVER_AUTHOR );
|
||||
MODULE_DESCRIPTION( DRIVER_DESC );
|
||||
MODULE_PARM( drm_opts, "s" );
|
||||
|
||||
#ifndef MODULE
|
||||
/* DRM(options) is called by the kernel to parse command-line options
|
||||
* passed via the boot-loader (e.g., LILO). It calls the insmod option
|
||||
* routine, drm_parse_drm.
|
||||
*/
|
||||
|
||||
static int __init DRM(options)( char *str )
|
||||
{
|
||||
DRM(parse_options)( str );
|
||||
return 1;
|
||||
}
|
||||
|
||||
__setup( DRIVER_NAME "=", DRM(options) );
|
||||
#endif
|
||||
|
||||
static int DRM(setup)( drm_device_t *dev )
|
||||
{
|
||||
int i;
|
||||
|
||||
atomic_set( &dev->ioctl_count, 0 );
|
||||
atomic_set( &dev->vma_count, 0 );
|
||||
dev->buf_use = 0;
|
||||
atomic_set( &dev->buf_alloc, 0 );
|
||||
|
||||
#if __HAVE_DMA
|
||||
i = DRM(dma_setup)( dev );
|
||||
if ( i < 0 )
|
||||
return i;
|
||||
#endif
|
||||
|
||||
atomic_set( &dev->total_open, 0 );
|
||||
atomic_set( &dev->total_close, 0 );
|
||||
atomic_set( &dev->total_ioctl, 0 );
|
||||
atomic_set( &dev->total_irq, 0 );
|
||||
atomic_set( &dev->total_ctx, 0 );
|
||||
atomic_set( &dev->total_locks, 0 );
|
||||
atomic_set( &dev->total_unlocks, 0 );
|
||||
atomic_set( &dev->total_contends, 0 );
|
||||
atomic_set( &dev->total_sleeps, 0 );
|
||||
|
||||
for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
|
||||
dev->magiclist[i].head = NULL;
|
||||
dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
dev->vmalist = NULL;
|
||||
dev->lock.hw_lock = NULL;
|
||||
init_waitqueue_head( &dev->lock.lock_queue );
|
||||
dev->queue_count = 0;
|
||||
dev->queue_reserved = 0;
|
||||
dev->queue_slots = 0;
|
||||
dev->queuelist = NULL;
|
||||
dev->irq = 0;
|
||||
dev->context_flag = 0;
|
||||
dev->interrupt_flag = 0;
|
||||
dev->dma_flag = 0;
|
||||
dev->last_context = 0;
|
||||
dev->last_switch = 0;
|
||||
dev->last_checked = 0;
|
||||
init_timer( &dev->timer );
|
||||
init_waitqueue_head( &dev->context_wait );
|
||||
|
||||
dev->ctx_start = 0;
|
||||
dev->lck_start = 0;
|
||||
|
||||
dev->buf_rp = dev->buf;
|
||||
dev->buf_wp = dev->buf;
|
||||
dev->buf_end = dev->buf + DRM_BSZ;
|
||||
dev->buf_async = NULL;
|
||||
init_waitqueue_head( &dev->buf_readers );
|
||||
init_waitqueue_head( &dev->buf_writers );
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
/* The kernel's context could be created here, but is now created
|
||||
* in drm_dma_enqueue. This is more resource-efficient for
|
||||
* hardware that does not do DMA, but may mean that
|
||||
* drm_select_queue fails between the time the interrupt is
|
||||
* initialized and the time the queues are initialized.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int DRM(takedown)( drm_device_t *dev )
|
||||
{
|
||||
drm_magic_entry_t *pt, *next;
|
||||
drm_map_t *map;
|
||||
drm_vma_entry_t *vma, *vma_next;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
DRIVER_PRETAKEDOWN();
|
||||
#if __HAVE_DMA_IRQ
|
||||
if ( dev->irq ) DRM(irq_uninstall)( dev );
|
||||
#endif
|
||||
|
||||
down( &dev->struct_sem );
|
||||
del_timer( &dev->timer );
|
||||
|
||||
if ( dev->devname ) {
|
||||
DRM(free)( dev->devname, strlen( dev->devname ) + 1,
|
||||
DRM_MEM_DRIVER );
|
||||
dev->devname = NULL;
|
||||
}
|
||||
|
||||
if ( dev->unique ) {
|
||||
DRM(free)( dev->unique, strlen( dev->unique ) + 1,
|
||||
DRM_MEM_DRIVER );
|
||||
dev->unique = NULL;
|
||||
dev->unique_len = 0;
|
||||
}
|
||||
/* Clear pid list */
|
||||
for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
|
||||
for ( pt = dev->magiclist[i].head ; pt ; pt = next ) {
|
||||
next = pt->next;
|
||||
DRM(free)( pt, sizeof(*pt), DRM_MEM_MAGIC );
|
||||
}
|
||||
dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
/* Clear AGP information */
|
||||
if ( dev->agp ) {
|
||||
drm_agp_mem_t *entry;
|
||||
drm_agp_mem_t *nexte;
|
||||
|
||||
/* Remove AGP resources, but leave dev->agp
|
||||
intact until drv_cleanup is called. */
|
||||
for ( entry = dev->agp->memory ; entry ; entry = nexte ) {
|
||||
nexte = entry->next;
|
||||
if ( entry->bound ) DRM(unbind_agp)( entry->memory );
|
||||
DRM(free_agp)( entry->memory, entry->pages );
|
||||
DRM(free)( entry, sizeof(*entry), DRM_MEM_AGPLISTS );
|
||||
}
|
||||
dev->agp->memory = NULL;
|
||||
|
||||
if ( dev->agp->acquired ) DRM(agp_do_release)();
|
||||
|
||||
dev->agp->acquired = 0;
|
||||
dev->agp->enabled = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clear vma list (only built for debugging) */
|
||||
if ( dev->vmalist ) {
|
||||
for ( vma = dev->vmalist ; vma ; vma = vma_next ) {
|
||||
vma_next = vma->next;
|
||||
DRM(free)( vma, sizeof(*vma), DRM_MEM_VMAS );
|
||||
}
|
||||
dev->vmalist = NULL;
|
||||
}
|
||||
|
||||
/* Clear map area and mtrr information */
|
||||
if ( dev->maplist ) {
|
||||
for ( i = 0 ; i < dev->map_count ; i++ ) {
|
||||
map = dev->maplist[i];
|
||||
switch ( map->type ) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#if __REALLY_HAVE_MTRR
|
||||
if ( map->mtrr >= 0 ) {
|
||||
int retcode;
|
||||
retcode = mtrr_del( map->mtrr,
|
||||
map->offset,
|
||||
map->size );
|
||||
DRM_DEBUG( "mtrr_del=%d\n", retcode );
|
||||
}
|
||||
#endif
|
||||
DRM(ioremapfree)( map->handle, map->size );
|
||||
break;
|
||||
case _DRM_SHM:
|
||||
DRM(free_pages)( (unsigned long)map->handle,
|
||||
DRM(order)( map->size )
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA );
|
||||
break;
|
||||
case _DRM_AGP:
|
||||
/* Do nothing here, because this is all
|
||||
* handled in the AGP/GART driver.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
|
||||
}
|
||||
DRM(free)( dev->maplist,
|
||||
dev->map_count * sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS );
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
}
|
||||
|
||||
#if HAVE_DMA_QUEUE || HAVE_MULTIPLE_DMA_QUEUES
|
||||
if ( dev->queuelist ) {
|
||||
for ( i = 0 ; i < dev->queue_count ; i++ ) {
|
||||
DRM(waitlist_destroy)( &dev->queuelist[i]->waitlist );
|
||||
if ( dev->queuelist[i] ) {
|
||||
DRM(free)( dev->queuelist[i],
|
||||
sizeof(*dev->queuelist[0]),
|
||||
DRM_MEM_QUEUES );
|
||||
dev->queuelist[i] = NULL;
|
||||
}
|
||||
}
|
||||
DRM(free)( dev->queuelist,
|
||||
dev->queue_slots * sizeof(*dev->queuelist),
|
||||
DRM_MEM_QUEUES );
|
||||
dev->queuelist = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA
|
||||
DRM(dma_takedown)( dev );
|
||||
#endif
|
||||
|
||||
dev->queue_count = 0;
|
||||
if ( dev->lock.hw_lock ) {
|
||||
dev->lock.hw_lock = NULL; /* SHM removed */
|
||||
dev->lock.pid = 0;
|
||||
wake_up_interruptible( &dev->lock.lock_queue );
|
||||
}
|
||||
up( &dev->struct_sem );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* drm_init is called via init_module at module load time, or via
|
||||
* linux/init/main.c (this is not currently supported).
|
||||
*/
|
||||
static int __init drm_init( void )
|
||||
{
|
||||
int retcode;
|
||||
drm_device_t *dev = &DRM(device);
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
memset( (void *)dev, 0, sizeof(*dev) );
|
||||
dev->count_lock = SPIN_LOCK_UNLOCKED;
|
||||
sema_init( &dev->struct_sem, 1 );
|
||||
|
||||
#ifdef MODULE
|
||||
DRM(parse_options)( drm_opts );
|
||||
#endif
|
||||
DRIVER_PREINIT();
|
||||
|
||||
retcode = misc_register( &DRM(misc) );
|
||||
if ( retcode ) {
|
||||
DRM_ERROR( "Cannot register \"%s\"\n", DRIVER_NAME );
|
||||
return retcode;
|
||||
}
|
||||
dev->device = MKDEV( MISC_MAJOR, DRM(misc).minor );
|
||||
dev->name = DRIVER_NAME;
|
||||
|
||||
DRM(mem_init)();
|
||||
DRM(proc_init)( dev );
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
dev->agp = DRM(agp_init)();
|
||||
#if __MUST_HAVE_AGP
|
||||
if ( dev->agp == NULL ) {
|
||||
DRM_ERROR( "Cannot initialize the agpgart module.\n" );
|
||||
DRM(proc_cleanup)();
|
||||
misc_deregister( &DRM(misc) );
|
||||
DRM(takedown)( dev );
|
||||
return -ENOMEM;
|
||||
}
|
||||
#endif
|
||||
#if __REALLY_HAVE_MTRR
|
||||
dev->agp->agp_mtrr = mtrr_add( dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size*1024*1024,
|
||||
MTRR_TYPE_WRCOMB,
|
||||
1 );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __HAVE_CTX_BITMAP
|
||||
retcode = DRM(ctxbitmap_init)( dev );
|
||||
if( retcode ) {
|
||||
DRM_ERROR( "Cannot allocate memory for context bitmap.\n" );
|
||||
DRM(proc_cleanup)();
|
||||
misc_deregister( &DRM(misc) );
|
||||
DRM(takedown)( dev );
|
||||
return retcode;
|
||||
}
|
||||
#endif
|
||||
|
||||
DRIVER_POSTINIT();
|
||||
|
||||
DRM_INFO( "Initialized %s %d.%d.%d %s on minor %d\n",
|
||||
DRIVER_NAME,
|
||||
DRIVER_MAJOR,
|
||||
DRIVER_MINOR,
|
||||
DRIVER_PATCHLEVEL,
|
||||
DRIVER_DATE,
|
||||
DRM(misc).minor );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* drm_cleanup is called via cleanup_module at module unload time.
|
||||
*/
|
||||
static void __exit drm_cleanup( void )
|
||||
{
|
||||
drm_device_t *dev = &DRM(device);
|
||||
|
||||
DRM_DEBUG( "\n" );
|
||||
|
||||
DRM(proc_cleanup)();
|
||||
if ( misc_deregister( &DRM(misc) ) ) {
|
||||
DRM_ERROR( "Cannot unload module\n" );
|
||||
} else {
|
||||
DRM_INFO( "Module unloaded\n" );
|
||||
}
|
||||
#if __HAVE_CTX_BITMAP
|
||||
DRM(ctxbitmap_cleanup)( dev );
|
||||
#endif
|
||||
|
||||
#if __REALLY_HAVE_MTRR
|
||||
if ( dev->agp && dev->agp->agp_mtrr ) {
|
||||
int retval;
|
||||
retval = mtrr_del( dev->agp->agp_mtrr,
|
||||
dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size*1024*1024 );
|
||||
DRM_DEBUG( "mtrr_del=%d\n", retval );
|
||||
}
|
||||
#endif
|
||||
|
||||
DRM(takedown)( dev );
|
||||
|
||||
#if __REALLY_HAVE_AGP
|
||||
if ( dev->agp ) {
|
||||
DRM(agp_uninit)();
|
||||
DRM(free)( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS );
|
||||
dev->agp = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
module_init( drm_init );
|
||||
module_exit( drm_cleanup );
|
||||
|
||||
|
||||
int DRM(version)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_version_t version;
|
||||
int len;
|
||||
|
||||
if ( copy_from_user( &version,
|
||||
(drm_version_t *)arg,
|
||||
sizeof(version) ) )
|
||||
return -EFAULT;
|
||||
|
||||
#define DRM_COPY( name, value ) \
|
||||
len = strlen( value ); \
|
||||
if ( len > name##_len ) len = name##_len; \
|
||||
name##_len = strlen( value ); \
|
||||
if ( len && name ) { \
|
||||
if ( copy_to_user( name, value, len ) ) \
|
||||
return -EFAULT; \
|
||||
}
|
||||
|
||||
version.version_major = DRIVER_MAJOR;
|
||||
version.version_minor = DRIVER_MINOR;
|
||||
version.version_patchlevel = DRIVER_PATCHLEVEL;
|
||||
|
||||
DRM_COPY( version.name, DRIVER_NAME );
|
||||
DRM_COPY( version.date, DRIVER_DATE );
|
||||
DRM_COPY( version.desc, DRIVER_DESC );
|
||||
|
||||
if ( copy_to_user( (drm_version_t *)arg,
|
||||
&version,
|
||||
sizeof(version) ) )
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(open)( struct inode *inode, struct file *filp )
|
||||
{
|
||||
drm_device_t *dev = &DRM(device);
|
||||
int retcode = 0;
|
||||
|
||||
DRM_DEBUG( "open_count = %d\n", dev->open_count );
|
||||
|
||||
retcode = DRM(open_helper)( inode, filp, dev );
|
||||
if ( !retcode ) {
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_inc( &dev->total_open );
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( !dev->open_count++ ) {
|
||||
spin_unlock( &dev->count_lock );
|
||||
return DRM(setup)( dev );
|
||||
}
|
||||
spin_unlock( &dev->count_lock );
|
||||
}
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int DRM(release)( struct inode *inode, struct file *filp )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev;
|
||||
int retcode = 0;
|
||||
|
||||
lock_kernel();
|
||||
dev = priv->dev;
|
||||
|
||||
DRM_DEBUG( "open_count = %d\n", dev->open_count );
|
||||
|
||||
/* ========================================================
|
||||
* Begin inline drm_release
|
||||
*/
|
||||
|
||||
DRM_DEBUG( "pid = %d, device = 0x%x, open_count = %d\n",
|
||||
current->pid, dev->device, dev->open_count );
|
||||
|
||||
if ( dev->lock.hw_lock &&
|
||||
_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
|
||||
dev->lock.pid == current->pid ) {
|
||||
DRM_ERROR( "Process %d dead, freeing lock for context %d\n",
|
||||
current->pid,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
|
||||
#if __HAVE_DRIVER_RELEASE
|
||||
DRIVER_RELEASE();
|
||||
#endif
|
||||
DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock) );
|
||||
|
||||
/* FIXME: may require heavy-handed reset of
|
||||
hardware at this point, possibly
|
||||
processed via a callback to the X
|
||||
server. */
|
||||
}
|
||||
#if __HAVE_DRIVER_RELEASE
|
||||
else if ( dev->lock.hw_lock ) {
|
||||
/* The lock is required to reclaim buffers */
|
||||
DECLARE_WAITQUEUE( entry, current );
|
||||
add_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if ( !dev->lock.hw_lock ) {
|
||||
/* Device has been unregistered */
|
||||
retcode = -EINTR;
|
||||
break;
|
||||
}
|
||||
if ( DRM(lock_take)( &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT ) ) {
|
||||
dev->lock.pid = priv->pid;
|
||||
dev->lock.lock_time = jiffies;
|
||||
atomic_inc( &dev->total_locks );
|
||||
break; /* Got lock */
|
||||
}
|
||||
/* Contention */
|
||||
atomic_inc( &dev->total_sleeps );
|
||||
schedule();
|
||||
if ( signal_pending( current ) ) {
|
||||
retcode = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
if( !retcode ) {
|
||||
DRIVER_RELEASE();
|
||||
DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT );
|
||||
}
|
||||
}
|
||||
#else
|
||||
DRM(reclaim_buffers)( dev, priv->pid );
|
||||
#endif
|
||||
|
||||
DRM(fasync)( -1, filp, 0 );
|
||||
|
||||
down( &dev->struct_sem );
|
||||
if ( priv->remove_auth_on_close == 1 ) {
|
||||
drm_file_t *temp = dev->file_first;
|
||||
while ( temp ) {
|
||||
temp->authenticated = 0;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
if ( priv->prev ) {
|
||||
priv->prev->next = priv->next;
|
||||
} else {
|
||||
dev->file_first = priv->next;
|
||||
}
|
||||
if ( priv->next ) {
|
||||
priv->next->prev = priv->prev;
|
||||
} else {
|
||||
dev->file_last = priv->prev;
|
||||
}
|
||||
up( &dev->struct_sem );
|
||||
|
||||
DRM(free)( priv, sizeof(*priv), DRM_MEM_FILES );
|
||||
|
||||
/* ========================================================
|
||||
* End inline drm_release
|
||||
*/
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_DEC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_inc( &dev->total_close );
|
||||
spin_lock( &dev->count_lock );
|
||||
if ( !--dev->open_count ) {
|
||||
if ( atomic_read( &dev->ioctl_count ) || dev->blocked ) {
|
||||
DRM_ERROR( "Device busy: %d %d\n",
|
||||
atomic_read( &dev->ioctl_count ),
|
||||
dev->blocked );
|
||||
spin_unlock( &dev->count_lock );
|
||||
unlock_kernel();
|
||||
return -EBUSY;
|
||||
}
|
||||
spin_unlock( &dev->count_lock );
|
||||
unlock_kernel();
|
||||
return DRM(takedown)( dev );
|
||||
}
|
||||
spin_unlock( &dev->count_lock );
|
||||
|
||||
unlock_kernel();
|
||||
return retcode;
|
||||
}
|
||||
|
||||
/* DRM(ioctl) is called whenever a process performs an ioctl on /dev/drm.
|
||||
*/
|
||||
int DRM(ioctl)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ioctl_desc_t *ioctl;
|
||||
drm_ioctl_t *func;
|
||||
int nr = DRM_IOCTL_NR(cmd);
|
||||
int retcode = 0;
|
||||
|
||||
atomic_inc( &dev->ioctl_count );
|
||||
atomic_inc( &dev->total_ioctl );
|
||||
++priv->ioctl_count;
|
||||
|
||||
DRM_DEBUG( "pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%x, auth=%d\n",
|
||||
current->pid, cmd, nr, dev->device, priv->authenticated );
|
||||
|
||||
if ( nr >= DRIVER_IOCTL_COUNT ) {
|
||||
retcode = -EINVAL;
|
||||
} else {
|
||||
ioctl = &DRM(ioctls)[nr];
|
||||
func = ioctl->func;
|
||||
|
||||
if ( !func ) {
|
||||
DRM_DEBUG( "no function\n" );
|
||||
retcode = -EINVAL;
|
||||
} else if ( ( ioctl->root_only && !capable( CAP_SYS_ADMIN ) )||
|
||||
( ioctl->auth_needed && !priv->authenticated ) ) {
|
||||
retcode = -EACCES;
|
||||
} else {
|
||||
retcode = func( inode, filp, cmd, arg );
|
||||
}
|
||||
}
|
||||
|
||||
atomic_dec( &dev->ioctl_count );
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int DRM(lock)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
DECLARE_WAITQUEUE( entry, current );
|
||||
drm_lock_t lock;
|
||||
int ret = 0;
|
||||
#if __HAVE_MULTIPLE_DMA_QUEUES
|
||||
drm_queue_t *q;
|
||||
#endif
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
cycles_t start;
|
||||
|
||||
dev->lck_start = start = get_cycles();
|
||||
#endif
|
||||
|
||||
if ( copy_from_user( &lock, (drm_lock_t *)arg, sizeof(lock) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( lock.context == DRM_KERNEL_CONTEXT ) {
|
||||
DRM_ERROR( "Process %d using kernel context %d\n",
|
||||
current->pid, lock.context );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
DRM_DEBUG( "%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
|
||||
lock.context, current->pid,
|
||||
dev->lock.hw_lock->lock, lock.flags );
|
||||
|
||||
#if __HAVE_DMA_QUEUE
|
||||
if ( lock.context < 0 )
|
||||
return -EINVAL;
|
||||
#elif __HAVE_MULTIPLE_DMA_QUEUES
|
||||
if ( lock.context < 0 || lock.context >= dev->queue_count )
|
||||
return -EINVAL;
|
||||
q = dev->queuelist[lock.context];
|
||||
#endif
|
||||
|
||||
#if __HAVE_DMA_FLUSH
|
||||
ret = drm_flush_block_and_flush( dev, lock.context, lock.flags );
|
||||
#endif
|
||||
if ( !ret ) {
|
||||
/* FIXME: do gamma stuff???
|
||||
*/
|
||||
|
||||
add_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if ( !dev->lock.hw_lock ) {
|
||||
/* Device has been unregistered */
|
||||
ret = -EINTR;
|
||||
break;
|
||||
}
|
||||
if ( DRM(lock_take)( &dev->lock.hw_lock->lock,
|
||||
lock.context ) ) {
|
||||
dev->lock.pid = current->pid;
|
||||
dev->lock.lock_time = jiffies;
|
||||
atomic_inc( &dev->total_locks );
|
||||
#if __HAVE_MULTIPLE_DMA_QUEUES
|
||||
atomic_inc( &q->total_locks );
|
||||
#endif
|
||||
break; /* Got lock */
|
||||
}
|
||||
|
||||
/* Contention */
|
||||
atomic_inc( &dev->total_sleeps );
|
||||
schedule();
|
||||
if ( signal_pending( current ) ) {
|
||||
ret = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue( &dev->lock.lock_queue, &entry );
|
||||
}
|
||||
|
||||
#if __HAVE_DMA_FLUSH
|
||||
DRM(flush_unblock)( dev, lock.context, lock.flags ); /* cleanup phase */
|
||||
#endif
|
||||
|
||||
if ( !ret ) {
|
||||
sigemptyset( &dev->sigmask );
|
||||
sigaddset( &dev->sigmask, SIGSTOP );
|
||||
sigaddset( &dev->sigmask, SIGTSTP );
|
||||
sigaddset( &dev->sigmask, SIGTTIN );
|
||||
sigaddset( &dev->sigmask, SIGTTOU );
|
||||
dev->sigdata.context = lock.context;
|
||||
dev->sigdata.lock = dev->lock.hw_lock;
|
||||
block_all_signals( DRM(notifier),
|
||||
&dev->sigdata, &dev->sigmask );
|
||||
|
||||
#if __HAVE_DMA_READY
|
||||
if ( lock.flags & _DRM_LOCK_READY ) {
|
||||
DRIVER_DMA_READY();
|
||||
}
|
||||
#endif
|
||||
#if __HAVE_DMA_QUIESCENT
|
||||
if ( lock.flags & _DRM_LOCK_QUIESCENT ) {
|
||||
DRIVER_DMA_QUIESCENT();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DRM_DEBUG( "%d %s\n", lock.context, ret ? "interrupted" : "has lock" );
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.lacq[DRM(histogram_slot)(get_cycles()-start)]);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int DRM(unlock)( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg )
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_lock_t lock;
|
||||
|
||||
if ( copy_from_user( &lock, (drm_lock_t *)arg, sizeof(lock) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( lock.context == DRM_KERNEL_CONTEXT ) {
|
||||
DRM_ERROR( "Process %d using kernel context %d\n",
|
||||
current->pid, lock.context );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
atomic_inc( &dev->total_unlocks );
|
||||
if ( _DRM_LOCK_IS_CONT( dev->lock.hw_lock->lock ) )
|
||||
atomic_inc( &dev->total_contends );
|
||||
|
||||
DRM(lock_transfer)( dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT );
|
||||
#if __HAVE_DMA_SCHEDULE
|
||||
DRM(dma_schedule)( dev, 1 );
|
||||
#endif
|
||||
|
||||
/* FIXME: Do we ever really need to check this???
|
||||
*/
|
||||
if ( 1 /* !dev->context_flag */ ) {
|
||||
if ( DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT ) ) {
|
||||
DRM_ERROR( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
unblock_all_signals();
|
||||
return 0;
|
||||
}
|
||||
252
linux/drm_fops.h
Normal file
252
linux/drm_fops.h
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
/* drm_fops.h -- File operations for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Daryll Strauss <daryll@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include <linux/poll.h>
|
||||
|
||||
/* drm_open is called whenever a process opens /dev/drm. */
|
||||
|
||||
int DRM(open_helper)(struct inode *inode, struct file *filp, drm_device_t *dev)
|
||||
{
|
||||
kdev_t minor = MINOR(inode->i_rdev);
|
||||
drm_file_t *priv;
|
||||
|
||||
if (filp->f_flags & O_EXCL) return -EBUSY; /* No exclusive opens */
|
||||
if (!DRM(cpu_valid)()) return -EINVAL;
|
||||
|
||||
DRM_DEBUG("pid = %d, minor = %d\n", current->pid, minor);
|
||||
|
||||
priv = DRM(alloc)(sizeof(*priv), DRM_MEM_FILES);
|
||||
memset(priv, 0, sizeof(*priv));
|
||||
filp->private_data = priv;
|
||||
priv->uid = current->euid;
|
||||
priv->pid = current->pid;
|
||||
priv->minor = minor;
|
||||
priv->dev = dev;
|
||||
priv->ioctl_count = 0;
|
||||
priv->authenticated = capable(CAP_SYS_ADMIN);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
if (!dev->file_last) {
|
||||
priv->next = NULL;
|
||||
priv->prev = NULL;
|
||||
dev->file_first = priv;
|
||||
dev->file_last = priv;
|
||||
} else {
|
||||
priv->next = NULL;
|
||||
priv->prev = dev->file_last;
|
||||
dev->file_last->next = priv;
|
||||
dev->file_last = priv;
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(flush)(struct file *filp)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
||||
DRM_DEBUG("pid = %d, device = 0x%x, open_count = %d\n",
|
||||
current->pid, dev->device, dev->open_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* drm_release is called whenever a process closes /dev/drm*. Linux calls
|
||||
this only if any mappings have been closed. */
|
||||
|
||||
int drm_release(struct inode *inode, struct file *filp)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
||||
DRM_DEBUG("pid = %d, device = 0x%x, open_count = %d\n",
|
||||
current->pid, dev->device, dev->open_count);
|
||||
|
||||
if (dev->lock.hw_lock
|
||||
&& _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)
|
||||
&& dev->lock.pid == current->pid) {
|
||||
DRM_ERROR("Process %d dead, freeing lock for context %d\n",
|
||||
current->pid,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
|
||||
drm_lock_free(dev,
|
||||
&dev->lock.hw_lock->lock,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
|
||||
|
||||
/* FIXME: may require heavy-handed reset of
|
||||
hardware at this point, possibly
|
||||
processed via a callback to the X
|
||||
server. */
|
||||
}
|
||||
drm_reclaim_buffers(dev, priv->pid);
|
||||
|
||||
drm_fasync(-1, filp, 0);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
if (priv->prev) priv->prev->next = priv->next;
|
||||
else dev->file_first = priv->next;
|
||||
if (priv->next) priv->next->prev = priv->prev;
|
||||
else dev->file_last = priv->prev;
|
||||
up(&dev->struct_sem);
|
||||
|
||||
drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int DRM(fasync)(int fd, struct file *filp, int on)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int retcode;
|
||||
|
||||
DRM_DEBUG("fd = %d, device = 0x%x\n", fd, dev->device);
|
||||
retcode = fasync_helper(fd, filp, on, &dev->buf_async);
|
||||
if (retcode < 0) return retcode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* The drm_read and drm_write_string code (especially that which manages
|
||||
the circular buffer), is based on Alessandro Rubini's LINUX DEVICE
|
||||
DRIVERS (Cambridge: O'Reilly, 1998), pages 111-113. */
|
||||
|
||||
ssize_t DRM(read)(struct file *filp, char *buf, size_t count, loff_t *off)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int left;
|
||||
int avail;
|
||||
int send;
|
||||
int cur;
|
||||
|
||||
DRM_DEBUG("%p, %p\n", dev->buf_rp, dev->buf_wp);
|
||||
|
||||
while (dev->buf_rp == dev->buf_wp) {
|
||||
DRM_DEBUG(" sleeping\n");
|
||||
if (filp->f_flags & O_NONBLOCK) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
interruptible_sleep_on(&dev->buf_readers);
|
||||
if (signal_pending(current)) {
|
||||
DRM_DEBUG(" interrupted\n");
|
||||
return -ERESTARTSYS;
|
||||
}
|
||||
DRM_DEBUG(" awake\n");
|
||||
}
|
||||
|
||||
left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
avail = DRM_BSZ - left;
|
||||
send = DRM_MIN(avail, count);
|
||||
|
||||
while (send) {
|
||||
if (dev->buf_wp > dev->buf_rp) {
|
||||
cur = DRM_MIN(send, dev->buf_wp - dev->buf_rp);
|
||||
} else {
|
||||
cur = DRM_MIN(send, dev->buf_end - dev->buf_rp);
|
||||
}
|
||||
if (copy_to_user(buf, dev->buf_rp, cur))
|
||||
return -EFAULT;
|
||||
dev->buf_rp += cur;
|
||||
if (dev->buf_rp == dev->buf_end) dev->buf_rp = dev->buf;
|
||||
send -= cur;
|
||||
}
|
||||
|
||||
wake_up_interruptible(&dev->buf_writers);
|
||||
return DRM_MIN(avail, count);;
|
||||
}
|
||||
|
||||
int DRM(write_string)(drm_device_t *dev, const char *s)
|
||||
{
|
||||
int left = (dev->buf_rp + DRM_BSZ - dev->buf_wp) % DRM_BSZ;
|
||||
int send = strlen(s);
|
||||
int count;
|
||||
|
||||
DRM_DEBUG("%d left, %d to send (%p, %p)\n",
|
||||
left, send, dev->buf_rp, dev->buf_wp);
|
||||
|
||||
if (left == 1 || dev->buf_wp != dev->buf_rp) {
|
||||
DRM_ERROR("Buffer not empty (%d left, wp = %p, rp = %p)\n",
|
||||
left,
|
||||
dev->buf_wp,
|
||||
dev->buf_rp);
|
||||
}
|
||||
|
||||
while (send) {
|
||||
if (dev->buf_wp >= dev->buf_rp) {
|
||||
count = DRM_MIN(send, dev->buf_end - dev->buf_wp);
|
||||
if (count == left) --count; /* Leave a hole */
|
||||
} else {
|
||||
count = DRM_MIN(send, dev->buf_rp - dev->buf_wp - 1);
|
||||
}
|
||||
strncpy(dev->buf_wp, s, count);
|
||||
dev->buf_wp += count;
|
||||
if (dev->buf_wp == dev->buf_end) dev->buf_wp = dev->buf;
|
||||
send -= count;
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020315 && !defined(KILLFASYNCHASTHREEPARAMETERS)
|
||||
/* The extra parameter to kill_fasync was added in 2.3.21, and is
|
||||
_not_ present in _stock_ 2.2.14 and 2.2.15. However, some
|
||||
distributions patch 2.2.x kernels to add this parameter. The
|
||||
Makefile.linux attempts to detect this addition and defines
|
||||
KILLFASYNCHASTHREEPARAMETERS if three parameters are found. */
|
||||
if (dev->buf_async) kill_fasync(dev->buf_async, SIGIO);
|
||||
#else
|
||||
|
||||
/* Parameter added in 2.3.21. */
|
||||
#if LINUX_VERSION_CODE < 0x020400
|
||||
if (dev->buf_async) kill_fasync(dev->buf_async, SIGIO, POLL_IN);
|
||||
#else
|
||||
/* Type of first parameter changed in
|
||||
Linux 2.4.0-test2... */
|
||||
if (dev->buf_async) kill_fasync(&dev->buf_async, SIGIO, POLL_IN);
|
||||
#endif
|
||||
#endif
|
||||
DRM_DEBUG("waking\n");
|
||||
wake_up_interruptible(&dev->buf_readers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
||||
poll_wait(filp, &dev->buf_readers, wait);
|
||||
if (dev->buf_wp != dev->buf_rp) return POLLIN | POLLRDNORM;
|
||||
return 0;
|
||||
}
|
||||
112
linux/drm_init.h
Normal file
112
linux/drm_init.h
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/* drm_init.h -- Setup/Cleanup for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(flags) = 0;
|
||||
|
||||
/* drm_parse_option parses a single option. See description for
|
||||
* drm_parse_options for details.
|
||||
*/
|
||||
static void DRM(parse_option)(char *s)
|
||||
{
|
||||
char *c, *r;
|
||||
|
||||
DRM_DEBUG("\"%s\"\n", s);
|
||||
if (!s || !*s) return;
|
||||
for (c = s; *c && *c != ':'; c++); /* find : or \0 */
|
||||
if (*c) r = c + 1; else r = NULL; /* remember remainder */
|
||||
*c = '\0'; /* terminate */
|
||||
if (!strcmp(s, "noctx")) {
|
||||
DRM(flags) |= DRM_FLAG_NOCTX;
|
||||
DRM_INFO("Server-mediated context switching OFF\n");
|
||||
return;
|
||||
}
|
||||
if (!strcmp(s, "debug")) {
|
||||
DRM(flags) |= DRM_FLAG_DEBUG;
|
||||
DRM_INFO("Debug messages ON\n");
|
||||
return;
|
||||
}
|
||||
DRM_ERROR("\"%s\" is not a valid option\n", s);
|
||||
return;
|
||||
}
|
||||
|
||||
/* drm_parse_options parse the insmod "drm=" options, or the command-line
|
||||
* options passed to the kernel via LILO. The grammar of the format is as
|
||||
* follows:
|
||||
*
|
||||
* drm ::= 'drm=' option_list
|
||||
* option_list ::= option [ ';' option_list ]
|
||||
* option ::= 'device:' major
|
||||
* | 'debug'
|
||||
* | 'noctx'
|
||||
* major ::= INTEGER
|
||||
*
|
||||
* Note that 's' contains option_list without the 'drm=' part.
|
||||
*
|
||||
* device=major,minor specifies the device number used for /dev/drm
|
||||
* if major == 0 then the misc device is used
|
||||
* if major == 0 and minor == 0 then dynamic misc allocation is used
|
||||
* debug=on specifies that debugging messages will be printk'd
|
||||
* debug=trace specifies that each function call will be logged via printk
|
||||
* debug=off turns off all debugging options
|
||||
*
|
||||
*/
|
||||
|
||||
void DRM(parse_options)(char *s)
|
||||
{
|
||||
char *h, *t, *n;
|
||||
|
||||
DRM_DEBUG("\"%s\"\n", s ?: "");
|
||||
if (!s || !*s) return;
|
||||
|
||||
for (h = t = n = s; h && *h; h = n) {
|
||||
for (; *t && *t != ';'; t++); /* find ; or \0 */
|
||||
if (*t) n = t + 1; else n = NULL; /* remember next */
|
||||
*t = '\0'; /* terminate */
|
||||
DRM(parse_option)(h); /* parse */
|
||||
}
|
||||
}
|
||||
|
||||
/* drm_cpu_valid returns non-zero if the DRI will run on this CPU, and 0
|
||||
* otherwise.
|
||||
*/
|
||||
int DRM(cpu_valid)(void)
|
||||
{
|
||||
#if defined(__i386__)
|
||||
if (boot_cpu_data.x86 == 3) return 0; /* No cmpxchg on a 386 */
|
||||
#endif
|
||||
#if defined(__sparc__) && !defined(__sparc_v9__)
|
||||
return 0; /* No cmpxchg before v9 sparc. */
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
99
linux/drm_ioctl.h
Normal file
99
linux/drm_ioctl.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/* drm_ioctl.h -- IOCTL processing for DRM -*- linux-c -*-
|
||||
* Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int DRM(irq_busid)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_irq_busid_t p;
|
||||
struct pci_dev *dev;
|
||||
|
||||
if (copy_from_user(&p, (drm_irq_busid_t *)arg, sizeof(p)))
|
||||
return -EFAULT;
|
||||
dev = pci_find_slot(p.busnum, PCI_DEVFN(p.devnum, p.funcnum));
|
||||
if (dev) p.irq = dev->irq;
|
||||
else p.irq = 0;
|
||||
DRM_DEBUG("%d:%d:%d => IRQ %d\n",
|
||||
p.busnum, p.devnum, p.funcnum, p.irq);
|
||||
if (copy_to_user((drm_irq_busid_t *)arg, &p, sizeof(p)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(getunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_unique_t u;
|
||||
|
||||
if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u)))
|
||||
return -EFAULT;
|
||||
if (u.unique_len >= dev->unique_len) {
|
||||
if (copy_to_user(u.unique, dev->unique, dev->unique_len))
|
||||
return -EFAULT;
|
||||
}
|
||||
u.unique_len = dev->unique_len;
|
||||
if (copy_to_user((drm_unique_t *)arg, &u, sizeof(u)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(setunique)(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_unique_t u;
|
||||
|
||||
if (dev->unique_len || dev->unique)
|
||||
return -EBUSY;
|
||||
|
||||
if (copy_from_user(&u, (drm_unique_t *)arg, sizeof(u)))
|
||||
return -EFAULT;
|
||||
|
||||
if (!u.unique_len)
|
||||
return -EINVAL;
|
||||
|
||||
dev->unique_len = u.unique_len;
|
||||
dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
|
||||
if (copy_from_user(dev->unique, u.unique, dev->unique_len))
|
||||
return -EFAULT;
|
||||
dev->unique[dev->unique_len] = '\0';
|
||||
|
||||
dev->devname = DRM(alloc)(strlen(dev->name) + strlen(dev->unique) + 2,
|
||||
DRM_MEM_DRIVER);
|
||||
sprintf(dev->devname, "%s@%s", dev->name, dev->unique);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* lists.c -- Buffer list handling routines -*- linux-c -*-
|
||||
* Created: Mon Apr 19 20:54:22 1999 by faith@precisioninsight.com
|
||||
/* drm_lists.h -- Buffer list handling routines -*- linux-c -*-
|
||||
* Created: Mon Apr 19 20:54:22 1999 by faith@valinux.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
||||
|
|
@ -11,34 +11,36 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
int drm_waitlist_create(drm_waitlist_t *bl, int count)
|
||||
#if __HAVE_DMA_WAITLIST
|
||||
|
||||
int DRM(waitlist_create)(drm_waitlist_t *bl, int count)
|
||||
{
|
||||
if (bl->count) return -EINVAL;
|
||||
|
||||
|
||||
bl->count = count;
|
||||
bl->bufs = drm_alloc((bl->count + 2) * sizeof(*bl->bufs),
|
||||
DRM_MEM_BUFLISTS);
|
||||
bl->bufs = DRM(alloc)((bl->count + 2) * sizeof(*bl->bufs),
|
||||
DRM_MEM_BUFLISTS);
|
||||
bl->rp = bl->bufs;
|
||||
bl->wp = bl->bufs;
|
||||
bl->end = &bl->bufs[bl->count+1];
|
||||
|
|
@ -47,12 +49,12 @@ int drm_waitlist_create(drm_waitlist_t *bl, int count)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_waitlist_destroy(drm_waitlist_t *bl)
|
||||
int DRM(waitlist_destroy)(drm_waitlist_t *bl)
|
||||
{
|
||||
if (bl->rp != bl->wp) return -EINVAL;
|
||||
if (bl->bufs) drm_free(bl->bufs,
|
||||
(bl->count + 2) * sizeof(*bl->bufs),
|
||||
DRM_MEM_BUFLISTS);
|
||||
if (bl->bufs) DRM(free)(bl->bufs,
|
||||
(bl->count + 2) * sizeof(*bl->bufs),
|
||||
DRM_MEM_BUFLISTS);
|
||||
bl->count = 0;
|
||||
bl->bufs = NULL;
|
||||
bl->rp = NULL;
|
||||
|
|
@ -61,8 +63,8 @@ int drm_waitlist_destroy(drm_waitlist_t *bl)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_waitlist_put(drm_waitlist_t *bl, drm_buf_t *buf)
|
||||
{
|
||||
int DRM(waitlist_put)(drm_waitlist_t *bl, drm_buf_t *buf)
|
||||
{
|
||||
int left;
|
||||
unsigned long flags;
|
||||
|
||||
|
|
@ -76,16 +78,16 @@ int drm_waitlist_put(drm_waitlist_t *bl, drm_buf_t *buf)
|
|||
buf->time_queued = get_cycles();
|
||||
#endif
|
||||
buf->list = DRM_LIST_WAIT;
|
||||
|
||||
|
||||
spin_lock_irqsave(&bl->write_lock, flags);
|
||||
*bl->wp = buf;
|
||||
if (++bl->wp >= bl->end) bl->wp = bl->bufs;
|
||||
spin_unlock_irqrestore(&bl->write_lock, flags);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
drm_buf_t *drm_waitlist_get(drm_waitlist_t *bl)
|
||||
drm_buf_t *DRM(waitlist_get)(drm_waitlist_t *bl)
|
||||
{
|
||||
drm_buf_t *buf;
|
||||
unsigned long flags;
|
||||
|
|
@ -95,14 +97,18 @@ drm_buf_t *drm_waitlist_get(drm_waitlist_t *bl)
|
|||
if (bl->rp == bl->wp) {
|
||||
spin_unlock_irqrestore(&bl->read_lock, flags);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (++bl->rp >= bl->end) bl->rp = bl->bufs;
|
||||
spin_unlock_irqrestore(&bl->read_lock, flags);
|
||||
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int drm_freelist_create(drm_freelist_t *bl, int count)
|
||||
#endif /* __HAVE_DMA_WAITLIST */
|
||||
|
||||
#if __HAVE_DMA_FREELIST
|
||||
|
||||
int DRM(freelist_create)(drm_freelist_t *bl, int count)
|
||||
{
|
||||
atomic_set(&bl->count, 0);
|
||||
bl->next = NULL;
|
||||
|
|
@ -115,14 +121,14 @@ int drm_freelist_create(drm_freelist_t *bl, int count)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int drm_freelist_destroy(drm_freelist_t *bl)
|
||||
int DRM(freelist_destroy)(drm_freelist_t *bl)
|
||||
{
|
||||
atomic_set(&bl->count, 0);
|
||||
bl->next = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl, drm_buf_t *buf)
|
||||
int DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl, drm_buf_t *buf)
|
||||
{
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
|
||||
|
|
@ -138,15 +144,15 @@ int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl, drm_buf_t *buf)
|
|||
if (!bl) return 1;
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_freed = get_cycles();
|
||||
drm_histogram_compute(dev, buf);
|
||||
DRM(histogram_compute)(dev, buf);
|
||||
#endif
|
||||
buf->list = DRM_LIST_FREE;
|
||||
|
||||
|
||||
spin_lock(&bl->lock);
|
||||
buf->next = bl->next;
|
||||
bl->next = buf;
|
||||
spin_unlock(&bl->lock);
|
||||
|
||||
|
||||
atomic_inc(&bl->count);
|
||||
if (atomic_read(&bl->count) > dma->buf_count) {
|
||||
DRM_ERROR("%d of %d buffers free after addition of %d\n",
|
||||
|
|
@ -161,12 +167,12 @@ int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl, drm_buf_t *buf)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static drm_buf_t *drm_freelist_try(drm_freelist_t *bl)
|
||||
static drm_buf_t *DRM(freelist_try)(drm_freelist_t *bl)
|
||||
{
|
||||
drm_buf_t *buf;
|
||||
|
||||
if (!bl) return NULL;
|
||||
|
||||
|
||||
/* Get buffer */
|
||||
spin_lock(&bl->lock);
|
||||
if (!bl->next) {
|
||||
|
|
@ -176,7 +182,7 @@ static drm_buf_t *drm_freelist_try(drm_freelist_t *bl)
|
|||
buf = bl->next;
|
||||
bl->next = bl->next->next;
|
||||
spin_unlock(&bl->lock);
|
||||
|
||||
|
||||
atomic_dec(&bl->count);
|
||||
buf->next = NULL;
|
||||
buf->list = DRM_LIST_NONE;
|
||||
|
|
@ -184,17 +190,17 @@ static drm_buf_t *drm_freelist_try(drm_freelist_t *bl)
|
|||
DRM_ERROR("Free buffer %d: w%d, p%d, l%d\n",
|
||||
buf->idx, buf->waiting, buf->pending, buf->list);
|
||||
}
|
||||
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block)
|
||||
drm_buf_t *DRM(freelist_get)(drm_freelist_t *bl, int block)
|
||||
{
|
||||
drm_buf_t *buf = NULL;
|
||||
DECLARE_WAITQUEUE(entry, current);
|
||||
|
||||
if (!bl || !bl->initialized) return NULL;
|
||||
|
||||
|
||||
/* Check for low water mark */
|
||||
if (atomic_read(&bl->count) <= bl->low_mark) /* Became low */
|
||||
atomic_set(&bl->wfh, 1);
|
||||
|
|
@ -204,7 +210,7 @@ drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block)
|
|||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if (!atomic_read(&bl->wfh)
|
||||
&& (buf = drm_freelist_try(bl))) break;
|
||||
&& (buf = DRM(freelist_try)(bl))) break;
|
||||
schedule();
|
||||
if (signal_pending(current)) break;
|
||||
}
|
||||
|
|
@ -213,6 +219,8 @@ drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block)
|
|||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
return drm_freelist_try(bl);
|
||||
|
||||
return DRM(freelist_try)(bl);
|
||||
}
|
||||
|
||||
#endif /* __HAVE_DMA_FREELIST */
|
||||
256
linux/drm_lock.h
Normal file
256
linux/drm_lock.h
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
/* lock.c -- IOCTLs for locking -*- linux-c -*-
|
||||
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
#ifndef HAVE_DMA_QUEUE
|
||||
#define HAVE_DMA_QUEUE 0
|
||||
#endif
|
||||
|
||||
int DRM(block)(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(unblock)(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
DRM_DEBUG("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new, prev;
|
||||
|
||||
do {
|
||||
old = *lock;
|
||||
if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
|
||||
else new = context | _DRM_LOCK_HELD;
|
||||
prev = cmpxchg(lock, old, new);
|
||||
} while (prev != old);
|
||||
if (_DRM_LOCKING_CONTEXT(old) == context) {
|
||||
if (old & _DRM_LOCK_HELD) {
|
||||
if (context != DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("%d holds heavyweight lock\n",
|
||||
context);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (new == (context | _DRM_LOCK_HELD)) {
|
||||
/* Have lock */
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This takes a lock forcibly and hands it to context. Should ONLY be used
|
||||
inside *_unlock to give lock to kernel before calling *_dma_schedule. */
|
||||
int DRM(lock_transfer)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new, prev;
|
||||
|
||||
dev->lock.pid = 0;
|
||||
do {
|
||||
old = *lock;
|
||||
new = context | _DRM_LOCK_HELD;
|
||||
prev = cmpxchg(lock, old, new);
|
||||
} while (prev != old);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DRM(lock_free)(drm_device_t *dev,
|
||||
__volatile__ unsigned int *lock, unsigned int context)
|
||||
{
|
||||
unsigned int old, new, prev;
|
||||
pid_t pid = dev->lock.pid;
|
||||
|
||||
dev->lock.pid = 0;
|
||||
do {
|
||||
old = *lock;
|
||||
new = 0;
|
||||
prev = cmpxchg(lock, old, new);
|
||||
} while (prev != old);
|
||||
if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
|
||||
DRM_ERROR("%d freed heavyweight lock held by %d (pid %d)\n",
|
||||
context,
|
||||
_DRM_LOCKING_CONTEXT(old),
|
||||
pid);
|
||||
return 1;
|
||||
}
|
||||
wake_up_interruptible(&dev->lock.lock_queue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DRM(flush_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
DECLARE_WAITQUEUE(entry, current);
|
||||
int ret = 0;
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
atomic_inc(&q->block_write);
|
||||
add_wait_queue(&q->flush_queue, &entry);
|
||||
atomic_inc(&q->block_count);
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if (!DRM_BUFCOUNT(&q->waitlist)) break;
|
||||
schedule();
|
||||
if (signal_pending(current)) {
|
||||
ret = -EINTR; /* Can't restart */
|
||||
break;
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->block_count);
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue(&q->flush_queue, &entry);
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
atomic_inc(&q->total_flushed);
|
||||
|
||||
/* NOTE: block_write is still incremented!
|
||||
Use drm_flush_unlock_queue to decrement. */
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int DRM(flush_unblock_queue)(drm_device_t *dev, int context)
|
||||
{
|
||||
drm_queue_t *q = dev->queuelist[context];
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
atomic_inc(&q->use_count);
|
||||
if (atomic_read(&q->use_count) > 1) {
|
||||
if (atomic_read(&q->block_write)) {
|
||||
atomic_dec(&q->block_write);
|
||||
wake_up_interruptible(&q->write_queue);
|
||||
}
|
||||
}
|
||||
atomic_dec(&q->use_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(flush_block_and_flush)(drm_device_t *dev, int context,
|
||||
drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = DRM(flush_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = DRM(flush_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(flush_unblock)(drm_device_t *dev, int context, drm_lock_flags_t flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (flags & _DRM_LOCK_FLUSH) {
|
||||
ret = DRM(flush_unblock_queue)(dev, DRM_KERNEL_CONTEXT);
|
||||
if (!ret) ret = DRM(flush_unblock_queue)(dev, context);
|
||||
}
|
||||
if (flags & _DRM_LOCK_FLUSH_ALL) {
|
||||
for (i = 0; !ret && i < dev->queue_count; i++) {
|
||||
ret = DRM(flush_unblock_queue)(dev, i);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DRM(finish)(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int ret = 0;
|
||||
drm_lock_t lock;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
|
||||
return -EFAULT;
|
||||
ret = DRM(flush_block_and_flush)(dev, lock.context, lock.flags);
|
||||
DRM(flush_unblock)(dev, lock.context, lock.flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If we get here, it means that the process has called DRM_IOCTL_LOCK
|
||||
without calling DRM_IOCTL_UNLOCK.
|
||||
|
||||
If the lock is not held, then let the signal proceed as usual.
|
||||
|
||||
If the lock is held, then set the contended flag and keep the signal
|
||||
blocked.
|
||||
|
||||
|
||||
Return 1 if the signal should be delivered normally.
|
||||
Return 0 if the signal should be blocked. */
|
||||
|
||||
int DRM(notifier)(void *priv)
|
||||
{
|
||||
drm_sigdata_t *s = (drm_sigdata_t *)priv;
|
||||
unsigned int old, new, prev;
|
||||
|
||||
|
||||
/* Allow signal delivery if lock isn't held */
|
||||
if (!_DRM_LOCK_IS_HELD(s->lock->lock)
|
||||
|| _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context) return 1;
|
||||
|
||||
/* Otherwise, set flag to force call to
|
||||
drmUnlock */
|
||||
do {
|
||||
old = s->lock->lock;
|
||||
new = old | _DRM_LOCK_CONT;
|
||||
prev = cmpxchg(&s->lock->lock, old, new);
|
||||
} while (prev != old);
|
||||
return 0;
|
||||
}
|
||||
450
linux/drm_memory.h
Normal file
450
linux/drm_memory.h
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
/* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
|
||||
* Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include <linux/config.h>
|
||||
#include "drmP.h"
|
||||
#include <linux/wrapper.h>
|
||||
|
||||
typedef struct drm_mem_stats {
|
||||
const char *name;
|
||||
int succeed_count;
|
||||
int free_count;
|
||||
int fail_count;
|
||||
unsigned long bytes_allocated;
|
||||
unsigned long bytes_freed;
|
||||
} drm_mem_stats_t;
|
||||
|
||||
static spinlock_t drm_mem_lock = SPIN_LOCK_UNLOCKED;
|
||||
static unsigned long drm_ram_available = 0; /* In pages */
|
||||
static unsigned long drm_ram_used = 0;
|
||||
static drm_mem_stats_t drm_mem_stats[] = {
|
||||
[DRM_MEM_DMA] = { "dmabufs" },
|
||||
[DRM_MEM_SAREA] = { "sareas" },
|
||||
[DRM_MEM_DRIVER] = { "driver" },
|
||||
[DRM_MEM_MAGIC] = { "magic" },
|
||||
[DRM_MEM_IOCTLS] = { "ioctltab" },
|
||||
[DRM_MEM_MAPS] = { "maplist" },
|
||||
[DRM_MEM_VMAS] = { "vmalist" },
|
||||
[DRM_MEM_BUFS] = { "buflist" },
|
||||
[DRM_MEM_SEGS] = { "seglist" },
|
||||
[DRM_MEM_PAGES] = { "pagelist" },
|
||||
[DRM_MEM_FILES] = { "files" },
|
||||
[DRM_MEM_QUEUES] = { "queues" },
|
||||
[DRM_MEM_CMDS] = { "commands" },
|
||||
[DRM_MEM_MAPPINGS] = { "mappings" },
|
||||
[DRM_MEM_BUFLISTS] = { "buflists" },
|
||||
[DRM_MEM_AGPLISTS] = { "agplist" },
|
||||
[DRM_MEM_TOTALAGP] = { "totalagp" },
|
||||
[DRM_MEM_BOUNDAGP] = { "boundagp" },
|
||||
[DRM_MEM_CTXBITMAP] = { "ctxbitmap"},
|
||||
{ NULL, 0, } /* Last entry must be null */
|
||||
};
|
||||
|
||||
void DRM(mem_init)(void)
|
||||
{
|
||||
drm_mem_stats_t *mem;
|
||||
struct sysinfo si;
|
||||
|
||||
for (mem = drm_mem_stats; mem->name; ++mem) {
|
||||
mem->succeed_count = 0;
|
||||
mem->free_count = 0;
|
||||
mem->fail_count = 0;
|
||||
mem->bytes_allocated = 0;
|
||||
mem->bytes_freed = 0;
|
||||
}
|
||||
|
||||
si_meminfo(&si);
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
/* Changed to page count in 2.3.23 */
|
||||
drm_ram_available = si.totalram >> PAGE_SHIFT;
|
||||
#else
|
||||
drm_ram_available = si.totalram;
|
||||
#endif
|
||||
drm_ram_used = 0;
|
||||
}
|
||||
|
||||
/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
|
||||
|
||||
static int _drm_mem_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data)
|
||||
{
|
||||
drm_mem_stats_t *pt;
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
DRM_PROC_PRINT(" total counts "
|
||||
" | outstanding \n");
|
||||
DRM_PROC_PRINT("type alloc freed fail bytes freed"
|
||||
" | allocs bytes\n\n");
|
||||
DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu kB |\n",
|
||||
"system", 0, 0, 0,
|
||||
drm_ram_available << (PAGE_SHIFT - 10));
|
||||
DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu kB |\n",
|
||||
"locked", 0, 0, 0, drm_ram_used >> 10);
|
||||
DRM_PROC_PRINT("\n");
|
||||
for (pt = drm_mem_stats; pt->name; pt++) {
|
||||
DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
|
||||
pt->name,
|
||||
pt->succeed_count,
|
||||
pt->free_count,
|
||||
pt->fail_count,
|
||||
pt->bytes_allocated,
|
||||
pt->bytes_freed,
|
||||
pt->succeed_count - pt->free_count,
|
||||
(long)pt->bytes_allocated
|
||||
- (long)pt->bytes_freed);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int DRM(mem_info)(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
ret = _drm_mem_info(buf, start, offset, len, eof, data);
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *DRM(alloc)(size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pt = kmalloc(size, GFP_KERNEL))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[area].fail_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return NULL;
|
||||
}
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[area].succeed_count;
|
||||
drm_mem_stats[area].bytes_allocated += size;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!(pt = DRM(alloc)(size, area))) return NULL;
|
||||
if (oldpt && oldsize) {
|
||||
memcpy(pt, oldpt, oldsize);
|
||||
DRM(free)(oldpt, oldsize, area);
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
char *DRM(strdup)(const char *s, int area)
|
||||
{
|
||||
char *pt;
|
||||
int length = s ? strlen(s) : 0;
|
||||
|
||||
if (!(pt = DRM(alloc)(length+1, area))) return NULL;
|
||||
strcpy(pt, s);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void DRM(strfree)(const char *s, int area)
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
if (!s) return;
|
||||
|
||||
size = 1 + (s ? strlen(s) : 0);
|
||||
DRM(free)((void *)s, size, area);
|
||||
}
|
||||
|
||||
void DRM(free)(void *pt, size_t size, int area)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
|
||||
else kfree(pt);
|
||||
spin_lock(&drm_mem_lock);
|
||||
drm_mem_stats[area].bytes_freed += size;
|
||||
free_count = ++drm_mem_stats[area].free_count;
|
||||
alloc_count = drm_mem_stats[area].succeed_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long DRM(alloc_pages)(int order, int area)
|
||||
{
|
||||
unsigned long address;
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
unsigned long addr;
|
||||
unsigned int sz;
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
if ((drm_ram_used >> PAGE_SHIFT)
|
||||
> (DRM_RAM_PERCENT * drm_ram_available) / 100) {
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return 0;
|
||||
}
|
||||
spin_unlock(&drm_mem_lock);
|
||||
|
||||
address = __get_free_pages(GFP_KERNEL, order);
|
||||
if (!address) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[area].fail_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return 0;
|
||||
}
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[area].succeed_count;
|
||||
drm_mem_stats[area].bytes_allocated += bytes;
|
||||
drm_ram_used += bytes;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
|
||||
|
||||
/* Zero outside the lock */
|
||||
memset((void *)address, 0, bytes);
|
||||
|
||||
/* Reserve */
|
||||
for (addr = address, sz = bytes;
|
||||
sz > 0;
|
||||
addr += PAGE_SIZE, sz -= PAGE_SIZE) {
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
/* Argument type changed in 2.4.0-test6/pre8 */
|
||||
mem_map_reserve(virt_to_page(addr));
|
||||
#else
|
||||
mem_map_reserve(MAP_NR(addr));
|
||||
#endif
|
||||
}
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
void DRM(free_pages)(unsigned long address, int order, int area)
|
||||
{
|
||||
unsigned long bytes = PAGE_SIZE << order;
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
unsigned long addr;
|
||||
unsigned int sz;
|
||||
|
||||
if (!address) {
|
||||
DRM_MEM_ERROR(area, "Attempt to free address 0\n");
|
||||
} else {
|
||||
/* Unreserve */
|
||||
for (addr = address, sz = bytes;
|
||||
sz > 0;
|
||||
addr += PAGE_SIZE, sz -= PAGE_SIZE) {
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
/* Argument type changed in 2.4.0-test6/pre8 */
|
||||
mem_map_unreserve(virt_to_page(addr));
|
||||
#else
|
||||
mem_map_unreserve(MAP_NR(addr));
|
||||
#endif
|
||||
}
|
||||
free_pages(address, order);
|
||||
}
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
free_count = ++drm_mem_stats[area].free_count;
|
||||
alloc_count = drm_mem_stats[area].succeed_count;
|
||||
drm_mem_stats[area].bytes_freed += bytes;
|
||||
drm_ram_used -= bytes;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(area,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
void *DRM(ioremap)(unsigned long offset, unsigned long size)
|
||||
{
|
||||
void *pt;
|
||||
|
||||
if (!size) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Mapping 0 bytes at 0x%08lx\n", offset);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pt = ioremap(offset, size))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_MAPPINGS].fail_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return NULL;
|
||||
}
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_MAPPINGS].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_MAPPINGS].bytes_allocated += size;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void DRM(ioremapfree)(void *pt, unsigned long size)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
|
||||
if (!pt)
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Attempt to free NULL pointer\n");
|
||||
else
|
||||
iounmap(pt);
|
||||
|
||||
spin_lock(&drm_mem_lock);
|
||||
drm_mem_stats[DRM_MEM_MAPPINGS].bytes_freed += size;
|
||||
free_count = ++drm_mem_stats[DRM_MEM_MAPPINGS].free_count;
|
||||
alloc_count = drm_mem_stats[DRM_MEM_MAPPINGS].succeed_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
|
||||
agp_memory *DRM(alloc_agp)(int pages, u32 type)
|
||||
{
|
||||
agp_memory *handle;
|
||||
|
||||
if (!pages) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((handle = DRM(agp_allocate_memory)(pages, type))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_TOTALAGP].bytes_allocated
|
||||
+= pages << PAGE_SHIFT;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return handle;
|
||||
}
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_TOTALAGP].fail_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DRM(free_agp)(agp_memory *handle, int pages)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
int retval = -EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
|
||||
"Attempt to free NULL AGP handle\n");
|
||||
return retval;;
|
||||
}
|
||||
|
||||
if (DRM(agp_free_memory)(handle)) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
free_count = ++drm_mem_stats[DRM_MEM_TOTALAGP].free_count;
|
||||
alloc_count = drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_TOTALAGP].bytes_freed
|
||||
+= pages << PAGE_SHIFT;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int DRM(bind_agp)(agp_memory *handle, unsigned int start)
|
||||
{
|
||||
int retcode = -EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to bind NULL AGP handle\n");
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_allocated
|
||||
+= handle->page_count << PAGE_SHIFT;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return retcode;
|
||||
}
|
||||
spin_lock(&drm_mem_lock);
|
||||
++drm_mem_stats[DRM_MEM_BOUNDAGP].fail_count;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int DRM(unbind_agp)(agp_memory *handle)
|
||||
{
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
int retcode = -EINVAL;
|
||||
|
||||
if (!handle) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Attempt to unbind NULL AGP handle\n");
|
||||
return retcode;
|
||||
}
|
||||
|
||||
if ((retcode = DRM(agp_unbind_memory)(handle))) return retcode;
|
||||
spin_lock(&drm_mem_lock);
|
||||
free_count = ++drm_mem_stats[DRM_MEM_BOUNDAGP].free_count;
|
||||
alloc_count = drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
|
||||
drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_freed
|
||||
+= handle->page_count << PAGE_SHIFT;
|
||||
spin_unlock(&drm_mem_lock);
|
||||
if (free_count > alloc_count) {
|
||||
DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
|
||||
"Excess frees: %d frees, %d allocs\n",
|
||||
free_count, alloc_count);
|
||||
}
|
||||
return retcode;
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE) */
|
||||
578
linux/drm_proc.h
Normal file
578
linux/drm_proc.h
Normal file
|
|
@ -0,0 +1,578 @@
|
|||
/* drm_proc.h -- /proc support for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
static struct proc_dir_entry *drm_root = NULL;
|
||||
static struct proc_dir_entry *drm_dev_root = NULL;
|
||||
static char drm_slot_name[64];
|
||||
|
||||
static int drm_name_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
static int drm_vm_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
static int drm_clients_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
static int drm_queues_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
static int drm_bufs_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
#if DRM_DEBUG_CODE
|
||||
static int drm_vma_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
#endif
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
static int drm_histo_info(char *buf, char **start, off_t offset,
|
||||
int len, int *eof, void *data);
|
||||
#endif
|
||||
|
||||
struct drm_proc_list {
|
||||
const char *name;
|
||||
int (*f)(char *, char **, off_t, int, int *, void *);
|
||||
} drm_proc_list[] = {
|
||||
{ "name", drm_name_info },
|
||||
{ "mem", DRM(mem_info) },
|
||||
{ "vm", drm_vm_info },
|
||||
{ "clients", drm_clients_info },
|
||||
{ "queues", drm_queues_info },
|
||||
{ "bufs", drm_bufs_info },
|
||||
#if DRM_DEBUG_CODE
|
||||
{ "vma", drm_vma_info },
|
||||
#endif
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
{ "histo", drm_histo_info },
|
||||
#endif
|
||||
};
|
||||
#define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
|
||||
|
||||
int DRM(proc_init)(drm_device_t *dev)
|
||||
{
|
||||
struct proc_dir_entry *ent;
|
||||
int i, j;
|
||||
|
||||
drm_root = create_proc_entry("dri", S_IFDIR, NULL);
|
||||
if (!drm_root) {
|
||||
DRM_ERROR("Cannot create /proc/dri\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Instead of doing this search, we should
|
||||
add some global support for /proc/dri. */
|
||||
for (i = 0; i < 8; i++) {
|
||||
sprintf(drm_slot_name, "dri/%d", i);
|
||||
drm_dev_root = create_proc_entry(drm_slot_name, S_IFDIR, NULL);
|
||||
if (!drm_dev_root) {
|
||||
DRM_ERROR("Cannot create /proc/%s\n", drm_slot_name);
|
||||
remove_proc_entry("dri", NULL);
|
||||
}
|
||||
if (drm_dev_root->nlink == 2) break;
|
||||
drm_dev_root = NULL;
|
||||
}
|
||||
if (!drm_dev_root) {
|
||||
DRM_ERROR("Cannot find slot in /proc/dri\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < DRM_PROC_ENTRIES; i++) {
|
||||
ent = create_proc_entry(drm_proc_list[i].name,
|
||||
S_IFREG|S_IRUGO, drm_dev_root);
|
||||
if (!ent) {
|
||||
DRM_ERROR("Cannot create /proc/%s/%s\n",
|
||||
drm_slot_name, drm_proc_list[i].name);
|
||||
for (j = 0; j < i; j++)
|
||||
remove_proc_entry(drm_proc_list[i].name,
|
||||
drm_dev_root);
|
||||
remove_proc_entry(drm_slot_name, NULL);
|
||||
remove_proc_entry("dri", NULL);
|
||||
return -1;
|
||||
}
|
||||
ent->read_proc = drm_proc_list[i].f;
|
||||
ent->data = dev;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DRM(proc_cleanup)(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (drm_root) {
|
||||
if (drm_dev_root) {
|
||||
for (i = 0; i < DRM_PROC_ENTRIES; i++) {
|
||||
remove_proc_entry(drm_proc_list[i].name,
|
||||
drm_dev_root);
|
||||
}
|
||||
remove_proc_entry(drm_slot_name, NULL);
|
||||
}
|
||||
remove_proc_entry("dri", NULL);
|
||||
remove_proc_entry(DRM_NAME, NULL);
|
||||
}
|
||||
drm_root = drm_dev_root = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int drm_name_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
|
||||
if (dev->unique) {
|
||||
DRM_PROC_PRINT("%s 0x%x %s\n",
|
||||
dev->name, dev->device, dev->unique);
|
||||
} else {
|
||||
DRM_PROC_PRINT("%s 0x%x\n", dev->name, dev->device);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int _drm_vm_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
drm_map_t *map;
|
||||
/* Hardcoded from _DRM_FRAME_BUFFER,
|
||||
_DRM_REGISTERS, _DRM_SHM, and
|
||||
_DRM_AGP. */
|
||||
const char *types[] = { "FB", "REG", "SHM", "AGP" };
|
||||
const char *type;
|
||||
int i;
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
DRM_PROC_PRINT("slot offset size type flags "
|
||||
"address mtrr\n\n");
|
||||
for (i = 0; i < dev->map_count; i++) {
|
||||
map = dev->maplist[i];
|
||||
if (map->type < 0 || map->type > 3) type = "??";
|
||||
else type = types[map->type];
|
||||
DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
|
||||
i,
|
||||
map->offset,
|
||||
map->size,
|
||||
type,
|
||||
map->flags,
|
||||
(unsigned long)map->handle);
|
||||
if (map->mtrr < 0) {
|
||||
DRM_PROC_PRINT("none\n");
|
||||
} else {
|
||||
DRM_PROC_PRINT("%4d\n", map->mtrr);
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int drm_vm_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int ret;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
ret = _drm_vm_info(buf, start, offset, len, eof, data);
|
||||
up(&dev->struct_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int _drm_queues_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int i;
|
||||
drm_queue_t *q;
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
DRM_PROC_PRINT(" ctx/flags use fin"
|
||||
" blk/rw/rwf wait flushed queued"
|
||||
" locks\n\n");
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
q = dev->queuelist[i];
|
||||
atomic_inc(&q->use_count);
|
||||
DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
|
||||
"%5d/0x%03x %5d %5d"
|
||||
" %5d/%c%c/%c%c%c %5Zd %10d %10d %10d\n",
|
||||
i,
|
||||
q->flags,
|
||||
atomic_read(&q->use_count),
|
||||
atomic_read(&q->finalization),
|
||||
atomic_read(&q->block_count),
|
||||
atomic_read(&q->block_read) ? 'r' : '-',
|
||||
atomic_read(&q->block_write) ? 'w' : '-',
|
||||
waitqueue_active(&q->read_queue) ? 'r':'-',
|
||||
waitqueue_active(&q->write_queue) ? 'w':'-',
|
||||
waitqueue_active(&q->flush_queue) ? 'f':'-',
|
||||
DRM_BUFCOUNT(&q->waitlist),
|
||||
atomic_read(&q->total_flushed),
|
||||
atomic_read(&q->total_queued),
|
||||
atomic_read(&q->total_locks));
|
||||
atomic_dec(&q->use_count);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int drm_queues_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int ret;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
ret = _drm_queues_info(buf, start, offset, len, eof, data);
|
||||
up(&dev->struct_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* drm_bufs_info is called whenever a process reads
|
||||
/dev/drm/<dev>/bufs. */
|
||||
|
||||
static int _drm_bufs_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i;
|
||||
|
||||
if (!dma) return 0;
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
DRM_PROC_PRINT(" o size count free segs pages kB\n\n");
|
||||
for (i = 0; i <= DRM_MAX_ORDER; i++) {
|
||||
if (dma->bufs[i].buf_count)
|
||||
DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
|
||||
i,
|
||||
dma->bufs[i].buf_size,
|
||||
dma->bufs[i].buf_count,
|
||||
atomic_read(&dma->bufs[i]
|
||||
.freelist.count),
|
||||
dma->bufs[i].seg_count,
|
||||
dma->bufs[i].seg_count
|
||||
*(1 << dma->bufs[i].page_order),
|
||||
(dma->bufs[i].seg_count
|
||||
* (1 << dma->bufs[i].page_order))
|
||||
* PAGE_SIZE / 1024);
|
||||
}
|
||||
DRM_PROC_PRINT("\n");
|
||||
for (i = 0; i < dma->buf_count; i++) {
|
||||
if (i && !(i%32)) DRM_PROC_PRINT("\n");
|
||||
DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
|
||||
}
|
||||
DRM_PROC_PRINT("\n");
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int drm_bufs_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int ret;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
ret = _drm_bufs_info(buf, start, offset, len, eof, data);
|
||||
up(&dev->struct_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int _drm_clients_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
drm_file_t *priv;
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
DRM_PROC_PRINT("a dev pid uid magic ioctls\n\n");
|
||||
for (priv = dev->file_first; priv; priv = priv->next) {
|
||||
DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
|
||||
priv->authenticated ? 'y' : 'n',
|
||||
priv->minor,
|
||||
priv->pid,
|
||||
priv->uid,
|
||||
priv->magic,
|
||||
priv->ioctl_count);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int drm_clients_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int ret;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
ret = _drm_clients_info(buf, start, offset, len, eof, data);
|
||||
up(&dev->struct_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if DRM_DEBUG_CODE
|
||||
|
||||
#define DRM_VMA_VERBOSE 0
|
||||
|
||||
static int _drm_vma_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
drm_vma_entry_t *pt;
|
||||
struct vm_area_struct *vma;
|
||||
#if DRM_VMA_VERBOSE
|
||||
unsigned long i;
|
||||
unsigned long address;
|
||||
pgd_t *pgd;
|
||||
pmd_t *pmd;
|
||||
pte_t *pte;
|
||||
#endif
|
||||
#if defined(__i386__)
|
||||
unsigned int pgprot;
|
||||
#endif
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
|
||||
atomic_read(&dev->vma_count),
|
||||
high_memory, virt_to_phys(high_memory));
|
||||
for (pt = dev->vmalist; pt; pt = pt->next) {
|
||||
if (!(vma = pt->vma)) continue;
|
||||
DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
|
||||
pt->pid,
|
||||
vma->vm_start,
|
||||
vma->vm_end,
|
||||
vma->vm_flags & VM_READ ? 'r' : '-',
|
||||
vma->vm_flags & VM_WRITE ? 'w' : '-',
|
||||
vma->vm_flags & VM_EXEC ? 'x' : '-',
|
||||
vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
|
||||
vma->vm_flags & VM_LOCKED ? 'l' : '-',
|
||||
vma->vm_flags & VM_IO ? 'i' : '-',
|
||||
VM_OFFSET(vma));
|
||||
|
||||
#if defined(__i386__)
|
||||
pgprot = pgprot_val(vma->vm_page_prot);
|
||||
DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
|
||||
pgprot & _PAGE_PRESENT ? 'p' : '-',
|
||||
pgprot & _PAGE_RW ? 'w' : 'r',
|
||||
pgprot & _PAGE_USER ? 'u' : 's',
|
||||
pgprot & _PAGE_PWT ? 't' : 'b',
|
||||
pgprot & _PAGE_PCD ? 'u' : 'c',
|
||||
pgprot & _PAGE_ACCESSED ? 'a' : '-',
|
||||
pgprot & _PAGE_DIRTY ? 'd' : '-',
|
||||
pgprot & _PAGE_PSE ? 'm' : 'k',
|
||||
pgprot & _PAGE_GLOBAL ? 'g' : 'l' );
|
||||
#endif
|
||||
DRM_PROC_PRINT("\n");
|
||||
#if 0
|
||||
for (i = vma->vm_start; i < vma->vm_end; i += PAGE_SIZE) {
|
||||
pgd = pgd_offset(vma->vm_mm, i);
|
||||
pmd = pmd_offset(pgd, i);
|
||||
pte = pte_offset(pmd, i);
|
||||
if (pte_present(*pte)) {
|
||||
address = __pa(pte_page(*pte))
|
||||
+ (i & (PAGE_SIZE-1));
|
||||
DRM_PROC_PRINT(" 0x%08lx -> 0x%08lx"
|
||||
" %c%c%c%c%c\n",
|
||||
i,
|
||||
address,
|
||||
pte_read(*pte) ? 'r' : '-',
|
||||
pte_write(*pte) ? 'w' : '-',
|
||||
pte_exec(*pte) ? 'x' : '-',
|
||||
pte_dirty(*pte) ? 'd' : '-',
|
||||
pte_young(*pte) ? 'a' : '-' );
|
||||
} else {
|
||||
DRM_PROC_PRINT(" 0x%08lx\n", i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int drm_vma_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int ret;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
ret = _drm_vma_info(buf, start, offset, len, eof, data);
|
||||
up(&dev->struct_sem);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
static int _drm_histo_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int i;
|
||||
unsigned long slot_value = DRM_DMA_HISTOGRAM_INITIAL;
|
||||
unsigned long prev_value = 0;
|
||||
drm_buf_t *buffer;
|
||||
|
||||
if (offset > 0) return 0; /* no partial requests */
|
||||
len = 0;
|
||||
*eof = 1;
|
||||
|
||||
DRM_PROC_PRINT("general statistics:\n");
|
||||
DRM_PROC_PRINT("total %10u\n", atomic_read(&dev->histo.total));
|
||||
DRM_PROC_PRINT("open %10u\n", atomic_read(&dev->total_open));
|
||||
DRM_PROC_PRINT("close %10u\n", atomic_read(&dev->total_close));
|
||||
DRM_PROC_PRINT("ioctl %10u\n", atomic_read(&dev->total_ioctl));
|
||||
DRM_PROC_PRINT("irq %10u\n", atomic_read(&dev->total_irq));
|
||||
DRM_PROC_PRINT("ctx %10u\n", atomic_read(&dev->total_ctx));
|
||||
|
||||
DRM_PROC_PRINT("\nlock statistics:\n");
|
||||
DRM_PROC_PRINT("locks %10u\n", atomic_read(&dev->total_locks));
|
||||
DRM_PROC_PRINT("unlocks %10u\n", atomic_read(&dev->total_unlocks));
|
||||
DRM_PROC_PRINT("contends %10u\n", atomic_read(&dev->total_contends));
|
||||
DRM_PROC_PRINT("sleeps %10u\n", atomic_read(&dev->total_sleeps));
|
||||
|
||||
|
||||
if (dma) {
|
||||
DRM_PROC_PRINT("\ndma statistics:\n");
|
||||
DRM_PROC_PRINT("prio %10u\n",
|
||||
atomic_read(&dma->total_prio));
|
||||
DRM_PROC_PRINT("bytes %10u\n",
|
||||
atomic_read(&dma->total_bytes));
|
||||
DRM_PROC_PRINT("dmas %10u\n",
|
||||
atomic_read(&dma->total_dmas));
|
||||
DRM_PROC_PRINT("missed:\n");
|
||||
DRM_PROC_PRINT(" dma %10u\n",
|
||||
atomic_read(&dma->total_missed_dma));
|
||||
DRM_PROC_PRINT(" lock %10u\n",
|
||||
atomic_read(&dma->total_missed_lock));
|
||||
DRM_PROC_PRINT(" free %10u\n",
|
||||
atomic_read(&dma->total_missed_free));
|
||||
DRM_PROC_PRINT(" sched %10u\n",
|
||||
atomic_read(&dma->total_missed_sched));
|
||||
DRM_PROC_PRINT("tried %10u\n",
|
||||
atomic_read(&dma->total_tried));
|
||||
DRM_PROC_PRINT("hit %10u\n",
|
||||
atomic_read(&dma->total_hit));
|
||||
DRM_PROC_PRINT("lost %10u\n",
|
||||
atomic_read(&dma->total_lost));
|
||||
|
||||
buffer = dma->next_buffer;
|
||||
if (buffer) {
|
||||
DRM_PROC_PRINT("next_buffer %7d\n", buffer->idx);
|
||||
} else {
|
||||
DRM_PROC_PRINT("next_buffer none\n");
|
||||
}
|
||||
buffer = dma->this_buffer;
|
||||
if (buffer) {
|
||||
DRM_PROC_PRINT("this_buffer %7d\n", buffer->idx);
|
||||
} else {
|
||||
DRM_PROC_PRINT("this_buffer none\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DRM_PROC_PRINT("\nvalues:\n");
|
||||
if (dev->lock.hw_lock) {
|
||||
DRM_PROC_PRINT("lock 0x%08x\n",
|
||||
dev->lock.hw_lock->lock);
|
||||
} else {
|
||||
DRM_PROC_PRINT("lock none\n");
|
||||
}
|
||||
DRM_PROC_PRINT("context_flag 0x%08lx\n", dev->context_flag);
|
||||
DRM_PROC_PRINT("interrupt_flag 0x%08lx\n", dev->interrupt_flag);
|
||||
DRM_PROC_PRINT("dma_flag 0x%08lx\n", dev->dma_flag);
|
||||
|
||||
DRM_PROC_PRINT("queue_count %10d\n", dev->queue_count);
|
||||
DRM_PROC_PRINT("last_context %10d\n", dev->last_context);
|
||||
DRM_PROC_PRINT("last_switch %10lu\n", dev->last_switch);
|
||||
DRM_PROC_PRINT("last_checked %10d\n", dev->last_checked);
|
||||
|
||||
|
||||
DRM_PROC_PRINT("\n q2d d2c c2f"
|
||||
" q2c q2f dma sch"
|
||||
" ctx lacq lhld\n\n");
|
||||
for (i = 0; i < DRM_DMA_HISTOGRAM_SLOTS; i++) {
|
||||
DRM_PROC_PRINT("%s %10lu %10u %10u %10u %10u %10u"
|
||||
" %10u %10u %10u %10u %10u\n",
|
||||
i == DRM_DMA_HISTOGRAM_SLOTS - 1 ? ">=" : "< ",
|
||||
i == DRM_DMA_HISTOGRAM_SLOTS - 1
|
||||
? prev_value : slot_value ,
|
||||
|
||||
atomic_read(&dev->histo
|
||||
.queued_to_dispatched[i]),
|
||||
atomic_read(&dev->histo
|
||||
.dispatched_to_completed[i]),
|
||||
atomic_read(&dev->histo
|
||||
.completed_to_freed[i]),
|
||||
|
||||
atomic_read(&dev->histo
|
||||
.queued_to_completed[i]),
|
||||
atomic_read(&dev->histo
|
||||
.queued_to_freed[i]),
|
||||
atomic_read(&dev->histo.dma[i]),
|
||||
atomic_read(&dev->histo.schedule[i]),
|
||||
atomic_read(&dev->histo.ctx[i]),
|
||||
atomic_read(&dev->histo.lacq[i]),
|
||||
atomic_read(&dev->histo.lhld[i]));
|
||||
prev_value = slot_value;
|
||||
slot_value = DRM_DMA_HISTOGRAM_NEXT(slot_value);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static int drm_histo_info(char *buf, char **start, off_t offset, int len,
|
||||
int *eof, void *data)
|
||||
{
|
||||
drm_device_t *dev = (drm_device_t *)data;
|
||||
int ret;
|
||||
|
||||
down(&dev->struct_sem);
|
||||
ret = _drm_histo_info(buf, start, offset, len, eof, data);
|
||||
up(&dev->struct_sem);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
370
linux/drm_vm.h
Normal file
370
linux/drm_vm.h
Normal file
|
|
@ -0,0 +1,370 @@
|
|||
/* drm_vm.h -- Memory mapping for DRM -*- linux-c -*-
|
||||
* Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
|
||||
struct vm_operations_struct drm_vm_ops = {
|
||||
nopage: DRM(vm_nopage),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
struct vm_operations_struct drm_vm_shm_ops = {
|
||||
nopage: DRM(vm_shm_nopage),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
struct vm_operations_struct drm_vm_shm_lock_ops = {
|
||||
nopage: DRM(vm_shm_nopage_lock),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
struct vm_operations_struct drm_vm_dma_ops = {
|
||||
nopage: DRM(vm_dma_nopage),
|
||||
open: DRM(vm_open),
|
||||
close: DRM(vm_close),
|
||||
};
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
return NOPAGE_SIGBUS; /* Disallow mremap */
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
#if LINUX_VERSION_CODE >= 0x020300
|
||||
drm_map_t *map = (drm_map_t *)vma->vm_private_data;
|
||||
#else
|
||||
drm_map_t *map = (drm_map_t *)vma->vm_pte;
|
||||
#endif
|
||||
unsigned long physical;
|
||||
unsigned long offset;
|
||||
|
||||
if (address > vma->vm_end) return NOPAGE_SIGBUS; /* Disallow mremap */
|
||||
if (!map) return NOPAGE_OOM; /* Nothing allocated */
|
||||
|
||||
offset = address - vma->vm_start;
|
||||
physical = (unsigned long)map->handle + offset;
|
||||
atomic_inc(&virt_to_page(physical)->count); /* Dec. by kernel */
|
||||
|
||||
DRM_DEBUG("0x%08lx => 0x%08lx\n", address, physical);
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
return physical;
|
||||
#else
|
||||
return virt_to_page(physical);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *DRM(vm_shm_nopage_lock)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
unsigned long physical;
|
||||
unsigned long offset;
|
||||
unsigned long page;
|
||||
|
||||
if (address > vma->vm_end) return NOPAGE_SIGBUS; /* Disallow mremap */
|
||||
if (!dev->lock.hw_lock) return NOPAGE_OOM; /* Nothing allocated */
|
||||
|
||||
offset = address - vma->vm_start;
|
||||
page = offset >> PAGE_SHIFT;
|
||||
physical = (unsigned long)dev->lock.hw_lock + offset;
|
||||
atomic_inc(&virt_to_page(physical)->count); /* Dec. by kernel */
|
||||
|
||||
DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", address, page, physical);
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
return physical;
|
||||
#else
|
||||
return virt_to_page(physical);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
unsigned long DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#else
|
||||
/* Return type changed in 2.3.23 */
|
||||
struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
|
||||
unsigned long address,
|
||||
int write_access)
|
||||
#endif
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
unsigned long physical;
|
||||
unsigned long offset;
|
||||
unsigned long page;
|
||||
|
||||
if (!dma) return NOPAGE_SIGBUS; /* Error */
|
||||
if (address > vma->vm_end) return NOPAGE_SIGBUS; /* Disallow mremap */
|
||||
if (!dma->pagelist) return NOPAGE_OOM ; /* Nothing allocated */
|
||||
|
||||
offset = address - vma->vm_start; /* vm_[pg]off[set] should be 0 */
|
||||
page = offset >> PAGE_SHIFT;
|
||||
physical = dma->pagelist[page] + (offset & (~PAGE_MASK));
|
||||
atomic_inc(&virt_to_page(physical)->count); /* Dec. by kernel */
|
||||
|
||||
DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", address, page, physical);
|
||||
#if LINUX_VERSION_CODE < 0x020317
|
||||
return physical;
|
||||
#else
|
||||
return virt_to_page(physical);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DRM(vm_open)(struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
#if DRM_DEBUG_CODE
|
||||
drm_vma_entry_t *vma_entry;
|
||||
#endif
|
||||
|
||||
DRM_DEBUG("0x%08lx,0x%08lx\n",
|
||||
vma->vm_start, vma->vm_end - vma->vm_start);
|
||||
atomic_inc(&dev->vma_count);
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
/* The map can exist after the fd is closed. */
|
||||
MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
|
||||
|
||||
#if DRM_DEBUG_CODE
|
||||
vma_entry = DRM(alloc)(sizeof(*vma_entry), DRM_MEM_VMAS);
|
||||
if (vma_entry) {
|
||||
down(&dev->struct_sem);
|
||||
vma_entry->vma = vma;
|
||||
vma_entry->next = dev->vmalist;
|
||||
vma_entry->pid = current->pid;
|
||||
dev->vmalist = vma_entry;
|
||||
up(&dev->struct_sem);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DRM(vm_close)(struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = vma->vm_file->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
#if DRM_DEBUG_CODE
|
||||
drm_vma_entry_t *pt, *prev;
|
||||
#endif
|
||||
|
||||
DRM_DEBUG("0x%08lx,0x%08lx\n",
|
||||
vma->vm_start, vma->vm_end - vma->vm_start);
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_DEC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_dec(&dev->vma_count);
|
||||
|
||||
#if DRM_DEBUG_CODE
|
||||
down(&dev->struct_sem);
|
||||
for (pt = dev->vmalist, prev = NULL; pt; prev = pt, pt = pt->next) {
|
||||
if (pt->vma == vma) {
|
||||
if (prev) {
|
||||
prev->next = pt->next;
|
||||
} else {
|
||||
dev->vmalist = pt->next;
|
||||
}
|
||||
DRM(free)(pt, sizeof(*pt), DRM_MEM_VMAS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
int DRM(mmap_dma)(struct file *filp, struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev;
|
||||
drm_device_dma_t *dma;
|
||||
unsigned long length = vma->vm_end - vma->vm_start;
|
||||
|
||||
lock_kernel();
|
||||
dev = priv->dev;
|
||||
dma = dev->dma;
|
||||
DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
|
||||
vma->vm_start, vma->vm_end, VM_OFFSET(vma));
|
||||
|
||||
/* Length must match exact page count */
|
||||
if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
|
||||
unlock_kernel();
|
||||
return -EINVAL;
|
||||
}
|
||||
unlock_kernel();
|
||||
|
||||
vma->vm_ops = &drm_vm_dma_ops;
|
||||
vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020203 /* KERNEL_VERSION(2,2,3) */
|
||||
/* In Linux 2.2.3 and above, this is
|
||||
handled in do_mmap() in mm/mmap.c. */
|
||||
++filp->f_count;
|
||||
#endif
|
||||
vma->vm_file = filp; /* Needed for drm_vm_open() */
|
||||
DRM(vm_open)(vma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRM(mmap)(struct file *filp, struct vm_area_struct *vma)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_map_t *map = NULL;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
|
||||
vma->vm_start, vma->vm_end, VM_OFFSET(vma));
|
||||
|
||||
if (!VM_OFFSET(vma)) return DRM(mmap_dma)(filp, vma);
|
||||
|
||||
/* A sequential search of a linked list is
|
||||
fine here because: 1) there will only be
|
||||
about 5-10 entries in the list and, 2) a
|
||||
DRI client only has to do this mapping
|
||||
once, so it doesn't have to be optimized
|
||||
for performance, even if the list was a
|
||||
bit longer. */
|
||||
for (i = 0; i < dev->map_count; i++) {
|
||||
map = dev->maplist[i];
|
||||
if (map->offset == VM_OFFSET(vma)) break;
|
||||
}
|
||||
|
||||
if (i >= dev->map_count) return -EINVAL;
|
||||
if (!map || ((map->flags&_DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
|
||||
return -EPERM;
|
||||
|
||||
/* Check for valid size. */
|
||||
if (map->size != vma->vm_end - vma->vm_start) return -EINVAL;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
|
||||
vma->vm_flags &= VM_MAYWRITE;
|
||||
#if defined(__i386__)
|
||||
pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
|
||||
#else
|
||||
/* Ye gads this is ugly. With more thought
|
||||
we could move this up higher and use
|
||||
`protection_map' instead. */
|
||||
vma->vm_page_prot = __pgprot(pte_val(pte_wrprotect(
|
||||
__pte(pgprot_val(vma->vm_page_prot)))));
|
||||
#endif
|
||||
}
|
||||
|
||||
switch (map->type) {
|
||||
case _DRM_FRAME_BUFFER:
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_AGP:
|
||||
if (VM_OFFSET(vma) >= __pa(high_memory)) {
|
||||
#if defined(__i386__)
|
||||
if (boot_cpu_data.x86 > 3 && map->type != _DRM_AGP) {
|
||||
pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
|
||||
pgprot_val(vma->vm_page_prot) &= ~_PAGE_PWT;
|
||||
}
|
||||
#elif defined(__ia64__)
|
||||
if (map->type != _DRM_AGP)
|
||||
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
|
||||
#endif
|
||||
vma->vm_flags |= VM_IO; /* not in core dump */
|
||||
}
|
||||
if (remap_page_range(vma->vm_start,
|
||||
VM_OFFSET(vma),
|
||||
vma->vm_end - vma->vm_start,
|
||||
vma->vm_page_prot))
|
||||
return -EAGAIN;
|
||||
DRM_DEBUG(" Type = %d; start = 0x%lx, end = 0x%lx,"
|
||||
" offset = 0x%lx\n",
|
||||
map->type,
|
||||
vma->vm_start, vma->vm_end, VM_OFFSET(vma));
|
||||
vma->vm_ops = &drm_vm_ops;
|
||||
break;
|
||||
case _DRM_SHM:
|
||||
if (map->flags & _DRM_CONTAINS_LOCK)
|
||||
vma->vm_ops = &drm_vm_shm_lock_ops;
|
||||
else {
|
||||
vma->vm_ops = &drm_vm_shm_ops;
|
||||
#if LINUX_VERSION_CODE >= 0x020300
|
||||
vma->vm_private_data = (void *)map;
|
||||
#else
|
||||
vma->vm_pte = (unsigned long)map;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Don't let this area swap. Change when
|
||||
DRM_KERNEL advisory is supported. */
|
||||
vma->vm_flags |= VM_LOCKED;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL; /* This should never happen. */
|
||||
}
|
||||
vma->vm_flags |= VM_LOCKED | VM_SHM; /* Don't swap */
|
||||
|
||||
#if LINUX_VERSION_CODE < 0x020203 /* KERNEL_VERSION(2,2,3) */
|
||||
/* In Linux 2.2.3 and above, this is
|
||||
handled in do_mmap() in mm/mmap.c. */
|
||||
++filp->f_count;
|
||||
#endif
|
||||
vma->vm_file = filp; /* Needed for drm_vm_open() */
|
||||
DRM(vm_open)(vma);
|
||||
return 0;
|
||||
}
|
||||
47
linux/mga.h
Normal file
47
linux/mga.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* mga.h -- Matrox G200/G400 DRM template customization -*- linux-c -*-
|
||||
* Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef __MGA_H__
|
||||
#define __MGA_H__
|
||||
|
||||
/* This remains constant for all DRM template files.
|
||||
*/
|
||||
#define DRM(x) mga_##x
|
||||
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
|
||||
#define __HAVE_MTRR 1
|
||||
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
|
||||
#endif
|
||||
612
linux/mga_bufs.c
612
linux/mga_bufs.c
|
|
@ -1,612 +0,0 @@
|
|||
/* mga_bufs.c -- IOCTLs to manage buffers -*- linux-c -*-
|
||||
* Created: Thu Jan 6 01:47:26 2000 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* 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: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
#include "linux/un.h"
|
||||
|
||||
|
||||
int mga_addbufs_agp(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
drm_buf_entry_t *entry;
|
||||
drm_buf_t *buf;
|
||||
unsigned long offset;
|
||||
unsigned long agp_offset;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int alignment;
|
||||
int page_order;
|
||||
int total;
|
||||
int byte_count;
|
||||
int i;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = drm_order(request.size);
|
||||
size = 1 << order;
|
||||
agp_offset = request.agp_start;
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN) ? PAGE_ALIGN(size):size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
byte_count = 0;
|
||||
|
||||
DRM_DEBUG("count: %d\n", count);
|
||||
DRM_DEBUG("order: %d\n", order);
|
||||
DRM_DEBUG("size: %d\n", size);
|
||||
DRM_DEBUG("agp_offset: %ld\n", agp_offset);
|
||||
DRM_DEBUG("alignment: %d\n", alignment);
|
||||
DRM_DEBUG("page_order: %d\n", page_order);
|
||||
DRM_DEBUG("total: %d\n", total);
|
||||
DRM_DEBUG("byte_count: %d\n", byte_count);
|
||||
|
||||
if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) return -EINVAL;
|
||||
if (dev->queue_count) return -EBUSY; /* Not while in use */
|
||||
spin_lock(&dev->count_lock);
|
||||
if (dev->buf_use) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc(&dev->buf_alloc);
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
entry = &dma->bufs[order];
|
||||
if (entry->buf_count) {
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
if (!entry->buflist) {
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
offset = 0;
|
||||
|
||||
|
||||
while(entry->buf_count < count) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
|
||||
buf->offset = offset; /* Hrm */
|
||||
buf->bus_address = dev->agp->base + agp_offset + offset;
|
||||
buf->address = (void *)(agp_offset + offset + dev->agp->base);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head(&buf->dma_wait);
|
||||
buf->pid = 0;
|
||||
|
||||
buf->dev_private = drm_alloc(sizeof(drm_mga_buf_priv_t),
|
||||
DRM_MEM_BUFS);
|
||||
buf->dev_priv_size = sizeof(drm_mga_buf_priv_t);
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
offset = offset + alignment;
|
||||
entry->buf_count++;
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
dma->buflist = drm_realloc(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
for (i = dma->buf_count; i < dma->buf_count + entry->buf_count; i++)
|
||||
dma->buflist[i] = &entry->buflist[i - dma->buf_count];
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
|
||||
DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
|
||||
|
||||
dma->byte_count += byte_count;
|
||||
|
||||
DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
|
||||
|
||||
drm_freelist_create(&entry->freelist, entry->buf_count);
|
||||
for (i = 0; i < entry->buf_count; i++) {
|
||||
drm_freelist_put(dev, &entry->freelist, &entry->buflist[i]);
|
||||
}
|
||||
|
||||
up(&dev->struct_sem);
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if (copy_to_user((drm_buf_desc_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
|
||||
DRM_DEBUG("count: %d\n", count);
|
||||
DRM_DEBUG("order: %d\n", order);
|
||||
DRM_DEBUG("size: %d\n", size);
|
||||
DRM_DEBUG("agp_offset: %ld\n", agp_offset);
|
||||
DRM_DEBUG("alignment: %d\n", alignment);
|
||||
DRM_DEBUG("page_order: %d\n", page_order);
|
||||
DRM_DEBUG("total: %d\n", total);
|
||||
DRM_DEBUG("byte_count: %d\n", byte_count);
|
||||
|
||||
dma->flags = _DRM_DMA_USE_AGP;
|
||||
|
||||
DRM_DEBUG("dma->flags : %x\n", dma->flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_addbufs_pci(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int count;
|
||||
int order;
|
||||
int size;
|
||||
int total;
|
||||
int page_order;
|
||||
drm_buf_entry_t *entry;
|
||||
unsigned long page;
|
||||
drm_buf_t *buf;
|
||||
int alignment;
|
||||
unsigned long offset;
|
||||
int i;
|
||||
int byte_count;
|
||||
int page_count;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
count = request.count;
|
||||
order = drm_order(request.size);
|
||||
size = 1 << order;
|
||||
|
||||
DRM_DEBUG("count = %d, size = %d (%d), order = %d, queue_count = %d\n",
|
||||
request.count, request.size, size, order, dev->queue_count);
|
||||
|
||||
if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) return -EINVAL;
|
||||
if (dev->queue_count) return -EBUSY; /* Not while in use */
|
||||
|
||||
alignment = (request.flags & _DRM_PAGE_ALIGN) ? PAGE_ALIGN(size):size;
|
||||
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
|
||||
total = PAGE_SIZE << page_order;
|
||||
|
||||
spin_lock(&dev->count_lock);
|
||||
if (dev->buf_use) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
atomic_inc(&dev->buf_alloc);
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
entry = &dma->bufs[order];
|
||||
if (entry->buf_count) {
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM; /* May only call once for each order */
|
||||
}
|
||||
|
||||
entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
if (!entry->buflist) {
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
|
||||
|
||||
entry->seglist = drm_alloc(count * sizeof(*entry->seglist),
|
||||
DRM_MEM_SEGS);
|
||||
if (!entry->seglist) {
|
||||
drm_free(entry->buflist,
|
||||
count * sizeof(*entry->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
up(&dev->struct_sem);
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(entry->seglist, 0, count * sizeof(*entry->seglist));
|
||||
|
||||
dma->pagelist = drm_realloc(dma->pagelist,
|
||||
dma->page_count * sizeof(*dma->pagelist),
|
||||
(dma->page_count + (count << page_order))
|
||||
* sizeof(*dma->pagelist),
|
||||
DRM_MEM_PAGES);
|
||||
DRM_DEBUG("pagelist: %d entries\n",
|
||||
dma->page_count + (count << page_order));
|
||||
|
||||
|
||||
entry->buf_size = size;
|
||||
entry->page_order = page_order;
|
||||
byte_count = 0;
|
||||
page_count = 0;
|
||||
while (entry->buf_count < count) {
|
||||
if (!(page = drm_alloc_pages(page_order, DRM_MEM_DMA))) break;
|
||||
entry->seglist[entry->seg_count++] = page;
|
||||
for (i = 0; i < (1 << page_order); i++) {
|
||||
DRM_DEBUG("page %d @ 0x%08lx\n",
|
||||
dma->page_count + page_count,
|
||||
page + PAGE_SIZE * i);
|
||||
dma->pagelist[dma->page_count + page_count++]
|
||||
= page + PAGE_SIZE * i;
|
||||
}
|
||||
for (offset = 0;
|
||||
offset + size <= total && entry->buf_count < count;
|
||||
offset += alignment, ++entry->buf_count) {
|
||||
buf = &entry->buflist[entry->buf_count];
|
||||
buf->idx = dma->buf_count + entry->buf_count;
|
||||
buf->total = alignment;
|
||||
buf->order = order;
|
||||
buf->used = 0;
|
||||
buf->offset = (dma->byte_count + byte_count + offset);
|
||||
buf->address = (void *)(page + offset);
|
||||
buf->next = NULL;
|
||||
buf->waiting = 0;
|
||||
buf->pending = 0;
|
||||
init_waitqueue_head(&buf->dma_wait);
|
||||
buf->pid = 0;
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
buf->time_queued = 0;
|
||||
buf->time_dispatched = 0;
|
||||
buf->time_completed = 0;
|
||||
buf->time_freed = 0;
|
||||
#endif
|
||||
DRM_DEBUG("buffer %d @ %p\n",
|
||||
entry->buf_count, buf->address);
|
||||
}
|
||||
byte_count += PAGE_SIZE << page_order;
|
||||
}
|
||||
|
||||
dma->buflist = drm_realloc(dma->buflist,
|
||||
dma->buf_count * sizeof(*dma->buflist),
|
||||
(dma->buf_count + entry->buf_count)
|
||||
* sizeof(*dma->buflist),
|
||||
DRM_MEM_BUFS);
|
||||
for (i = dma->buf_count; i < dma->buf_count + entry->buf_count; i++)
|
||||
dma->buflist[i] = &entry->buflist[i - dma->buf_count];
|
||||
|
||||
dma->buf_count += entry->buf_count;
|
||||
dma->seg_count += entry->seg_count;
|
||||
dma->page_count += entry->seg_count << page_order;
|
||||
dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
|
||||
|
||||
drm_freelist_create(&entry->freelist, entry->buf_count);
|
||||
for (i = 0; i < entry->buf_count; i++) {
|
||||
drm_freelist_put(dev, &entry->freelist, &entry->buflist[i]);
|
||||
}
|
||||
|
||||
up(&dev->struct_sem);
|
||||
|
||||
request.count = entry->buf_count;
|
||||
request.size = size;
|
||||
|
||||
if (copy_to_user((drm_buf_desc_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
atomic_dec(&dev->buf_alloc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_addbufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_buf_desc_t request;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_desc_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
if(request.flags & _DRM_AGP_BUFFER)
|
||||
return mga_addbufs_agp(inode, filp, cmd, arg);
|
||||
else
|
||||
return mga_addbufs_pci(inode, filp, cmd, arg);
|
||||
}
|
||||
|
||||
int mga_infobufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_info_t request;
|
||||
int i;
|
||||
int count;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
spin_lock(&dev->count_lock);
|
||||
if (atomic_read(&dev->buf_alloc)) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
++dev->buf_use; /* Can't allocate more after this call */
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_info_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
for (i = 0, count = 0; i < DRM_MAX_ORDER+1; i++) {
|
||||
if (dma->bufs[i].buf_count) ++count;
|
||||
}
|
||||
|
||||
if (request.count >= count) {
|
||||
for (i = 0, count = 0; i < DRM_MAX_ORDER+1; i++) {
|
||||
if (dma->bufs[i].buf_count) {
|
||||
if (copy_to_user(&request.list[count].count,
|
||||
&dma->bufs[i].buf_count,
|
||||
sizeof(dma->bufs[0]
|
||||
.buf_count)) ||
|
||||
copy_to_user(&request.list[count].size,
|
||||
&dma->bufs[i].buf_size,
|
||||
sizeof(dma->bufs[0].buf_size)) ||
|
||||
copy_to_user(&request.list[count].low_mark,
|
||||
&dma->bufs[i]
|
||||
.freelist.low_mark,
|
||||
sizeof(dma->bufs[0]
|
||||
.freelist.low_mark)) ||
|
||||
copy_to_user(&request.list[count]
|
||||
.high_mark,
|
||||
&dma->bufs[i]
|
||||
.freelist.high_mark,
|
||||
sizeof(dma->bufs[0]
|
||||
.freelist.high_mark)))
|
||||
return -EFAULT;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
request.count = count;
|
||||
|
||||
if (copy_to_user((drm_buf_info_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_markbufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_desc_t request;
|
||||
int order;
|
||||
drm_buf_entry_t *entry;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request, (drm_buf_desc_t *)arg, sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
order = drm_order(request.size);
|
||||
if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) return -EINVAL;
|
||||
entry = &dma->bufs[order];
|
||||
|
||||
if (request.low_mark < 0 || request.low_mark > entry->buf_count)
|
||||
return -EINVAL;
|
||||
if (request.high_mark < 0 || request.high_mark > entry->buf_count)
|
||||
return -EINVAL;
|
||||
|
||||
entry->freelist.low_mark = request.low_mark;
|
||||
entry->freelist.high_mark = request.high_mark;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_freebufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_buf_free_t request;
|
||||
int i;
|
||||
int idx;
|
||||
drm_buf_t *buf;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_free_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
for (i = 0; i < request.count; i++) {
|
||||
if (copy_from_user(&idx,
|
||||
&request.list[i],
|
||||
sizeof(idx)))
|
||||
return -EFAULT;
|
||||
if (idx < 0 || idx >= dma->buf_count) {
|
||||
DRM_ERROR("Index %d (of %d max)\n",
|
||||
idx, dma->buf_count - 1);
|
||||
return -EINVAL;
|
||||
}
|
||||
buf = dma->buflist[idx];
|
||||
if (buf->pid != current->pid) {
|
||||
DRM_ERROR("Process %d freeing buffer owned by %d\n",
|
||||
current->pid, buf->pid);
|
||||
return -EINVAL;
|
||||
}
|
||||
drm_free_buffer(dev, buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_mapbufs(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
int retcode = 0;
|
||||
const int zero = 0;
|
||||
unsigned long virtual;
|
||||
unsigned long address;
|
||||
drm_buf_map_t request;
|
||||
int i;
|
||||
|
||||
if (!dma) return -EINVAL;
|
||||
|
||||
spin_lock(&dev->count_lock);
|
||||
if (atomic_read(&dev->buf_alloc)) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return -EBUSY;
|
||||
}
|
||||
++dev->buf_use; /* Can't allocate more after this call */
|
||||
spin_unlock(&dev->count_lock);
|
||||
|
||||
if (copy_from_user(&request,
|
||||
(drm_buf_map_t *)arg,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
if (request.count >= dma->buf_count) {
|
||||
if(dma->flags & _DRM_DMA_USE_AGP) {
|
||||
drm_mga_private_t *dev_priv = dev->dev_private;
|
||||
drm_map_t *map = NULL;
|
||||
|
||||
map = dev->maplist[dev_priv->buffer_map_idx];
|
||||
if (!map) {
|
||||
retcode = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
DRM_DEBUG("map->offset : %lx\n", map->offset);
|
||||
DRM_DEBUG("map->size : %lx\n", map->size);
|
||||
DRM_DEBUG("map->type : %d\n", map->type);
|
||||
DRM_DEBUG("map->flags : %x\n", map->flags);
|
||||
DRM_DEBUG("map->handle : %p\n", map->handle);
|
||||
DRM_DEBUG("map->mtrr : %d\n", map->mtrr);
|
||||
down(¤t->mm->mmap_sem);
|
||||
virtual = do_mmap(filp, 0, map->size,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
(unsigned long)map->offset);
|
||||
up(¤t->mm->mmap_sem);
|
||||
} else {
|
||||
down(¤t->mm->mmap_sem);
|
||||
virtual = do_mmap(filp, 0, dma->byte_count,
|
||||
PROT_READ|PROT_WRITE, MAP_SHARED, 0);
|
||||
up(¤t->mm->mmap_sem);
|
||||
}
|
||||
if (virtual > -1024UL) {
|
||||
/* Real error */
|
||||
DRM_DEBUG("mmap error\n");
|
||||
retcode = (signed long)virtual;
|
||||
goto done;
|
||||
}
|
||||
request.virtual = (void *)virtual;
|
||||
|
||||
for (i = 0; i < dma->buf_count; i++) {
|
||||
if (copy_to_user(&request.list[i].idx,
|
||||
&dma->buflist[i]->idx,
|
||||
sizeof(request.list[0].idx))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if (copy_to_user(&request.list[i].total,
|
||||
&dma->buflist[i]->total,
|
||||
sizeof(request.list[0].total))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
if (copy_to_user(&request.list[i].used,
|
||||
&zero,
|
||||
sizeof(zero))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
address = virtual + dma->buflist[i]->offset;
|
||||
if (copy_to_user(&request.list[i].address,
|
||||
&address,
|
||||
sizeof(address))) {
|
||||
retcode = -EFAULT;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
done:
|
||||
request.count = dma->buf_count;
|
||||
DRM_DEBUG("%d buffers, retcode = %d\n", request.count, retcode);
|
||||
|
||||
if (copy_to_user((drm_buf_map_t *)arg,
|
||||
&request,
|
||||
sizeof(request)))
|
||||
return -EFAULT;
|
||||
|
||||
DRM_DEBUG("retcode : %d\n", retcode);
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
/* mga_context.c -- IOCTLs for mga contexts -*- linux-c -*-
|
||||
* Created: Mon Dec 13 09:51:35 1999 by faith@precisioninsight.com
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Author: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
|
||||
static int mga_alloc_queue(drm_device_t *dev)
|
||||
{
|
||||
return drm_ctxbitmap_next(dev);
|
||||
}
|
||||
|
||||
int mga_context_switch(drm_device_t *dev, int old, int new)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
atomic_inc(&dev->total_ctx);
|
||||
|
||||
if (test_and_set_bit(0, &dev->context_flag)) {
|
||||
DRM_ERROR("Reentering -- FIXME\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
dev->ctx_start = get_cycles();
|
||||
#endif
|
||||
|
||||
DRM_DEBUG("Context switch from %d to %d\n", old, new);
|
||||
|
||||
if (new == dev->last_context) {
|
||||
clear_bit(0, &dev->context_flag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (drm_flags & DRM_FLAG_NOCTX) {
|
||||
mga_context_switch_complete(dev, new);
|
||||
} else {
|
||||
sprintf(buf, "C %d %d\n", old, new);
|
||||
drm_write_string(dev, buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_context_switch_complete(drm_device_t *dev, int new)
|
||||
{
|
||||
dev->last_context = new; /* PRE/POST: This is the _only_ writer. */
|
||||
dev->last_switch = jiffies;
|
||||
|
||||
if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
|
||||
DRM_ERROR("Lock isn't held after context switch\n");
|
||||
}
|
||||
|
||||
/* If a context switch is ever initiated
|
||||
when the kernel holds the lock, release
|
||||
that lock here. */
|
||||
#if DRM_DMA_HISTOGRAM
|
||||
atomic_inc(&dev->histo.ctx[drm_histogram_slot(get_cycles()
|
||||
- dev->ctx_start)]);
|
||||
|
||||
#endif
|
||||
clear_bit(0, &dev->context_flag);
|
||||
wake_up(&dev->context_wait);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_resctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_ctx_res_t res;
|
||||
drm_ctx_t ctx;
|
||||
int i;
|
||||
|
||||
if (copy_from_user(&res, (drm_ctx_res_t *)arg, sizeof(res)))
|
||||
return -EFAULT;
|
||||
if (res.count >= DRM_RESERVED_CONTEXTS) {
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
|
||||
ctx.handle = i;
|
||||
if (copy_to_user(&res.contexts[i],
|
||||
&i,
|
||||
sizeof(i)))
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
res.count = DRM_RESERVED_CONTEXTS;
|
||||
if (copy_to_user((drm_ctx_res_t *)arg, &res, sizeof(res)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_addctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
if ((ctx.handle = mga_alloc_queue(dev)) == DRM_KERNEL_CONTEXT) {
|
||||
/* Skip kernel's context and get a new one. */
|
||||
ctx.handle = mga_alloc_queue(dev);
|
||||
}
|
||||
if (ctx.handle == -1) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_modctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
/* This does nothing for the mga */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_getctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if (copy_from_user(&ctx, (drm_ctx_t*)arg, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
/* This is 0, because we don't hanlde any context flags */
|
||||
ctx.flags = 0;
|
||||
if (copy_to_user((drm_ctx_t*)arg, &ctx, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_switchctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
return mga_context_switch(dev, dev->last_context, ctx.handle);
|
||||
}
|
||||
|
||||
int mga_newctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
mga_context_switch_complete(dev, ctx.handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_rmctx(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_ctx_t ctx;
|
||||
|
||||
if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
|
||||
return -EFAULT;
|
||||
DRM_DEBUG("%d\n", ctx.handle);
|
||||
if(ctx.handle == DRM_KERNEL_CONTEXT+1) priv->remove_auth_on_close = 1;
|
||||
|
||||
if(ctx.handle != DRM_KERNEL_CONTEXT) {
|
||||
drm_ctxbitmap_free(dev, ctx.handle);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
1661
linux/mga_dma.c
1661
linux/mga_dma.c
File diff suppressed because it is too large
Load diff
66
linux/mga_drm.c
Normal file
66
linux/mga_drm.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* mga_drm.c -- Matrox G200/G400 core DRM -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "mga.h"
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
|
||||
/*
|
||||
* This is an early version...
|
||||
*/
|
||||
|
||||
#define DRIVER_DEV_PRIV_T drm_mga_private_t
|
||||
#define DRIVER_AGP_BUFFER_MAP dev_priv->buffers
|
||||
|
||||
#include "drm_agpsupport.h"
|
||||
|
||||
#include "drm_auth.h"
|
||||
|
||||
#include "drm_bufs.h"
|
||||
|
||||
#include "drm_context.h"
|
||||
|
||||
#include "drm_dma.h"
|
||||
|
||||
#include "drm_drawable.h"
|
||||
|
||||
#include "drm_fops.h"
|
||||
|
||||
#include "drm_init.h"
|
||||
|
||||
#include "drm_ioctl.h"
|
||||
|
||||
#include "drm_lock.h"
|
||||
|
||||
#include "drm_memory.h"
|
||||
|
||||
#include "drm_proc.h"
|
||||
|
||||
#include "drm_vm.h"
|
||||
367
linux/mga_drm.h
367
linux/mga_drm.h
|
|
@ -11,197 +11,171 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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.
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors: Jeff Hartmann <jhartmann@valinux.com>
|
||||
* Keith Whitwell <keithw@valinux.com>
|
||||
*
|
||||
* Rewritten by:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef _MGA_DRM_H_
|
||||
#define _MGA_DRM_H_
|
||||
#ifndef __MGA_DRM_H__
|
||||
#define __MGA_DRM_H__
|
||||
|
||||
/* WARNING: If you change any of these defines, make sure to change the
|
||||
* defines in the Xserver file (xf86drmMga.h)
|
||||
* defines in the Xserver file (mga_sarea.h)
|
||||
*/
|
||||
#ifndef _MGA_DEFINES_
|
||||
#define _MGA_DEFINES_
|
||||
#ifndef __MGA_SAREA_DEFINES__
|
||||
#define __MGA_SAREA_DEFINES__
|
||||
|
||||
#define MGA_F 0x1 /* fog */
|
||||
#define MGA_A 0x2 /* alpha */
|
||||
#define MGA_S 0x4 /* specular */
|
||||
#define MGA_T2 0x8 /* multitexture */
|
||||
|
||||
#define MGA_WARP_TGZ 0
|
||||
#define MGA_WARP_TGZF (MGA_F)
|
||||
#define MGA_WARP_TGZA (MGA_A)
|
||||
#define MGA_WARP_TGZAF (MGA_F|MGA_A)
|
||||
#define MGA_WARP_TGZS (MGA_S)
|
||||
#define MGA_WARP_TGZSF (MGA_S|MGA_F)
|
||||
#define MGA_WARP_TGZSA (MGA_S|MGA_A)
|
||||
#define MGA_WARP_TGZSAF (MGA_S|MGA_F|MGA_A)
|
||||
#define MGA_WARP_T2GZ (MGA_T2)
|
||||
#define MGA_WARP_T2GZF (MGA_T2|MGA_F)
|
||||
#define MGA_WARP_T2GZA (MGA_T2|MGA_A)
|
||||
#define MGA_WARP_T2GZAF (MGA_T2|MGA_A|MGA_F)
|
||||
#define MGA_WARP_T2GZS (MGA_T2|MGA_S)
|
||||
#define MGA_WARP_T2GZSF (MGA_T2|MGA_S|MGA_F)
|
||||
#define MGA_WARP_T2GZSA (MGA_T2|MGA_S|MGA_A)
|
||||
#define MGA_WARP_T2GZSAF (MGA_T2|MGA_S|MGA_F|MGA_A)
|
||||
|
||||
#define MGA_MAX_G400_PIPES 16
|
||||
#define MGA_MAX_G200_PIPES 8 /* no multitex */
|
||||
#define MGA_MAX_WARP_PIPES MGA_MAX_G400_PIPES
|
||||
|
||||
#define MGA_CARD_TYPE_G200 1
|
||||
#define MGA_CARD_TYPE_G400 2
|
||||
|
||||
#define MGA_FRONT 0x1
|
||||
#define MGA_BACK 0x2
|
||||
#define MGA_DEPTH 0x4
|
||||
|
||||
/* 3d state excluding texture units:
|
||||
/* WARP pipe flags
|
||||
*/
|
||||
#define MGA_CTXREG_DSTORG 0 /* validated */
|
||||
#define MGA_CTXREG_MACCESS 1
|
||||
#define MGA_CTXREG_PLNWT 2
|
||||
#define MGA_CTXREG_DWGCTL 3
|
||||
#define MGA_CTXREG_ALPHACTRL 4
|
||||
#define MGA_CTXREG_FOGCOLOR 5
|
||||
#define MGA_CTXREG_WFLAG 6
|
||||
#define MGA_CTXREG_TDUAL0 7
|
||||
#define MGA_CTXREG_TDUAL1 8
|
||||
#define MGA_CTXREG_FCOL 9
|
||||
#define MGA_CTXREG_STENCIL 10
|
||||
#define MGA_CTXREG_STENCILCTL 11
|
||||
#define MGA_CTX_SETUP_SIZE 12
|
||||
#define MGA_F 0x1 /* fog */
|
||||
#define MGA_A 0x2 /* alpha */
|
||||
#define MGA_S 0x4 /* specular */
|
||||
#define MGA_T2 0x8 /* multitexture */
|
||||
|
||||
/* 2d state
|
||||
*/
|
||||
#define MGA_2DREG_PITCH 0
|
||||
#define MGA_2D_SETUP_SIZE 1
|
||||
#define MGA_WARP_TGZ 0
|
||||
#define MGA_WARP_TGZF (MGA_F)
|
||||
#define MGA_WARP_TGZA (MGA_A)
|
||||
#define MGA_WARP_TGZAF (MGA_F|MGA_A)
|
||||
#define MGA_WARP_TGZS (MGA_S)
|
||||
#define MGA_WARP_TGZSF (MGA_S|MGA_F)
|
||||
#define MGA_WARP_TGZSA (MGA_S|MGA_A)
|
||||
#define MGA_WARP_TGZSAF (MGA_S|MGA_F|MGA_A)
|
||||
#define MGA_WARP_T2GZ (MGA_T2)
|
||||
#define MGA_WARP_T2GZF (MGA_T2|MGA_F)
|
||||
#define MGA_WARP_T2GZA (MGA_T2|MGA_A)
|
||||
#define MGA_WARP_T2GZAF (MGA_T2|MGA_A|MGA_F)
|
||||
#define MGA_WARP_T2GZS (MGA_T2|MGA_S)
|
||||
#define MGA_WARP_T2GZSF (MGA_T2|MGA_S|MGA_F)
|
||||
#define MGA_WARP_T2GZSA (MGA_T2|MGA_S|MGA_A)
|
||||
#define MGA_WARP_T2GZSAF (MGA_T2|MGA_S|MGA_F|MGA_A)
|
||||
|
||||
/* Each texture unit has a state:
|
||||
*/
|
||||
#define MGA_TEXREG_CTL 0
|
||||
#define MGA_TEXREG_CTL2 1
|
||||
#define MGA_TEXREG_FILTER 2
|
||||
#define MGA_TEXREG_BORDERCOL 3
|
||||
#define MGA_TEXREG_ORG 4 /* validated */
|
||||
#define MGA_TEXREG_ORG1 5
|
||||
#define MGA_TEXREG_ORG2 6
|
||||
#define MGA_TEXREG_ORG3 7
|
||||
#define MGA_TEXREG_ORG4 8
|
||||
#define MGA_TEXREG_WIDTH 9
|
||||
#define MGA_TEXREG_HEIGHT 10
|
||||
#define MGA_TEX_SETUP_SIZE 11
|
||||
#define MGA_MAX_G200_PIPES 8 /* no multitex */
|
||||
#define MGA_MAX_G400_PIPES 16
|
||||
#define MGA_MAX_WARP_PIPES MGA_MAX_G400_PIPES
|
||||
#define MGA_WARP_UCODE_SIZE 32768 /* in bytes */
|
||||
|
||||
#define MGA_CARD_TYPE_G200 1
|
||||
#define MGA_CARD_TYPE_G400 2
|
||||
|
||||
|
||||
#define MGA_FRONT 0x1
|
||||
#define MGA_BACK 0x2
|
||||
#define MGA_DEPTH 0x4
|
||||
|
||||
/* What needs to be changed for the current vertex dma buffer?
|
||||
*/
|
||||
#define MGA_UPLOAD_CTX 0x1
|
||||
#define MGA_UPLOAD_TEX0 0x2
|
||||
#define MGA_UPLOAD_TEX1 0x4
|
||||
#define MGA_UPLOAD_PIPE 0x8
|
||||
#define MGA_UPLOAD_TEX0IMAGE 0x10 /* handled client-side */
|
||||
#define MGA_UPLOAD_TEX1IMAGE 0x20 /* handled client-side */
|
||||
#define MGA_UPLOAD_2D 0x40
|
||||
#define MGA_WAIT_AGE 0x80 /* handled client-side */
|
||||
#define MGA_UPLOAD_CLIPRECTS 0x100 /* handled client-side */
|
||||
#define MGA_DMA_FLUSH 0x200 /* set when someone gets the lock
|
||||
quiescent */
|
||||
#define MGA_UPLOAD_CONTEXT 0x1
|
||||
#define MGA_UPLOAD_TEX0 0x2
|
||||
#define MGA_UPLOAD_TEX1 0x4
|
||||
#define MGA_UPLOAD_PIPE 0x8
|
||||
#define MGA_UPLOAD_TEX0IMAGE 0x10 /* handled client-side */
|
||||
#define MGA_UPLOAD_TEX1IMAGE 0x20 /* handled client-side */
|
||||
#define MGA_UPLOAD_2D 0x40
|
||||
#define MGA_WAIT_AGE 0x80 /* handled client-side */
|
||||
#define MGA_UPLOAD_CLIPRECTS 0x100 /* handled client-side */
|
||||
#if 0
|
||||
#define MGA_DMA_FLUSH 0x200 /* set when someone gets the lock
|
||||
quiescent */
|
||||
#endif
|
||||
|
||||
/* 32 buffers of 64k each, total 2 meg.
|
||||
*/
|
||||
#define MGA_DMA_BUF_ORDER 16
|
||||
#define MGA_DMA_BUF_SZ (1<<MGA_DMA_BUF_ORDER)
|
||||
#define MGA_DMA_BUF_NR 31
|
||||
#define MGA_DMA_BUF_ORDER 16
|
||||
#define MGA_DMA_BUF_SZ (1 << MGA_DMA_BUF_ORDER)
|
||||
#define MGA_DMA_BUF_NR 31
|
||||
|
||||
/* Keep these small for testing.
|
||||
*/
|
||||
#define MGA_NR_SAREA_CLIPRECTS 8
|
||||
#define MGA_NR_SAREA_CLIPRECTS 8
|
||||
|
||||
/* 2 heaps (1 for card, 1 for agp), each divided into upto 128
|
||||
* regions, subject to a minimum region size of (1<<16) == 64k.
|
||||
* regions, subject to a minimum region size of (1<<16) == 64k.
|
||||
*
|
||||
* Clients may subdivide regions internally, but when sharing between
|
||||
* clients, the region size is the minimum granularity.
|
||||
* clients, the region size is the minimum granularity.
|
||||
*/
|
||||
|
||||
#define MGA_CARD_HEAP 0
|
||||
#define MGA_AGP_HEAP 1
|
||||
#define MGA_NR_TEX_HEAPS 2
|
||||
#define MGA_NR_TEX_REGIONS 16
|
||||
#define MGA_LOG_MIN_TEX_REGION_SIZE 16
|
||||
#endif
|
||||
#define MGA_CARD_HEAP 0
|
||||
#define MGA_AGP_HEAP 1
|
||||
#define MGA_NR_TEX_HEAPS 2
|
||||
#define MGA_NR_TEX_REGIONS 16
|
||||
#define MGA_LOG_MIN_TEX_REGION_SIZE 16
|
||||
|
||||
typedef struct _drm_mga_warp_index {
|
||||
int installed;
|
||||
unsigned long phys_addr;
|
||||
int size;
|
||||
} drm_mga_warp_index_t;
|
||||
#endif /* __MGA_SAREA_DEFINES__ */
|
||||
|
||||
typedef struct drm_mga_init {
|
||||
enum {
|
||||
MGA_INIT_DMA = 0x01,
|
||||
MGA_CLEANUP_DMA = 0x02
|
||||
} func;
|
||||
int reserved_map_agpstart;
|
||||
int reserved_map_idx;
|
||||
int buffer_map_idx;
|
||||
int sarea_priv_offset;
|
||||
int primary_size;
|
||||
int warp_ucode_size;
|
||||
unsigned int frontOffset;
|
||||
unsigned int backOffset;
|
||||
unsigned int depthOffset;
|
||||
unsigned int textureOffset;
|
||||
unsigned int textureSize;
|
||||
unsigned int agpTextureOffset;
|
||||
unsigned int agpTextureSize;
|
||||
unsigned int cpp;
|
||||
unsigned int stride;
|
||||
int sgram;
|
||||
int chipset;
|
||||
drm_mga_warp_index_t WarpIndex[MGA_MAX_WARP_PIPES];
|
||||
unsigned int mAccess;
|
||||
} drm_mga_init_t;
|
||||
|
||||
/* Warning: if you change the sarea structure, you must change the Xserver
|
||||
* structures as well */
|
||||
/* Setup registers for 3D context
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int dstorg;
|
||||
unsigned int maccess;
|
||||
unsigned int plnwt;
|
||||
unsigned int dwgctl;
|
||||
unsigned int alphactrl;
|
||||
unsigned int fogcolor;
|
||||
unsigned int wflag;
|
||||
unsigned int tdualstage0;
|
||||
unsigned int tdualstage1;
|
||||
unsigned int fcol;
|
||||
unsigned int stencil;
|
||||
unsigned int stencilctl;
|
||||
} drm_mga_context_regs_t;
|
||||
|
||||
typedef struct _drm_mga_tex_region {
|
||||
unsigned char next, prev;
|
||||
unsigned char in_use;
|
||||
unsigned int age;
|
||||
} drm_mga_tex_region_t;
|
||||
/* Setup registers for 2D, X server
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int pitch;
|
||||
} drm_mga_server_regs_t;
|
||||
|
||||
/* Setup registers for each texture unit
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int texctl;
|
||||
unsigned int texctl2;
|
||||
unsigned int texfilter;
|
||||
unsigned int texbordercol;
|
||||
unsigned int texorg;
|
||||
unsigned int texwidth;
|
||||
unsigned int texheight;
|
||||
unsigned int texorg1;
|
||||
unsigned int texorg2;
|
||||
unsigned int texorg3;
|
||||
unsigned int texorg4;
|
||||
} drm_mga_texture_regs_t;
|
||||
|
||||
typedef struct _drm_mga_sarea {
|
||||
/* The channel for communication of state information to the kernel
|
||||
* on firing a vertex dma buffer.
|
||||
*/
|
||||
unsigned int ContextState[MGA_CTX_SETUP_SIZE];
|
||||
unsigned int ServerState[MGA_2D_SETUP_SIZE];
|
||||
unsigned int TexState[2][MGA_TEX_SETUP_SIZE];
|
||||
unsigned int WarpPipe;
|
||||
drm_mga_context_regs_t context_state;
|
||||
drm_mga_server_regs_t server_state;
|
||||
drm_mga_texture_regs_t tex_state[2];
|
||||
unsigned int warp_pipe;
|
||||
unsigned int dirty;
|
||||
unsigned int vertsize;
|
||||
|
||||
unsigned int nbox;
|
||||
/* The current cliprects, or a subset thereof.
|
||||
*/
|
||||
drm_clip_rect_t boxes[MGA_NR_SAREA_CLIPRECTS];
|
||||
|
||||
unsigned int nbox;
|
||||
|
||||
/* Information about the most recently used 3d drawable. The
|
||||
* client fills in the req_* fields, the server fills in the
|
||||
* client fills in the req_* fields, the server fills in the
|
||||
* exported_ fields and puts the cliprects into boxes, above.
|
||||
*
|
||||
* The client clears the exported_drawable field before
|
||||
|
|
@ -210,75 +184,104 @@ typedef struct _drm_mga_sarea {
|
|||
unsigned int req_drawable; /* the X drawable id */
|
||||
unsigned int req_draw_buffer; /* MGA_FRONT or MGA_BACK */
|
||||
|
||||
unsigned int exported_drawable;
|
||||
unsigned int exported_index;
|
||||
unsigned int exported_stamp;
|
||||
unsigned int exported_buffers;
|
||||
unsigned int exported_drawable;
|
||||
unsigned int exported_index;
|
||||
unsigned int exported_stamp;
|
||||
unsigned int exported_buffers;
|
||||
unsigned int exported_nfront;
|
||||
unsigned int exported_nback;
|
||||
int exported_back_x, exported_front_x, exported_w;
|
||||
int exported_back_x, exported_front_x, exported_w;
|
||||
int exported_back_y, exported_front_y, exported_h;
|
||||
drm_clip_rect_t exported_boxes[MGA_NR_SAREA_CLIPRECTS];
|
||||
|
||||
|
||||
/* Counters for aging textures and for client-side throttling.
|
||||
*/
|
||||
unsigned int last_enqueue; /* last time a buffer was enqueued */
|
||||
unsigned int last_dispatch; /* age of the most recently dispatched buffer */
|
||||
unsigned int last_quiescent; /* */
|
||||
|
||||
|
||||
/* LRU lists for texture memory in agp space and on the card
|
||||
/* LRU lists for texture memory in agp space and on the card.
|
||||
*/
|
||||
drm_mga_tex_region_t texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS+1];
|
||||
drm_tex_region_t texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS+1];
|
||||
unsigned int texAge[MGA_NR_TEX_HEAPS];
|
||||
|
||||
|
||||
/* Mechanism to validate card state.
|
||||
*/
|
||||
int ctxOwner;
|
||||
int vertexsize;
|
||||
} drm_mga_sarea_t;
|
||||
} drm_mga_sarea_t;
|
||||
|
||||
/* Device specific ioctls:
|
||||
|
||||
/* WARNING: If you change any of these defines, make sure to change the
|
||||
* defines in the Xserver file (xf86drmMga.h)
|
||||
*/
|
||||
typedef struct _drm_mga_clear {
|
||||
typedef struct _drm_mga_warp_index {
|
||||
int installed;
|
||||
unsigned long phys_addr;
|
||||
int size;
|
||||
} drm_mga_warp_index_t;
|
||||
|
||||
typedef struct drm_mga_init {
|
||||
enum {
|
||||
MGA_INIT_DMA = 0x01,
|
||||
MGA_CLEANUP_DMA = 0x02
|
||||
} func;
|
||||
|
||||
int sarea_priv_offset;
|
||||
|
||||
int chipset;
|
||||
int sgram;
|
||||
|
||||
unsigned int maccess;
|
||||
|
||||
unsigned int fb_cpp;
|
||||
unsigned int front_offset, front_pitch;
|
||||
unsigned int back_offset, back_pitch;
|
||||
|
||||
unsigned int depth_cpp;
|
||||
unsigned int depth_offset, depth_pitch;
|
||||
|
||||
unsigned int texture_offset[MGA_NR_TEX_HEAPS];
|
||||
unsigned int texture_size[MGA_NR_TEX_HEAPS];
|
||||
|
||||
unsigned int fb_offset;
|
||||
unsigned int mmio_offset;
|
||||
unsigned int warp_offset;
|
||||
unsigned int primary_offset;
|
||||
unsigned int buffers_offset;
|
||||
} drm_mga_init_t;
|
||||
|
||||
typedef struct drm_mga_fullscreen {
|
||||
enum {
|
||||
MGA_INIT_FULLSCREEN = 0x01,
|
||||
MGA_CLEANUP_FULLSCREEN = 0x02
|
||||
} func;
|
||||
} drm_mga_fullscreen_t;
|
||||
|
||||
typedef struct drm_mga_clear {
|
||||
unsigned int flags;
|
||||
unsigned int clear_color;
|
||||
unsigned int clear_depth;
|
||||
unsigned int flags;
|
||||
unsigned int clear_depth_mask;
|
||||
unsigned int clear_color_mask;
|
||||
unsigned int color_mask;
|
||||
unsigned int depth_mask;
|
||||
} drm_mga_clear_t;
|
||||
|
||||
typedef struct _drm_mga_swap {
|
||||
int dummy;
|
||||
} drm_mga_swap_t;
|
||||
|
||||
typedef struct _drm_mga_iload {
|
||||
int idx;
|
||||
int length;
|
||||
unsigned int destOrg;
|
||||
} drm_mga_iload_t;
|
||||
|
||||
typedef struct _drm_mga_vertex {
|
||||
typedef struct drm_mga_vertex {
|
||||
int idx; /* buffer to queue */
|
||||
int used; /* bytes in use */
|
||||
int discard; /* client finished with buffer? */
|
||||
} drm_mga_vertex_t;
|
||||
|
||||
typedef struct _drm_mga_indices {
|
||||
typedef struct drm_mga_indices {
|
||||
int idx; /* buffer to queue */
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
unsigned int start;
|
||||
unsigned int end;
|
||||
int discard; /* client finished with buffer? */
|
||||
} drm_mga_indices_t;
|
||||
|
||||
typedef struct _drm_mga_blit {
|
||||
unsigned int planemask;
|
||||
unsigned int source;
|
||||
unsigned int dest;
|
||||
int delta_sx, delta_sy;
|
||||
int delta_dx, delta_dy;
|
||||
int height, ydir; /* flip image vertically */
|
||||
int source_pitch, dest_pitch;
|
||||
} drm_mga_blit_t;
|
||||
typedef struct drm_mga_iload {
|
||||
int idx;
|
||||
int length;
|
||||
unsigned int destOrg;
|
||||
} drm_mga_iload_t;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
716
linux/mga_drv.c
716
linux/mga_drv.c
|
|
@ -1,4 +1,4 @@
|
|||
/* mga_drv.c -- Matrox g200/g400 driver -*- linux-c -*-
|
||||
/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
|
|
@ -19,648 +19,130 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
*
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include "mga.h"
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
|
||||
#define MGA_NAME "mga"
|
||||
#define MGA_DESC "Matrox G200/G400"
|
||||
#define MGA_DATE "20000928"
|
||||
#define MGA_MAJOR 2
|
||||
#define MGA_MINOR 1
|
||||
#define MGA_PATCHLEVEL 1
|
||||
#define DRIVER_AUTHOR "Gareth Hughes, VA Linux Systems Inc."
|
||||
|
||||
static drm_device_t mga_device;
|
||||
drm_ctx_t mga_res_ctx;
|
||||
#define DRIVER_NAME "mga"
|
||||
#define DRIVER_DESC "Matrox G200/G400"
|
||||
#define DRIVER_DATE "20010110"
|
||||
|
||||
static struct file_operations mga_fops = {
|
||||
#if LINUX_VERSION_CODE >= 0x020400
|
||||
/* This started being used during 2.4.0-test */
|
||||
owner: THIS_MODULE,
|
||||
#endif
|
||||
open: mga_open,
|
||||
flush: drm_flush,
|
||||
release: mga_release,
|
||||
ioctl: mga_ioctl,
|
||||
mmap: drm_mmap,
|
||||
read: drm_read,
|
||||
fasync: drm_fasync,
|
||||
poll: drm_poll,
|
||||
};
|
||||
#define DRIVER_MAJOR 3
|
||||
#define DRIVER_MINOR 0
|
||||
#define DRIVER_PATCHLEVEL 0
|
||||
|
||||
static struct miscdevice mga_misc = {
|
||||
minor: MISC_DYNAMIC_MINOR,
|
||||
name: MGA_NAME,
|
||||
fops: &mga_fops,
|
||||
};
|
||||
|
||||
static drm_ioctl_desc_t mga_ioctls[] = {
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { mga_version, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { drm_irq_busid, 0, 1 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { drm_setunique, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { drm_block, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { drm_unblock, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { mga_control, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { drm_authmagic, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { drm_addmap, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { mga_addbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { mga_markbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { mga_infobufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { mga_mapbufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { mga_freebufs, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { mga_addctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { mga_rmctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { mga_modctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { mga_getctx, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { mga_switchctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { mga_newctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { mga_resctx, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { drm_adddraw, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { drm_rmdraw, 1, 1 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { mga_dma, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { mga_lock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { mga_unlock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { drm_finish, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { drm_agp_acquire, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { drm_agp_release, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = { drm_agp_enable, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = { drm_agp_info, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = { drm_agp_alloc, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = { drm_agp_free, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = { drm_agp_bind, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = { drm_agp_unbind, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INIT)] = { mga_dma_init, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_SWAP)] = { mga_swap_bufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_CLEAR)] = { mga_clear_bufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_ILOAD)] = { mga_iload, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_VERTEX)] = { mga_vertex, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_FLUSH)] = { mga_flush_ioctl, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INDICES)] = { mga_indices, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_BLIT)] = { mga_blit, 1, 0 },
|
||||
};
|
||||
|
||||
#define MGA_IOCTL_COUNT DRM_ARRAY_SIZE(mga_ioctls)
|
||||
|
||||
#ifdef MODULE
|
||||
static char *mga = NULL;
|
||||
#endif
|
||||
|
||||
MODULE_AUTHOR("VA Linux Systems, Inc.");
|
||||
MODULE_DESCRIPTION("Matrox G200/G400");
|
||||
MODULE_PARM(mga, "s");
|
||||
|
||||
#ifndef MODULE
|
||||
/* mga_options is called by the kernel to parse command-line options passed
|
||||
* via the boot-loader (e.g., LILO). It calls the insmod option routine,
|
||||
* drm_parse_drm.
|
||||
/* Now that we do this, we can move the DRM(ioctls) array into a
|
||||
* template file and have a DRIVER_IOCTLS block at the end.
|
||||
*/
|
||||
static drm_ioctl_desc_t mga_ioctls[] = {
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { mga_version, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { mga_getunique, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { mga_getmagic, 0, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { mga_irq_busid, 0, 1 },
|
||||
|
||||
static int __init mga_options(char *str)
|
||||
{
|
||||
drm_parse_options(str);
|
||||
return 1;
|
||||
}
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { mga_setunique, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { mga_block, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { mga_unblock, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { mga_control, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { mga_authmagic, 1, 1 },
|
||||
|
||||
__setup("mga=", mga_options);
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { mga_addmap, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { mga_addbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { mga_markbufs, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { mga_infobufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { mga_mapbufs, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { mga_freebufs, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { mga_addctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { mga_rmctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { mga_modctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { mga_getctx, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { mga_switchctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { mga_newctx, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { mga_resctx, 1, 0 },
|
||||
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { mga_adddraw, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { mga_rmdraw, 1, 1 },
|
||||
#if 0
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { mga_dma, 1, 0 },
|
||||
#endif
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { mga_lock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { mga_unlock, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { mga_finish, 1, 0 },
|
||||
|
||||
#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { mga_agp_acquire, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { mga_agp_release, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = { mga_agp_enable, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = { mga_agp_info, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = { mga_agp_alloc, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = { mga_agp_free, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = { mga_agp_bind, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = { mga_agp_unbind, 1, 1 },
|
||||
#endif
|
||||
|
||||
static int mga_setup(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
atomic_set(&dev->ioctl_count, 0);
|
||||
atomic_set(&dev->vma_count, 0);
|
||||
dev->buf_use = 0;
|
||||
atomic_set(&dev->buf_alloc, 0);
|
||||
|
||||
drm_dma_setup(dev);
|
||||
|
||||
atomic_set(&dev->total_open, 0);
|
||||
atomic_set(&dev->total_close, 0);
|
||||
atomic_set(&dev->total_ioctl, 0);
|
||||
atomic_set(&dev->total_irq, 0);
|
||||
atomic_set(&dev->total_ctx, 0);
|
||||
atomic_set(&dev->total_locks, 0);
|
||||
atomic_set(&dev->total_unlocks, 0);
|
||||
atomic_set(&dev->total_contends, 0);
|
||||
atomic_set(&dev->total_sleeps, 0);
|
||||
|
||||
for (i = 0; i < DRM_HASH_SIZE; i++) {
|
||||
dev->magiclist[i].head = NULL;
|
||||
dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
dev->vmalist = NULL;
|
||||
dev->lock.hw_lock = NULL;
|
||||
init_waitqueue_head(&dev->lock.lock_queue);
|
||||
dev->queue_count = 0;
|
||||
dev->queue_reserved = 0;
|
||||
dev->queue_slots = 0;
|
||||
dev->queuelist = NULL;
|
||||
dev->irq = 0;
|
||||
dev->context_flag = 0;
|
||||
dev->interrupt_flag = 0;
|
||||
dev->dma_flag = 0;
|
||||
dev->last_context = 0;
|
||||
dev->last_switch = 0;
|
||||
dev->last_checked = 0;
|
||||
init_timer(&dev->timer);
|
||||
init_waitqueue_head(&dev->context_wait);
|
||||
|
||||
dev->ctx_start = 0;
|
||||
dev->lck_start = 0;
|
||||
|
||||
dev->buf_rp = dev->buf;
|
||||
dev->buf_wp = dev->buf;
|
||||
dev->buf_end = dev->buf + DRM_BSZ;
|
||||
dev->buf_async = NULL;
|
||||
init_waitqueue_head(&dev->buf_readers);
|
||||
init_waitqueue_head(&dev->buf_writers);
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
/* The kernel's context could be created here, but is now created
|
||||
in drm_dma_enqueue. This is more resource-efficient for
|
||||
hardware that does not do DMA, but may mean that
|
||||
drm_select_queue fails between the time the interrupt is
|
||||
initialized and the time the queues are initialized. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int mga_takedown(drm_device_t *dev)
|
||||
{
|
||||
int i;
|
||||
drm_magic_entry_t *pt, *next;
|
||||
drm_map_t *map;
|
||||
drm_vma_entry_t *vma, *vma_next;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
if (dev->dev_private) mga_dma_cleanup(dev);
|
||||
if (dev->irq) mga_irq_uninstall(dev);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
del_timer(&dev->timer);
|
||||
|
||||
if (dev->devname) {
|
||||
drm_free(dev->devname, strlen(dev->devname)+1, DRM_MEM_DRIVER);
|
||||
dev->devname = NULL;
|
||||
}
|
||||
|
||||
if (dev->unique) {
|
||||
drm_free(dev->unique, strlen(dev->unique)+1, DRM_MEM_DRIVER);
|
||||
dev->unique = NULL;
|
||||
dev->unique_len = 0;
|
||||
}
|
||||
/* Clear pid list */
|
||||
for (i = 0; i < DRM_HASH_SIZE; i++) {
|
||||
for (pt = dev->magiclist[i].head; pt; pt = next) {
|
||||
next = pt->next;
|
||||
drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
||||
}
|
||||
dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
|
||||
}
|
||||
/* Clear AGP information */
|
||||
if (dev->agp) {
|
||||
drm_agp_mem_t *entry;
|
||||
drm_agp_mem_t *nexte;
|
||||
|
||||
/* Remove AGP resources, but leave dev->agp
|
||||
intact until cleanup is called. */
|
||||
for (entry = dev->agp->memory; entry; entry = nexte) {
|
||||
nexte = entry->next;
|
||||
if (entry->bound) drm_unbind_agp(entry->memory);
|
||||
drm_free_agp(entry->memory, entry->pages);
|
||||
drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
|
||||
}
|
||||
dev->agp->memory = NULL;
|
||||
|
||||
if (dev->agp->acquired) _drm_agp_release();
|
||||
|
||||
dev->agp->acquired = 0;
|
||||
dev->agp->enabled = 0;
|
||||
}
|
||||
/* Clear vma list (only built for debugging) */
|
||||
if (dev->vmalist) {
|
||||
for (vma = dev->vmalist; vma; vma = vma_next) {
|
||||
vma_next = vma->next;
|
||||
drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
|
||||
}
|
||||
dev->vmalist = NULL;
|
||||
}
|
||||
|
||||
/* Clear map area and mtrr information */
|
||||
if (dev->maplist) {
|
||||
for (i = 0; i < dev->map_count; i++) {
|
||||
map = dev->maplist[i];
|
||||
switch (map->type) {
|
||||
case _DRM_REGISTERS:
|
||||
case _DRM_FRAME_BUFFER:
|
||||
#ifdef CONFIG_MTRR
|
||||
if (map->mtrr >= 0) {
|
||||
int retcode;
|
||||
retcode = mtrr_del(map->mtrr,
|
||||
map->offset,
|
||||
map->size);
|
||||
DRM_DEBUG("mtrr_del = %d\n", retcode);
|
||||
}
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INIT)] = { mga_dma_init, 1, 1 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_FLUSH)] = { mga_dma_flush, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_RESET)] = { mga_dma_reset, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_SWAP)] = { mga_dma_swap, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_CLEAR)] = { mga_dma_clear, 1, 0 },
|
||||
#if 0
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_ILOAD)] = { mga_iload, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_VERTEX)] = { mga_vertex, 1, 0 },
|
||||
[DRM_IOCTL_NR(DRM_IOCTL_MGA_INDICES)] = { mga_indices, 1, 0 },
|
||||
#endif
|
||||
drm_ioremapfree(map->handle, map->size);
|
||||
break;
|
||||
case _DRM_SHM:
|
||||
drm_free_pages((unsigned long)map->handle,
|
||||
drm_order(map->size)
|
||||
- PAGE_SHIFT,
|
||||
DRM_MEM_SAREA);
|
||||
break;
|
||||
case _DRM_AGP:
|
||||
break;
|
||||
}
|
||||
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
||||
}
|
||||
drm_free(dev->maplist,
|
||||
dev->map_count * sizeof(*dev->maplist),
|
||||
DRM_MEM_MAPS);
|
||||
dev->maplist = NULL;
|
||||
dev->map_count = 0;
|
||||
}
|
||||
};
|
||||
|
||||
if (dev->queuelist) {
|
||||
for (i = 0; i < dev->queue_count; i++) {
|
||||
drm_waitlist_destroy(&dev->queuelist[i]->waitlist);
|
||||
if (dev->queuelist[i]) {
|
||||
drm_free(dev->queuelist[i],
|
||||
sizeof(*dev->queuelist[0]),
|
||||
DRM_MEM_QUEUES);
|
||||
dev->queuelist[i] = NULL;
|
||||
}
|
||||
}
|
||||
drm_free(dev->queuelist,
|
||||
dev->queue_slots * sizeof(*dev->queuelist),
|
||||
DRM_MEM_QUEUES);
|
||||
dev->queuelist = NULL;
|
||||
}
|
||||
#define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( mga_ioctls )
|
||||
|
||||
drm_dma_takedown(dev);
|
||||
#define __HAVE_AGP 1
|
||||
#define __MUST_HAVE_AGP 1
|
||||
|
||||
dev->queue_count = 0;
|
||||
if (dev->lock.hw_lock) {
|
||||
dev->lock.hw_lock = NULL; /* SHM removed */
|
||||
dev->lock.pid = 0;
|
||||
wake_up_interruptible(&dev->lock.lock_queue);
|
||||
}
|
||||
up(&dev->struct_sem);
|
||||
#define __HAVE_MTRR 1
|
||||
|
||||
return 0;
|
||||
}
|
||||
#define __HAVE_CTX_BITMAP 1
|
||||
|
||||
/* mga_init is called via init_module at module load time, or via
|
||||
* linux/init/main.c (this is not currently supported). */
|
||||
#define __HAVE_DMA 1
|
||||
#define __HAVE_DMA_IRQ 1
|
||||
|
||||
static int __init mga_init(void)
|
||||
{
|
||||
int retcode;
|
||||
drm_device_t *dev = &mga_device;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
memset((void *)dev, 0, sizeof(*dev));
|
||||
dev->count_lock = SPIN_LOCK_UNLOCKED;
|
||||
sema_init(&dev->struct_sem, 1);
|
||||
|
||||
#ifdef MODULE
|
||||
drm_parse_options(mga);
|
||||
#endif
|
||||
if ((retcode = misc_register(&mga_misc))) {
|
||||
DRM_ERROR("Cannot register \"%s\"\n", MGA_NAME);
|
||||
return retcode;
|
||||
}
|
||||
dev->device = MKDEV(MISC_MAJOR, mga_misc.minor);
|
||||
dev->name = MGA_NAME;
|
||||
|
||||
drm_mem_init();
|
||||
drm_proc_init(dev);
|
||||
dev->agp = drm_agp_init();
|
||||
if(dev->agp == NULL) {
|
||||
DRM_INFO("The mga drm module requires the agpgart module"
|
||||
" to function correctly\nPlease load the agpgart"
|
||||
" module before you load the mga module\n");
|
||||
drm_proc_cleanup();
|
||||
misc_deregister(&mga_misc);
|
||||
mga_takedown(dev);
|
||||
return -ENOMEM;
|
||||
}
|
||||
#ifdef CONFIG_MTRR
|
||||
dev->agp->agp_mtrr = mtrr_add(dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size * 1024 * 1024,
|
||||
MTRR_TYPE_WRCOMB,
|
||||
1);
|
||||
#endif
|
||||
if((retcode = drm_ctxbitmap_init(dev))) {
|
||||
DRM_ERROR("Cannot allocate memory for context bitmap.\n");
|
||||
drm_proc_cleanup();
|
||||
misc_deregister(&mga_misc);
|
||||
mga_takedown(dev);
|
||||
return retcode;
|
||||
}
|
||||
|
||||
DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
|
||||
MGA_NAME,
|
||||
MGA_MAJOR,
|
||||
MGA_MINOR,
|
||||
MGA_PATCHLEVEL,
|
||||
MGA_DATE,
|
||||
mga_misc.minor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mga_cleanup is called via cleanup_module at module unload time. */
|
||||
|
||||
static void __exit mga_cleanup(void)
|
||||
{
|
||||
drm_device_t *dev = &mga_device;
|
||||
|
||||
DRM_DEBUG("\n");
|
||||
|
||||
drm_proc_cleanup();
|
||||
if (misc_deregister(&mga_misc)) {
|
||||
DRM_ERROR("Cannot unload module\n");
|
||||
} else {
|
||||
DRM_INFO("Module unloaded\n");
|
||||
}
|
||||
drm_ctxbitmap_cleanup(dev);
|
||||
#ifdef CONFIG_MTRR
|
||||
if(dev->agp && dev->agp->agp_mtrr) {
|
||||
int retval;
|
||||
retval = mtrr_del(dev->agp->agp_mtrr,
|
||||
dev->agp->agp_info.aper_base,
|
||||
dev->agp->agp_info.aper_size * 1024*1024);
|
||||
DRM_DEBUG("mtrr_del = %d\n", retval);
|
||||
}
|
||||
#if 0
|
||||
#define __HAVE_DMA_QUEUE 1
|
||||
#define __HAVE_DMA_SCHEDULE 1
|
||||
#endif
|
||||
|
||||
mga_takedown(dev);
|
||||
if (dev->agp) {
|
||||
drm_agp_uninit();
|
||||
drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
|
||||
dev->agp = NULL;
|
||||
}
|
||||
}
|
||||
#define __HAVE_DMA_QUIESCENT 1
|
||||
#define DRIVER_DMA_QUIESCENT() \
|
||||
do { \
|
||||
drm_mga_private_t *dev_priv = dev->dev_private; \
|
||||
return mga_do_wait_for_idle( dev_priv ); \
|
||||
} while (0)
|
||||
|
||||
module_init(mga_init);
|
||||
module_exit(mga_cleanup);
|
||||
|
||||
|
||||
int mga_version(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_version_t version;
|
||||
int len;
|
||||
|
||||
if (copy_from_user(&version,
|
||||
(drm_version_t *)arg,
|
||||
sizeof(version)))
|
||||
return -EFAULT;
|
||||
|
||||
#define DRM_COPY(name,value) \
|
||||
len = strlen(value); \
|
||||
if (len > name##_len) len = name##_len; \
|
||||
name##_len = strlen(value); \
|
||||
if (len && name) { \
|
||||
if (copy_to_user(name, value, len)) \
|
||||
return -EFAULT; \
|
||||
}
|
||||
|
||||
version.version_major = MGA_MAJOR;
|
||||
version.version_minor = MGA_MINOR;
|
||||
version.version_patchlevel = MGA_PATCHLEVEL;
|
||||
|
||||
DRM_COPY(version.name, MGA_NAME);
|
||||
DRM_COPY(version.date, MGA_DATE);
|
||||
DRM_COPY(version.desc, MGA_DESC);
|
||||
|
||||
if (copy_to_user((drm_version_t *)arg,
|
||||
&version,
|
||||
sizeof(version)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
drm_device_t *dev = &mga_device;
|
||||
int retcode = 0;
|
||||
|
||||
DRM_DEBUG("open_count = %d\n", dev->open_count);
|
||||
if (!(retcode = drm_open_helper(inode, filp, dev))) {
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_INC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#if 0
|
||||
#define __HAVE_DRIVER_RELEASE 1
|
||||
#define DRIVER_RELEASE() do { \
|
||||
mga_reclaim_buffers( dev, priv->pid ); \
|
||||
if ( dev->dev_private ) { \
|
||||
drm_mga_private_t *dev_priv = dev->dev_private; \
|
||||
dev_priv->dispatch_status &= MGA_IN_DISPATCH; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
atomic_inc(&dev->total_open);
|
||||
spin_lock(&dev->count_lock);
|
||||
if (!dev->open_count++) {
|
||||
spin_unlock(&dev->count_lock);
|
||||
return mga_setup(dev);
|
||||
}
|
||||
spin_unlock(&dev->count_lock);
|
||||
}
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int mga_release(struct inode *inode, struct file *filp)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev;
|
||||
int retcode = 0;
|
||||
#define DRIVER_PRETAKEDOWN() do { \
|
||||
if ( dev->dev_private ) mga_do_cleanup_dma( dev ); \
|
||||
} while (0)
|
||||
|
||||
lock_kernel();
|
||||
dev = priv->dev;
|
||||
DRM_DEBUG("pid = %d, device = 0x%x, open_count = %d\n",
|
||||
current->pid, dev->device, dev->open_count);
|
||||
|
||||
if (dev->lock.hw_lock && _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)
|
||||
&& dev->lock.pid == current->pid) {
|
||||
mga_reclaim_buffers(dev, priv->pid);
|
||||
DRM_INFO("Process %d dead (ctx %d, d_s = 0x%02lx)\n",
|
||||
current->pid,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock),
|
||||
dev->dev_private ?
|
||||
((drm_mga_private_t *)dev->dev_private)
|
||||
->dispatch_status
|
||||
: 0);
|
||||
|
||||
if (dev->dev_private)
|
||||
((drm_mga_private_t *)dev->dev_private)
|
||||
->dispatch_status &= MGA_IN_DISPATCH;
|
||||
|
||||
drm_lock_free(dev,
|
||||
&dev->lock.hw_lock->lock,
|
||||
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
|
||||
} else if (dev->lock.hw_lock) {
|
||||
/* The lock is required to reclaim buffers */
|
||||
DECLARE_WAITQUEUE(entry, current);
|
||||
add_wait_queue(&dev->lock.lock_queue, &entry);
|
||||
for (;;) {
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
if (!dev->lock.hw_lock) {
|
||||
/* Device has been unregistered */
|
||||
retcode = -EINTR;
|
||||
break;
|
||||
}
|
||||
if (drm_lock_take(&dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) {
|
||||
dev->lock.pid = priv->pid;
|
||||
dev->lock.lock_time = jiffies;
|
||||
atomic_inc(&dev->total_locks);
|
||||
break; /* Got lock */
|
||||
}
|
||||
/* Contention */
|
||||
atomic_inc(&dev->total_sleeps);
|
||||
schedule();
|
||||
if (signal_pending(current)) {
|
||||
retcode = -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue(&dev->lock.lock_queue, &entry);
|
||||
if(!retcode) {
|
||||
mga_reclaim_buffers(dev, priv->pid);
|
||||
if (dev->dev_private)
|
||||
((drm_mga_private_t *)dev->dev_private)
|
||||
->dispatch_status &= MGA_IN_DISPATCH;
|
||||
drm_lock_free(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT);
|
||||
}
|
||||
}
|
||||
drm_fasync(-1, filp, 0);
|
||||
|
||||
down(&dev->struct_sem);
|
||||
if (priv->remove_auth_on_close == 1) {
|
||||
drm_file_t *temp = dev->file_first;
|
||||
while(temp) {
|
||||
temp->authenticated = 0;
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
if (priv->prev) priv->prev->next = priv->next;
|
||||
else dev->file_first = priv->next;
|
||||
if (priv->next) priv->next->prev = priv->prev;
|
||||
else dev->file_last = priv->prev;
|
||||
up(&dev->struct_sem);
|
||||
|
||||
drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
|
||||
#if LINUX_VERSION_CODE < 0x020333
|
||||
MOD_DEC_USE_COUNT; /* Needed before Linux 2.3.51 */
|
||||
#endif
|
||||
atomic_inc(&dev->total_close);
|
||||
spin_lock(&dev->count_lock);
|
||||
if (!--dev->open_count) {
|
||||
if (atomic_read(&dev->ioctl_count) || dev->blocked) {
|
||||
DRM_ERROR("Device busy: %d %d\n",
|
||||
atomic_read(&dev->ioctl_count),
|
||||
dev->blocked);
|
||||
spin_unlock(&dev->count_lock);
|
||||
unlock_kernel();
|
||||
return -EBUSY;
|
||||
}
|
||||
spin_unlock(&dev->count_lock);
|
||||
unlock_kernel();
|
||||
return mga_takedown(dev);
|
||||
}
|
||||
spin_unlock(&dev->count_lock);
|
||||
unlock_kernel();
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
||||
/* drm_ioctl is called whenever a process performs an ioctl on /dev/drm. */
|
||||
|
||||
int mga_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
int nr = DRM_IOCTL_NR(cmd);
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
int retcode = 0;
|
||||
drm_ioctl_desc_t *ioctl;
|
||||
drm_ioctl_t *func;
|
||||
|
||||
atomic_inc(&dev->ioctl_count);
|
||||
atomic_inc(&dev->total_ioctl);
|
||||
++priv->ioctl_count;
|
||||
|
||||
if (nr >= MGA_IOCTL_COUNT) {
|
||||
retcode = -EINVAL;
|
||||
} else {
|
||||
ioctl = &mga_ioctls[nr];
|
||||
func = ioctl->func;
|
||||
|
||||
if (!func) {
|
||||
DRM_DEBUG("no function: pid = %d, cmd = 0x%02x,"
|
||||
" nr = 0x%02x, dev 0x%x, auth = %d\n",
|
||||
current->pid, cmd, nr, dev->device,
|
||||
priv->authenticated);
|
||||
retcode = -EINVAL;
|
||||
} else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN))
|
||||
|| (ioctl->auth_needed && !priv->authenticated)) {
|
||||
retcode = -EACCES;
|
||||
} else {
|
||||
retcode = (func)(inode, filp, cmd, arg);
|
||||
}
|
||||
}
|
||||
|
||||
atomic_dec(&dev->ioctl_count);
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int mga_unlock(struct inode *inode, struct file *filp, unsigned int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_lock_t lock;
|
||||
|
||||
if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
|
||||
return -EFAULT;
|
||||
|
||||
if (lock.context == DRM_KERNEL_CONTEXT) {
|
||||
DRM_ERROR("Process %d using kernel context %d\n",
|
||||
current->pid, lock.context);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
atomic_inc(&dev->total_unlocks);
|
||||
if (_DRM_LOCK_IS_CONT(dev->lock.hw_lock->lock))
|
||||
atomic_inc(&dev->total_contends);
|
||||
drm_lock_transfer(dev, &dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT);
|
||||
mga_dma_schedule(dev, 1);
|
||||
|
||||
if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
|
||||
DRM_KERNEL_CONTEXT)) DRM_ERROR("\n");
|
||||
|
||||
unblock_all_signals();
|
||||
return 0;
|
||||
}
|
||||
#include "drm_drv.h"
|
||||
|
|
|
|||
772
linux/mga_drv.h
772
linux/mga_drv.h
|
|
@ -1,4 +1,4 @@
|
|||
/* mga_drv.h -- Private header for the Matrox g200/g400 driver -*- linux-c -*-
|
||||
/* mga_drv.h -- Private header for the Matrox G200/G400 driver -*- linux-c -*-
|
||||
* Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
|
||||
*
|
||||
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
||||
|
|
@ -19,18 +19,17 @@
|
|||
* 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
|
||||
* VA LINUX SYSTEMS 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: Rickard E. (Rik) Faith <faith@valinux.com>
|
||||
* Jeff Hartmann <jhartmann@valinux.com>
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#ifndef _MGA_DRV_H_
|
||||
#define _MGA_DRV_H_
|
||||
#ifndef __MGA_DRV_H__
|
||||
#define __MGA_DRV_H__
|
||||
|
||||
#define MGA_BUF_IN_USE 0
|
||||
#define MGA_BUF_SWAP_PENDING 1
|
||||
|
|
@ -38,7 +37,7 @@
|
|||
#define MGA_BUF_NEEDS_OVERFLOW 3
|
||||
|
||||
typedef struct {
|
||||
long buffer_status; /* long req'd for set_bit() --RR */
|
||||
u32 buffer_status;
|
||||
int num_dwords;
|
||||
int max_dwords;
|
||||
u32 *current_dma_ptr;
|
||||
|
|
@ -49,22 +48,57 @@ typedef struct {
|
|||
int idx;
|
||||
} drm_mga_prim_buf_t;
|
||||
|
||||
typedef struct _drm_mga_freelist {
|
||||
__volatile__ unsigned int age;
|
||||
|
||||
enum {
|
||||
MGA_DMA_IDLE, /* Primary DMA stream is idle */
|
||||
MGA_DMA_FLUSH, /* Flush primary DMA stream */
|
||||
MGA_DMA_WRAP /* Primary DMA has been wrapped */
|
||||
};
|
||||
|
||||
typedef struct drm_mga_primary_buffer {
|
||||
u8 *start;
|
||||
u8 *end;
|
||||
int size;
|
||||
|
||||
volatile u32 *head;
|
||||
u32 tail;
|
||||
u32 wrap;
|
||||
int space;
|
||||
|
||||
unsigned long status_page;
|
||||
volatile u32 *status;
|
||||
|
||||
u32 last_flush;
|
||||
u32 low_mark;
|
||||
u32 mid_mark;
|
||||
u32 high_mark;
|
||||
|
||||
unsigned long state;
|
||||
} drm_mga_primary_buffer_t;
|
||||
|
||||
|
||||
typedef struct drm_mga_freelist {
|
||||
struct drm_mga_freelist *next;
|
||||
struct drm_mga_freelist *prev;
|
||||
volatile unsigned int age;
|
||||
drm_buf_t *buf;
|
||||
struct _drm_mga_freelist *next;
|
||||
struct _drm_mga_freelist *prev;
|
||||
} drm_mga_freelist_t;
|
||||
|
||||
typedef struct {
|
||||
drm_mga_freelist_t *list_entry;
|
||||
int discard;
|
||||
int dispatched;
|
||||
} drm_mga_buf_priv_t;
|
||||
|
||||
#define MGA_IN_DISPATCH 0
|
||||
#define MGA_IN_FLUSH 1
|
||||
#define MGA_IN_WAIT 2
|
||||
#define MGA_IN_GETBUF 3
|
||||
|
||||
typedef struct _drm_mga_private {
|
||||
long dispatch_status; /* long req'd for set_bit() --RR */
|
||||
typedef struct drm_mga_private {
|
||||
u32 dispatch_status;
|
||||
unsigned int next_prim_age;
|
||||
__volatile__ unsigned int last_prim_age;
|
||||
volatile unsigned int last_prim_age;
|
||||
int reserved_map_idx;
|
||||
int buffer_map_idx;
|
||||
drm_mga_sarea_t *sarea_priv;
|
||||
|
|
@ -92,97 +126,112 @@ typedef struct _drm_mga_private {
|
|||
drm_mga_prim_buf_t *last_prim;
|
||||
drm_mga_prim_buf_t *current_prim;
|
||||
int current_prim_idx;
|
||||
drm_mga_freelist_t *head;
|
||||
drm_mga_freelist_t *tail;
|
||||
wait_queue_head_t flush_queue; /* Processes waiting until flush */
|
||||
wait_queue_head_t wait_queue; /* Processes waiting until interrupt */
|
||||
wait_queue_head_t buf_queue; /* Processes waiting for a free buf */
|
||||
/* Some validated register values:
|
||||
*/
|
||||
u32 mAccess;
|
||||
|
||||
|
||||
drm_mga_primary_buffer_t prim;
|
||||
|
||||
unsigned int warp_pipe;
|
||||
unsigned long warp_pipe_phys[MGA_MAX_WARP_PIPES];
|
||||
|
||||
drm_mga_freelist_t *head;
|
||||
drm_mga_freelist_t *tail;
|
||||
|
||||
int usec_timeout;
|
||||
|
||||
u32 clear_cmd;
|
||||
|
||||
unsigned int fb_cpp;
|
||||
unsigned int front_offset;
|
||||
unsigned int front_pitch;
|
||||
unsigned int back_offset;
|
||||
unsigned int back_pitch;
|
||||
|
||||
unsigned int depth_cpp;
|
||||
unsigned int depth_offset;
|
||||
unsigned int depth_pitch;
|
||||
|
||||
unsigned int texture_offset;
|
||||
unsigned int texture_size;
|
||||
|
||||
drm_map_t *sarea;
|
||||
drm_map_t *fb;
|
||||
drm_map_t *mmio;
|
||||
drm_map_t *warp;
|
||||
drm_map_t *primary;
|
||||
drm_map_t *buffers;
|
||||
drm_map_t *agp_textures;
|
||||
} drm_mga_private_t;
|
||||
|
||||
/* mga_drv.c */
|
||||
extern int mga_version(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_open(struct inode *inode, struct file *filp);
|
||||
extern int mga_release(struct inode *inode, struct file *filp);
|
||||
extern int mga_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_unlock(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_version( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_open( struct inode *inode, struct file *filp );
|
||||
extern int mga_release( struct inode *inode, struct file *filp );
|
||||
extern int mga_ioctl( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_lock( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_unlock( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
/* mga_dma.c */
|
||||
extern int mga_dma_schedule(drm_device_t *dev, int locked);
|
||||
extern int mga_dma(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_irq_install(drm_device_t *dev, int irq);
|
||||
extern int mga_irq_uninstall(drm_device_t *dev);
|
||||
extern int mga_control(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_lock(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_dma_init( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_dma_flush( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_dma_reset( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_control( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
|
||||
/* mga_dma_init does init and release */
|
||||
extern int mga_dma_init(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_dma_cleanup(drm_device_t *dev);
|
||||
extern int mga_flush_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern unsigned int mga_create_sync_tag(drm_device_t *dev);
|
||||
extern drm_buf_t *mga_freelist_get(drm_device_t *dev);
|
||||
extern int mga_freelist_put(drm_device_t *dev, drm_buf_t *buf);
|
||||
extern int mga_advance_primary(drm_device_t *dev);
|
||||
extern void mga_reclaim_buffers(drm_device_t *dev, pid_t pid);
|
||||
extern int mga_do_wait_for_idle( drm_mga_private_t *dev_priv );
|
||||
extern int mga_do_dma_idle( drm_mga_private_t *dev_priv );
|
||||
extern int mga_do_dma_reset( drm_mga_private_t *dev_priv );
|
||||
extern int mga_do_engine_reset( drm_mga_private_t *dev_priv );
|
||||
extern int mga_do_cleanup_dma( drm_device_t *dev );
|
||||
|
||||
extern int mga_dma_schedule( drm_device_t *dev, int locked );
|
||||
extern void mga_dma_wrap_or_wait( drm_mga_private_t *dev_priv, int n );
|
||||
extern int mga_irq_uninstall( drm_device_t *dev );
|
||||
|
||||
/* mga_bufs.c */
|
||||
extern int mga_addbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_infobufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_markbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_freebufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_mapbufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_addmap(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
/* mga_state.c */
|
||||
extern int mga_clear_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_swap_bufs(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_iload(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_vertex(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_indices(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_blit(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
/* mga_context.c */
|
||||
extern int mga_resctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_addctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_modctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_getctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_switchctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_newctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_rmctx(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
extern int mga_dma_clear( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_dma_swap( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
#if 0
|
||||
extern int mga_clear_bufs( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_swap_bufs( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_iload( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_vertex( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
extern int mga_indices( struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg );
|
||||
#endif
|
||||
|
||||
extern int mga_context_switch(drm_device_t *dev, int old, int new);
|
||||
extern int mga_context_switch_complete(drm_device_t *dev, int new);
|
||||
/* mga_warp.c */
|
||||
extern int mga_warp_install_microcode( drm_device_t *dev );
|
||||
extern int mga_warp_init( drm_device_t *dev );
|
||||
|
||||
#define mga_flush_write_combine() mb()
|
||||
|
||||
|
||||
#define MGA_BASE( reg ) ((u32)(dev_priv->mmio->handle))
|
||||
#define MGA_ADDR( reg ) (MGA_BASE(reg) + reg)
|
||||
|
||||
#define MGA_DEREF( reg ) *(__volatile__ int *)MGA_ADDR( reg )
|
||||
#define MGA_READ( reg ) MGA_DEREF( reg )
|
||||
#define MGA_WRITE( reg, val ) do { MGA_DEREF( reg ) = val; } while (0)
|
||||
|
||||
typedef enum {
|
||||
TT_GENERAL,
|
||||
TT_BLIT,
|
||||
|
|
@ -190,11 +239,6 @@ typedef enum {
|
|||
TT_VERTEX
|
||||
} transferType_t;
|
||||
|
||||
typedef struct {
|
||||
drm_mga_freelist_t *my_freelist;
|
||||
int discard;
|
||||
int dispatched;
|
||||
} drm_mga_buf_priv_t;
|
||||
|
||||
#define DWGREG0 0x1c00
|
||||
#define DWGREG0_END 0x1dff
|
||||
|
|
@ -202,11 +246,10 @@ typedef struct {
|
|||
#define DWGREG1_END 0x2dff
|
||||
|
||||
#define ISREG0(r) (r >= DWGREG0 && r <= DWGREG0_END)
|
||||
#define ADRINDEX0(r) (u8)((r - DWGREG0) >> 2)
|
||||
#define ADRINDEX1(r) (u8)(((r - DWGREG1) >> 2) | 0x80)
|
||||
#define ADRINDEX(r) (ISREG0(r) ? ADRINDEX0(r) : ADRINDEX1(r))
|
||||
#define DMAREG0(r) (u8)((r - DWGREG0) >> 2)
|
||||
#define DMAREG1(r) (u8)(((r - DWGREG1) >> 2) | 0x80)
|
||||
#define DMAREG(r) (ISREG0(r) ? DMAREG0(r) : DMAREG1(r))
|
||||
|
||||
#define MGA_VERBOSE 0
|
||||
#define MGA_NUM_PRIM_BUFS 8
|
||||
|
||||
#define PRIMLOCALS u8 tempIndex[4]; u32 *dma_ptr; u32 phys_head; \
|
||||
|
|
@ -303,148 +346,399 @@ drm_mga_prim_buf_t *tmp_buf = \
|
|||
} \
|
||||
}while (0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MGA_VERBOSE 1
|
||||
|
||||
#define DMA_LOCALS unsigned int write; volatile u8 *prim;
|
||||
#define DMA_BLOCK_SIZE (5 * sizeof(u32))
|
||||
|
||||
#define BEGIN_DMA( n ) \
|
||||
do { \
|
||||
if ( MGA_VERBOSE ) { \
|
||||
DRM_INFO( "BEGIN_DMA( %d ) in %s\n", \
|
||||
(n), __FUNCTION__ ); \
|
||||
} \
|
||||
if ( dev_priv->prim.space < (int)((n) * DMA_BLOCK_SIZE) ) { \
|
||||
mga_dma_wrap_or_wait( dev_priv, \
|
||||
(n) * DMA_BLOCK_SIZE ); \
|
||||
} \
|
||||
prim = dev_priv->prim.start; \
|
||||
write = dev_priv->prim.tail; \
|
||||
} while (0)
|
||||
|
||||
#define ADVANCE_DMA() \
|
||||
do { \
|
||||
dev_priv->prim.space -= (write - dev_priv->prim.tail); \
|
||||
dev_priv->prim.tail = write; \
|
||||
if ( MGA_VERBOSE ) { \
|
||||
DRM_INFO( "ADVANCE_DMA() tail=0x%05x sp=0x%x s=%lx\n", \
|
||||
write, dev_priv->prim.space, \
|
||||
dev_priv->prim.state ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define MAYBE_FLUSH_DMA() \
|
||||
do { \
|
||||
if ( dev_priv->prim.wrap && MGA_DMA_IS_IDLE( dev_priv ) ) { \
|
||||
DRM_INFO( "MAYBE_FLUSH_DMA() wrap at 0x%x\n", \
|
||||
dev_priv->prim.wrap ); \
|
||||
mga_do_dma_wrap( dev_priv ); \
|
||||
mga_update_primary_snapshot( dev_priv ); \
|
||||
} else if ( dev_priv->prim.tail - dev_priv->prim.last_flush >= \
|
||||
dev_priv->prim.mid_mark && \
|
||||
MGA_DMA_IS_IDLE( dev_priv ) ) { \
|
||||
DRM_INFO( "MAYBE_FLUSH_DMA() wm hit 0x%x >= 0x%x\n", \
|
||||
dev_priv->prim.tail - \
|
||||
dev_priv->prim.last_flush, \
|
||||
dev_priv->prim.mid_mark ); \
|
||||
mga_do_dma_flush( dev_priv ); \
|
||||
mga_update_primary_snapshot( dev_priv ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* Never use this, always use DMA_BLOCK(...) for primary DMA output.
|
||||
*/
|
||||
#define DMA_WRITE( offset, val ) \
|
||||
do { \
|
||||
if ( MGA_VERBOSE ) { \
|
||||
DRM_INFO( " DMA_WRITE( 0x%08x ) at 0x%04x\n", \
|
||||
(u32)(val), write + (offset) * sizeof(u32) ); \
|
||||
} \
|
||||
*(volatile u32 *)(prim + write + (offset) * sizeof(u32)) = val; \
|
||||
} while (0)
|
||||
|
||||
#define DMA_BLOCK( reg0, val0, reg1, val1, reg2, val2, reg3, val3 ) \
|
||||
do { \
|
||||
DMA_WRITE( 0, ((DMAREG( reg0 ) << 0) | \
|
||||
(DMAREG( reg1 ) << 8) | \
|
||||
(DMAREG( reg2 ) << 16) | \
|
||||
(DMAREG( reg3 ) << 24)) ); \
|
||||
DMA_WRITE( 1, val0 ); \
|
||||
DMA_WRITE( 2, val1 ); \
|
||||
DMA_WRITE( 3, val2 ); \
|
||||
DMA_WRITE( 4, val3 ); \
|
||||
write += DMA_BLOCK_SIZE; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define MGA_ENGINE_IDLE_MASK (MGA_SOFTRAPEN | \
|
||||
MGA_DWGENGSTS | \
|
||||
MGA_ENDPRDMASTS)
|
||||
#define MGA_DMA_IDLE_MASK (MGA_SOFTRAPEN | \
|
||||
MGA_ENDPRDMASTS)
|
||||
|
||||
#define MGA_DMA_SOFTRAP_SIZE DMA_BLOCK_SIZE
|
||||
|
||||
#define MGA_DMA_IS_IDLE( dev_priv ) test_bit( MGA_DMA_IDLE, \
|
||||
&dev_priv->prim.state )
|
||||
|
||||
|
||||
#define MGA_EMIT_STATE( dev_priv, dirty ) \
|
||||
do { \
|
||||
if ( (dirty) & ~MGA_UPLOAD_CLIPRECTS ) { \
|
||||
if ( dev_priv->chipset == MGA_CARD_TYPE_G400 ) { \
|
||||
mga_g400_emit_state( dev_priv ); \
|
||||
} else { \
|
||||
mga_g200_emit_state( dev_priv ); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* A reduced set of the mga registers.
|
||||
*/
|
||||
|
||||
#define MGAREG_MGA_EXEC 0x0100
|
||||
#define MGAREG_ALPHACTRL 0x2c7c
|
||||
#define MGAREG_AR0 0x1c60
|
||||
#define MGAREG_AR1 0x1c64
|
||||
#define MGAREG_AR2 0x1c68
|
||||
#define MGAREG_AR3 0x1c6c
|
||||
#define MGAREG_AR4 0x1c70
|
||||
#define MGAREG_AR5 0x1c74
|
||||
#define MGAREG_AR6 0x1c78
|
||||
#define MGAREG_CXBNDRY 0x1c80
|
||||
#define MGAREG_CXLEFT 0x1ca0
|
||||
#define MGAREG_CXRIGHT 0x1ca4
|
||||
#define MGAREG_DMAPAD 0x1c54
|
||||
#define MGAREG_DSTORG 0x2cb8
|
||||
#define MGAREG_DWGCTL 0x1c00
|
||||
#define MGAREG_DWGSYNC 0x2c4c
|
||||
#define MGAREG_FCOL 0x1c24
|
||||
#define MGAREG_FIFOSTATUS 0x1e10
|
||||
#define MGAREG_FOGCOL 0x1cf4
|
||||
#define MGAREG_FXBNDRY 0x1c84
|
||||
#define MGAREG_FXLEFT 0x1ca8
|
||||
#define MGAREG_FXRIGHT 0x1cac
|
||||
#define MGAREG_ICLEAR 0x1e18
|
||||
#define MGAREG_IEN 0x1e1c
|
||||
#define MGAREG_LEN 0x1c5c
|
||||
#define MGAREG_MACCESS 0x1c04
|
||||
#define MGAREG_PITCH 0x1c8c
|
||||
#define MGAREG_PLNWT 0x1c1c
|
||||
#define MGAREG_PRIMADDRESS 0x1e58
|
||||
#define MGAREG_PRIMEND 0x1e5c
|
||||
#define MGAREG_PRIMPTR 0x1e50
|
||||
#define MGAREG_SECADDRESS 0x2c40
|
||||
#define MGAREG_SECEND 0x2c44
|
||||
#define MGAREG_SETUPADDRESS 0x2cd0
|
||||
#define MGAREG_SETUPEND 0x2cd4
|
||||
#define MGAREG_SGN 0x1c58
|
||||
#define MGAREG_SOFTRAP 0x2c48
|
||||
#define MGAREG_SRCORG 0x2cb4
|
||||
#define MGAREG_STATUS 0x1e14
|
||||
#define MGAREG_STENCIL 0x2cc8
|
||||
#define MGAREG_STENCILCTL 0x2ccc
|
||||
#define MGAREG_TDUALSTAGE0 0x2cf8
|
||||
#define MGAREG_TDUALSTAGE1 0x2cfc
|
||||
#define MGAREG_TEXBORDERCOL 0x2c5c
|
||||
#define MGAREG_TEXCTL 0x2c30
|
||||
#define MGAREG_TEXCTL2 0x2c3c
|
||||
#define MGAREG_TEXFILTER 0x2c58
|
||||
#define MGAREG_TEXHEIGHT 0x2c2c
|
||||
#define MGAREG_TEXORG 0x2c24
|
||||
#define MGAREG_TEXORG1 0x2ca4
|
||||
#define MGAREG_TEXORG2 0x2ca8
|
||||
#define MGAREG_TEXORG3 0x2cac
|
||||
#define MGAREG_TEXORG4 0x2cb0
|
||||
#define MGAREG_TEXTRANS 0x2c34
|
||||
#define MGAREG_TEXTRANSHIGH 0x2c38
|
||||
#define MGAREG_TEXWIDTH 0x2c28
|
||||
#define MGAREG_WACCEPTSEQ 0x1dd4
|
||||
#define MGAREG_WCODEADDR 0x1e6c
|
||||
#define MGAREG_WFLAG 0x1dc4
|
||||
#define MGAREG_WFLAG1 0x1de0
|
||||
#define MGAREG_WFLAGNB 0x1e64
|
||||
#define MGAREG_WFLAGNB1 0x1e08
|
||||
#define MGAREG_WGETMSB 0x1dc8
|
||||
#define MGAREG_WIADDR 0x1dc0
|
||||
#define MGAREG_WIADDR2 0x1dd8
|
||||
#define MGAREG_WMISC 0x1e70
|
||||
#define MGAREG_WVRTXSZ 0x1dcc
|
||||
#define MGAREG_YBOT 0x1c9c
|
||||
#define MGAREG_YDST 0x1c90
|
||||
#define MGAREG_YDSTLEN 0x1c88
|
||||
#define MGAREG_YDSTORG 0x1c94
|
||||
#define MGAREG_YTOP 0x1c98
|
||||
#define MGAREG_ZORG 0x1c0c
|
||||
#define MGA_ALPHACTRL 0x2c7c
|
||||
#define MGA_AR0 0x1c60
|
||||
#define MGA_AR1 0x1c64
|
||||
#define MGA_AR2 0x1c68
|
||||
#define MGA_AR3 0x1c6c
|
||||
#define MGA_AR4 0x1c70
|
||||
#define MGA_AR5 0x1c74
|
||||
#define MGA_AR6 0x1c78
|
||||
|
||||
#define MGA_CXBNDRY 0x1c80
|
||||
#define MGA_CXLEFT 0x1ca0
|
||||
#define MGA_CXRIGHT 0x1ca4
|
||||
|
||||
#define MGA_DMAPAD 0x1c54
|
||||
#define MGA_DSTORG 0x2cb8
|
||||
#define MGA_DWGCTL 0x1c00
|
||||
# define MGA_OPCOD_MASK (15 << 0)
|
||||
# define MGA_OPCOD_TRAP (4 << 0)
|
||||
# define MGA_OPCOD_TEXTURE_TRAP (6 << 0)
|
||||
# define MGA_OPCOD_BITBLT (8 << 0)
|
||||
# define MGA_OPCOD_ILOAD (9 << 0)
|
||||
# define MGA_ATYPE_MASK (7 << 4)
|
||||
# define MGA_ATYPE_RPL (0 << 4)
|
||||
# define MGA_ATYPE_RSTR (1 << 4)
|
||||
# define MGA_ATYPE_ZI (3 << 4)
|
||||
# define MGA_ATYPE_BLK (4 << 4)
|
||||
# define MGA_ATYPE_I (7 << 4)
|
||||
# define MGA_LINEAR (1 << 7)
|
||||
# define MGA_ZMODE_MASK (7 << 8)
|
||||
# define MGA_ZMODE_NOZCMP (0 << 8)
|
||||
# define MGA_ZMODE_ZE (2 << 8)
|
||||
# define MGA_ZMODE_ZNE (3 << 8)
|
||||
# define MGA_ZMODE_ZLT (4 << 8)
|
||||
# define MGA_ZMODE_ZLTE (5 << 8)
|
||||
# define MGA_ZMODE_ZGT (6 << 8)
|
||||
# define MGA_ZMODE_ZGTE (7 << 8)
|
||||
# define MGA_SOLID (1 << 11)
|
||||
# define MGA_ARZERO (1 << 12)
|
||||
# define MGA_SGNZERO (1 << 13)
|
||||
# define MGA_SHIFTZERO (1 << 14)
|
||||
# define MGA_BOP_MASK (15 << 16)
|
||||
# define MGA_BOP_ZERO (0 << 16)
|
||||
# define MGA_BOP_DST (10 << 16)
|
||||
# define MGA_BOP_SRC (12 << 16)
|
||||
# define MGA_BOP_ONE (15 << 16)
|
||||
# define MGA_TRANS_SHIFT 20
|
||||
# define MGA_TRANS_MASK (15 << 20)
|
||||
# define MGA_BLTMOD_MASK (15 << 25)
|
||||
# define MGA_BLTMOD_BMONOLEF (0 << 25)
|
||||
# define MGA_BLTMOD_BMONOWF (4 << 25)
|
||||
# define MGA_BLTMOD_PLAN (1 << 25)
|
||||
# define MGA_BLTMOD_BFCOL (2 << 25)
|
||||
# define MGA_BLTMOD_BU32BGR (3 << 25)
|
||||
# define MGA_BLTMOD_BU32RGB (7 << 25)
|
||||
# define MGA_BLTMOD_BU24BGR (11 << 25)
|
||||
# define MGA_BLTMOD_BU24RGB (15 << 25)
|
||||
# define MGA_PATTERN (1 << 29)
|
||||
# define MGA_TRANSC (1 << 30)
|
||||
# define MGA_CLIPDIS (1 << 31)
|
||||
#define MGA_DWGSYNC 0x2c4c
|
||||
|
||||
#define MGA_FCOL 0x1c24
|
||||
#define MGA_FIFOSTATUS 0x1e10
|
||||
#define MGA_FOGCOL 0x1cf4
|
||||
#define MGA_FXBNDRY 0x1c84
|
||||
#define MGA_FXLEFT 0x1ca8
|
||||
#define MGA_FXRIGHT 0x1cac
|
||||
|
||||
#define MGA_ICLEAR 0x1e18
|
||||
# define MGA_SOFTRAPICLR (1 << 0)
|
||||
#define MGA_IEN 0x1e1c
|
||||
# define MGA_SOFTRAPIEN (1 << 0)
|
||||
|
||||
#define MGA_LEN 0x1c5c
|
||||
|
||||
#define MGA_MACCESS 0x1c04
|
||||
|
||||
#define MGA_PITCH 0x1c8c
|
||||
#define MGA_PLNWT 0x1c1c
|
||||
#define MGA_PRIMADDRESS 0x1e58
|
||||
# define MGA_DMA_GENERAL (0 << 0)
|
||||
# define MGA_DMA_BLIT (1 << 0)
|
||||
# define MGA_DMA_VECTOR (2 << 0)
|
||||
# define MGA_DMA_VERTEX (3 << 0)
|
||||
#define MGA_PRIMEND 0x1e5c
|
||||
# define MGA_PRIMNOSTART (1 << 0)
|
||||
# define MGA_PAGPXFER (1 << 1)
|
||||
#define MGA_PRIMPTR 0x1e50
|
||||
# define MGA_PRIMPTREN0 (1 << 0)
|
||||
# define MGA_PRIMPTREN1 (1 << 1)
|
||||
|
||||
#define MGA_RST 0x1e40
|
||||
# define MGA_SOFTRESET (1 << 0)
|
||||
# define MGA_SOFTEXTRST (1 << 1)
|
||||
|
||||
#define MGA_SECADDRESS 0x2c40
|
||||
#define MGA_SECEND 0x2c44
|
||||
#define MGA_SETUPADDRESS 0x2cd0
|
||||
#define MGA_SETUPEND 0x2cd4
|
||||
#define MGA_SOFTRAP 0x2c48
|
||||
#define MGA_SRCORG 0x2cb4
|
||||
#define MGA_STATUS 0x1e14
|
||||
# define MGA_SOFTRAPEN (1 << 0)
|
||||
# define MGA_DWGENGSTS (1 << 16)
|
||||
# define MGA_ENDPRDMASTS (1 << 17)
|
||||
#define MGA_STENCIL 0x2cc8
|
||||
#define MGA_STENCILCTL 0x2ccc
|
||||
|
||||
#define MGA_TDUALSTAGE0 0x2cf8
|
||||
#define MGA_TDUALSTAGE1 0x2cfc
|
||||
#define MGA_TEXBORDERCOL 0x2c5c
|
||||
#define MGA_TEXCTL 0x2c30
|
||||
#define MGA_TEXCTL2 0x2c3c
|
||||
# define MGA_DUALTEX (1 << 7)
|
||||
# define MGA_G400_TC2_MAGIC (1 << 15)
|
||||
# define MGA_MAP1_ENABLE (1 << 31)
|
||||
#define MGA_TEXFILTER 0x2c58
|
||||
#define MGA_TEXHEIGHT 0x2c2c
|
||||
#define MGA_TEXORG 0x2c24
|
||||
# define MGA_TEXORGMAP_MASK (1 << 0)
|
||||
# define MGA_TEXORGMAP_FB (0 << 0)
|
||||
# define MGA_TEXORGMAP_SYSMEM (1 << 0)
|
||||
# define MGA_TEXORGACC_MASK (1 << 1)
|
||||
# define MGA_TEXORGACC_PCI (0 << 1)
|
||||
# define MGA_TEXORGACC_AGP (1 << 1)
|
||||
#define MGA_TEXORG1 0x2ca4
|
||||
#define MGA_TEXORG2 0x2ca8
|
||||
#define MGA_TEXORG3 0x2cac
|
||||
#define MGA_TEXORG4 0x2cb0
|
||||
#define MGA_TEXTRANS 0x2c34
|
||||
#define MGA_TEXTRANSHIGH 0x2c38
|
||||
#define MGA_TEXWIDTH 0x2c28
|
||||
|
||||
#define MGA_WACCEPTSEQ 0x1dd4
|
||||
#define MGA_WCODEADDR 0x1e6c
|
||||
#define MGA_WFLAG 0x1dc4
|
||||
#define MGA_WFLAG1 0x1de0
|
||||
#define MGA_WFLAGNB 0x1e64
|
||||
#define MGA_WFLAGNB1 0x1e08
|
||||
#define MGA_WGETMSB 0x1dc8
|
||||
#define MGA_WIADDR 0x1dc0
|
||||
#define MGA_WIADDR2 0x1dd8
|
||||
# define MGA_WMODE_SUSPEND (0 << 0)
|
||||
# define MGA_WMODE_RESUME (1 << 0)
|
||||
# define MGA_WMODE_JUMP (2 << 0)
|
||||
# define MGA_WMODE_START (3 << 0)
|
||||
# define MGA_WAGP_ENABLE (1 << 2)
|
||||
#define MGA_WMISC 0x1e70
|
||||
# define MGA_WUCODECACHE_ENABLE (1 << 0)
|
||||
# define MGA_WMASTER_ENABLE (1 << 1)
|
||||
# define MGA_WCACHEFLUSH_ENABLE (1 << 3)
|
||||
#define MGA_WVRTXSZ 0x1dcc
|
||||
|
||||
#define MGA_YBOT 0x1c9c
|
||||
#define MGA_YDST 0x1c90
|
||||
#define MGA_YDSTLEN 0x1c88
|
||||
#define MGA_YDSTORG 0x1c94
|
||||
#define MGA_YTOP 0x1c98
|
||||
|
||||
#define MGA_ZORG 0x1c0c
|
||||
|
||||
/* This finishes the current batch of commands
|
||||
*/
|
||||
#define MGA_EXEC 0x0100
|
||||
|
||||
/* Warp registers
|
||||
*/
|
||||
#define MGA_WR0 0x2d00
|
||||
#define MGA_WR1 0x2d04
|
||||
#define MGA_WR2 0x2d08
|
||||
#define MGA_WR3 0x2d0c
|
||||
#define MGA_WR4 0x2d10
|
||||
#define MGA_WR5 0x2d14
|
||||
#define MGA_WR6 0x2d18
|
||||
#define MGA_WR7 0x2d1c
|
||||
#define MGA_WR8 0x2d20
|
||||
#define MGA_WR9 0x2d24
|
||||
#define MGA_WR10 0x2d28
|
||||
#define MGA_WR11 0x2d2c
|
||||
#define MGA_WR12 0x2d30
|
||||
#define MGA_WR13 0x2d34
|
||||
#define MGA_WR14 0x2d38
|
||||
#define MGA_WR15 0x2d3c
|
||||
#define MGA_WR16 0x2d40
|
||||
#define MGA_WR17 0x2d44
|
||||
#define MGA_WR18 0x2d48
|
||||
#define MGA_WR19 0x2d4c
|
||||
#define MGA_WR20 0x2d50
|
||||
#define MGA_WR21 0x2d54
|
||||
#define MGA_WR22 0x2d58
|
||||
#define MGA_WR23 0x2d5c
|
||||
#define MGA_WR24 0x2d60
|
||||
#define MGA_WR25 0x2d64
|
||||
#define MGA_WR26 0x2d68
|
||||
#define MGA_WR27 0x2d6c
|
||||
#define MGA_WR28 0x2d70
|
||||
#define MGA_WR29 0x2d74
|
||||
#define MGA_WR30 0x2d78
|
||||
#define MGA_WR31 0x2d7c
|
||||
#define MGA_WR32 0x2d80
|
||||
#define MGA_WR33 0x2d84
|
||||
#define MGA_WR34 0x2d88
|
||||
#define MGA_WR35 0x2d8c
|
||||
#define MGA_WR36 0x2d90
|
||||
#define MGA_WR37 0x2d94
|
||||
#define MGA_WR38 0x2d98
|
||||
#define MGA_WR39 0x2d9c
|
||||
#define MGA_WR40 0x2da0
|
||||
#define MGA_WR41 0x2da4
|
||||
#define MGA_WR42 0x2da8
|
||||
#define MGA_WR43 0x2dac
|
||||
#define MGA_WR44 0x2db0
|
||||
#define MGA_WR45 0x2db4
|
||||
#define MGA_WR46 0x2db8
|
||||
#define MGA_WR47 0x2dbc
|
||||
#define MGA_WR48 0x2dc0
|
||||
#define MGA_WR49 0x2dc4
|
||||
#define MGA_WR50 0x2dc8
|
||||
#define MGA_WR51 0x2dcc
|
||||
#define MGA_WR52 0x2dd0
|
||||
#define MGA_WR53 0x2dd4
|
||||
#define MGA_WR54 0x2dd8
|
||||
#define MGA_WR55 0x2ddc
|
||||
#define MGA_WR56 0x2de0
|
||||
#define MGA_WR57 0x2de4
|
||||
#define MGA_WR58 0x2de8
|
||||
#define MGA_WR59 0x2dec
|
||||
#define MGA_WR60 0x2df0
|
||||
#define MGA_WR61 0x2df4
|
||||
#define MGA_WR62 0x2df8
|
||||
#define MGA_WR63 0x2dfc
|
||||
# define MGA_G400_WR_MAGIC (1 << 6)
|
||||
# define MGA_G400_WR56_MAGIC 0x46480000 /* 12800.0f */
|
||||
|
||||
|
||||
#define MGA_ILOAD_ALIGN 64
|
||||
#define MGA_ILOAD_MASK (MGA_ILOAD_ALIGN - 1)
|
||||
|
||||
#define MGA_DWGCTL_FLUSH (MGA_OPCOD_TEXTURE_TRAP | \
|
||||
MGA_ATYPE_I | \
|
||||
MGA_ZMODE_NOZCMP | \
|
||||
MGA_ARZERO | \
|
||||
MGA_SGNZERO | \
|
||||
MGA_BOP_SRC | \
|
||||
(15 << MGA_TRANS_SHIFT))
|
||||
|
||||
#define MGA_DWGCTL_CLEAR (MGA_OPCOD_TRAP | \
|
||||
MGA_ZMODE_NOZCMP | \
|
||||
MGA_SOLID | \
|
||||
MGA_ARZERO | \
|
||||
MGA_SGNZERO | \
|
||||
MGA_SHIFTZERO | \
|
||||
MGA_BOP_SRC | \
|
||||
(0 << MGA_TRANS_SHIFT) | \
|
||||
MGA_BLTMOD_BMONOLEF | \
|
||||
MGA_TRANSC | \
|
||||
MGA_CLIPDIS)
|
||||
|
||||
#define MGA_DWGCTL_COPY (MGA_OPCOD_BITBLT | \
|
||||
MGA_ATYPE_RPL | \
|
||||
MGA_SGNZERO | \
|
||||
MGA_SHIFTZERO | \
|
||||
MGA_BOP_SRC | \
|
||||
(0 << MGA_TRANS_SHIFT) | \
|
||||
MGA_BLTMOD_BFCOL | \
|
||||
MGA_CLIPDIS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MGA_CLEAR_CMD (DC_opcod_trap | DC_arzero_enable | \
|
||||
DC_sgnzero_enable | DC_shftzero_enable | \
|
||||
(0xC << DC_bop_SHIFT) | DC_clipdis_enable | \
|
||||
DC_solid_enable | DC_transc_enable)
|
||||
|
||||
|
||||
#define MGA_COPY_CMD (DC_opcod_bitblt | DC_atype_rpl | DC_linear_xy | \
|
||||
DC_solid_disable | DC_arzero_disable | \
|
||||
DC_sgnzero_enable | DC_shftzero_enable | \
|
||||
(0xC << DC_bop_SHIFT) | DC_bltmod_bfcol | \
|
||||
DC_pattern_disable | DC_transc_disable | \
|
||||
DC_clipdis_enable) \
|
||||
|
||||
#define MGA_FLUSH_CMD (DC_opcod_texture_trap | (0xF << DC_trans_SHIFT) |\
|
||||
DC_arzero_enable | DC_sgnzero_enable | \
|
||||
DC_atype_i)
|
||||
|
||||
/* Warp registers */
|
||||
#define MGAREG_WR0 0x2d00
|
||||
#define MGAREG_WR1 0x2d04
|
||||
#define MGAREG_WR2 0x2d08
|
||||
#define MGAREG_WR3 0x2d0c
|
||||
#define MGAREG_WR4 0x2d10
|
||||
#define MGAREG_WR5 0x2d14
|
||||
#define MGAREG_WR6 0x2d18
|
||||
#define MGAREG_WR7 0x2d1c
|
||||
#define MGAREG_WR8 0x2d20
|
||||
#define MGAREG_WR9 0x2d24
|
||||
#define MGAREG_WR10 0x2d28
|
||||
#define MGAREG_WR11 0x2d2c
|
||||
#define MGAREG_WR12 0x2d30
|
||||
#define MGAREG_WR13 0x2d34
|
||||
#define MGAREG_WR14 0x2d38
|
||||
#define MGAREG_WR15 0x2d3c
|
||||
#define MGAREG_WR16 0x2d40
|
||||
#define MGAREG_WR17 0x2d44
|
||||
#define MGAREG_WR18 0x2d48
|
||||
#define MGAREG_WR19 0x2d4c
|
||||
#define MGAREG_WR20 0x2d50
|
||||
#define MGAREG_WR21 0x2d54
|
||||
#define MGAREG_WR22 0x2d58
|
||||
#define MGAREG_WR23 0x2d5c
|
||||
#define MGAREG_WR24 0x2d60
|
||||
#define MGAREG_WR25 0x2d64
|
||||
#define MGAREG_WR26 0x2d68
|
||||
#define MGAREG_WR27 0x2d6c
|
||||
#define MGAREG_WR28 0x2d70
|
||||
#define MGAREG_WR29 0x2d74
|
||||
#define MGAREG_WR30 0x2d78
|
||||
#define MGAREG_WR31 0x2d7c
|
||||
#define MGAREG_WR32 0x2d80
|
||||
#define MGAREG_WR33 0x2d84
|
||||
#define MGAREG_WR34 0x2d88
|
||||
#define MGAREG_WR35 0x2d8c
|
||||
#define MGAREG_WR36 0x2d90
|
||||
#define MGAREG_WR37 0x2d94
|
||||
#define MGAREG_WR38 0x2d98
|
||||
#define MGAREG_WR39 0x2d9c
|
||||
#define MGAREG_WR40 0x2da0
|
||||
#define MGAREG_WR41 0x2da4
|
||||
#define MGAREG_WR42 0x2da8
|
||||
#define MGAREG_WR43 0x2dac
|
||||
#define MGAREG_WR44 0x2db0
|
||||
#define MGAREG_WR45 0x2db4
|
||||
#define MGAREG_WR46 0x2db8
|
||||
#define MGAREG_WR47 0x2dbc
|
||||
#define MGAREG_WR48 0x2dc0
|
||||
#define MGAREG_WR49 0x2dc4
|
||||
#define MGAREG_WR50 0x2dc8
|
||||
#define MGAREG_WR51 0x2dcc
|
||||
#define MGAREG_WR52 0x2dd0
|
||||
#define MGAREG_WR53 0x2dd4
|
||||
#define MGAREG_WR54 0x2dd8
|
||||
#define MGAREG_WR55 0x2ddc
|
||||
#define MGAREG_WR56 0x2de0
|
||||
#define MGAREG_WR57 0x2de4
|
||||
#define MGAREG_WR58 0x2de8
|
||||
#define MGAREG_WR59 0x2dec
|
||||
#define MGAREG_WR60 0x2df0
|
||||
#define MGAREG_WR61 0x2df4
|
||||
#define MGAREG_WR62 0x2df8
|
||||
#define MGAREG_WR63 0x2dfc
|
||||
|
||||
#define PDEA_pagpxfer_enable 0x2
|
||||
|
||||
|
|
@ -500,12 +794,6 @@ drm_mga_prim_buf_t *tmp_buf = \
|
|||
#define DC_clipdis_enable 0x80000000
|
||||
|
||||
|
||||
#define SO_srcacc_pci 0x0
|
||||
#define SO_srcacc_agp 0x2
|
||||
#define SO_srcmap_fb 0x0
|
||||
#define SO_srcmap_sys 0x1
|
||||
|
||||
|
||||
#define SETADD_mode_vertlist 0x0
|
||||
|
||||
|
||||
|
|
|
|||
1278
linux/mga_state.c
1278
linux/mga_state.c
File diff suppressed because it is too large
Load diff
11645
linux/mga_ucode.h
Normal file
11645
linux/mga_ucode.h
Normal file
File diff suppressed because it is too large
Load diff
215
linux/mga_warp.c
Normal file
215
linux/mga_warp.c
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
/* mga_warp.c -- Matrox G200/G400 WARP engine management -*- linux-c -*-
|
||||
* Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
|
||||
*
|
||||
* 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
|
||||
* VA LINUX SYSTEMS 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:
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*/
|
||||
|
||||
#define __NO_VERSION__
|
||||
#include "mga.h"
|
||||
#include "drmP.h"
|
||||
#include "mga_drv.h"
|
||||
#include "mga_ucode.h"
|
||||
|
||||
|
||||
#define MGA_WARP_CODE_ALIGN 256 /* in bytes */
|
||||
|
||||
#define WARP_UCODE_SIZE( which ) \
|
||||
((sizeof(which) / MGA_WARP_CODE_ALIGN + 1) * MGA_WARP_CODE_ALIGN)
|
||||
|
||||
#define WARP_UCODE_INSTALL( which, where ) \
|
||||
do { \
|
||||
DRM_INFO( " pcbase = 0x%08lx vcbase = %p\n", pcbase, vcbase ); \
|
||||
dev_priv->warp_pipe_phys[where] = pcbase; \
|
||||
memcpy( vcbase, which, sizeof(which) ); \
|
||||
pcbase += WARP_UCODE_SIZE( which ); \
|
||||
vcbase += WARP_UCODE_SIZE( which ); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static unsigned int mga_warp_g400_microcode_size( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
size = ( WARP_UCODE_SIZE( warp_g400_tgz ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgza ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzs ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzsa ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzsaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_tgzsf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gz ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gza ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzs ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzsa ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzsaf ) +
|
||||
WARP_UCODE_SIZE( warp_g400_t2gzsf ) );
|
||||
|
||||
size = PAGE_ALIGN( size );
|
||||
|
||||
DRM_INFO( "G400 ucode size = %d bytes\n", size );
|
||||
return size;
|
||||
}
|
||||
|
||||
static unsigned int mga_warp_g200_microcode_size( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned int size;
|
||||
|
||||
size = ( WARP_UCODE_SIZE( warp_g200_tgz ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgza ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzaf ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzf ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzs ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzsa ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzsaf ) +
|
||||
WARP_UCODE_SIZE( warp_g200_tgzsf ) );
|
||||
|
||||
size = PAGE_ALIGN( size );
|
||||
|
||||
DRM_INFO( "G200 ucode size = %d bytes\n", size );
|
||||
return size;
|
||||
}
|
||||
|
||||
static int mga_warp_install_g400_microcode( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned char *vcbase = dev_priv->warp->handle;
|
||||
unsigned long pcbase = dev_priv->warp->offset;
|
||||
unsigned int size;
|
||||
|
||||
size = mga_warp_g400_microcode_size( dev_priv );
|
||||
if ( size > dev_priv->warp->size ) {
|
||||
DRM_ERROR( "microcode too large! (%u > %lu)\n",
|
||||
size, dev_priv->warp->size );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset( dev_priv->warp_pipe_phys, 0,
|
||||
sizeof(dev_priv->warp_pipe_phys) );
|
||||
|
||||
WARP_UCODE_INSTALL( warp_g400_tgz, MGA_WARP_TGZ );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzf, MGA_WARP_TGZF );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgza, MGA_WARP_TGZA );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzaf, MGA_WARP_TGZAF );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzs, MGA_WARP_TGZS );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzsf, MGA_WARP_TGZSF );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzsa, MGA_WARP_TGZSA );
|
||||
WARP_UCODE_INSTALL( warp_g400_tgzsaf, MGA_WARP_TGZSAF );
|
||||
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gz, MGA_WARP_T2GZ );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzf, MGA_WARP_T2GZF );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gza, MGA_WARP_T2GZA );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzaf, MGA_WARP_T2GZAF );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzs, MGA_WARP_T2GZS );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzsf, MGA_WARP_T2GZSF );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzsa, MGA_WARP_T2GZSA );
|
||||
WARP_UCODE_INSTALL( warp_g400_t2gzsaf, MGA_WARP_T2GZSAF );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mga_warp_install_g200_microcode( drm_mga_private_t *dev_priv )
|
||||
{
|
||||
unsigned char *vcbase = dev_priv->warp->handle;
|
||||
unsigned long pcbase = dev_priv->warp->offset;
|
||||
unsigned int size;
|
||||
|
||||
size = mga_warp_g200_microcode_size( dev_priv );
|
||||
if ( size > dev_priv->warp->size ) {
|
||||
DRM_ERROR( "microcode too large! (%u > %lu)\n",
|
||||
size, dev_priv->warp->size );
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset( dev_priv->warp_pipe_phys, 0,
|
||||
sizeof(dev_priv->warp_pipe_phys) );
|
||||
|
||||
WARP_UCODE_INSTALL( warp_g200_tgz, MGA_WARP_TGZ );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzf, MGA_WARP_TGZF );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgza, MGA_WARP_TGZA );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzaf, MGA_WARP_TGZAF );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzs, MGA_WARP_TGZS );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzsf, MGA_WARP_TGZSF );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzsa, MGA_WARP_TGZSA );
|
||||
WARP_UCODE_INSTALL( warp_g200_tgzsaf, MGA_WARP_TGZSAF );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mga_warp_install_microcode( drm_device_t *dev )
|
||||
{
|
||||
drm_mga_private_t *dev_priv = dev->dev_private;
|
||||
DRM_INFO( "%s\n", __FUNCTION__ );
|
||||
|
||||
switch ( dev_priv->chipset ) {
|
||||
case MGA_CARD_TYPE_G400:
|
||||
return mga_warp_install_g400_microcode( dev_priv );
|
||||
case MGA_CARD_TYPE_G200:
|
||||
return mga_warp_install_g200_microcode( dev_priv );
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
#define WMISC_EXPECTED (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
|
||||
|
||||
int mga_warp_init( drm_device_t *dev )
|
||||
{
|
||||
drm_mga_private_t *dev_priv = dev->dev_private;
|
||||
u32 wmisc;
|
||||
DRM_INFO( "%s\n", __FUNCTION__ );
|
||||
|
||||
/* FIXME: Get rid of these damned magic numbers...
|
||||
*/
|
||||
switch ( dev_priv->chipset ) {
|
||||
case MGA_CARD_TYPE_G400:
|
||||
MGA_WRITE( MGA_WIADDR2, MGA_WMODE_SUSPEND );
|
||||
MGA_WRITE( MGA_WGETMSB, 0x00000E00 );
|
||||
MGA_WRITE( MGA_WVRTXSZ, 0x00001807 );
|
||||
MGA_WRITE( MGA_WACCEPTSEQ, 0x18000000 );
|
||||
break;
|
||||
case MGA_CARD_TYPE_G200:
|
||||
MGA_WRITE( MGA_WIADDR, MGA_WMODE_SUSPEND );
|
||||
MGA_WRITE( MGA_WGETMSB, 0x1606 );
|
||||
MGA_WRITE( MGA_WVRTXSZ, 7 );
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
MGA_WRITE( MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
|
||||
MGA_WMASTER_ENABLE |
|
||||
MGA_WCACHEFLUSH_ENABLE) );
|
||||
wmisc = MGA_READ( MGA_WMISC );
|
||||
if ( wmisc != WMISC_EXPECTED ) {
|
||||
DRM_ERROR( "WARP engine config failed! 0x%x != 0x%x\n",
|
||||
wmisc, WMISC_EXPECTED );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
127
linux/r128_cce.c
127
linux/r128_cce.c
|
|
@ -85,6 +85,26 @@ static u32 r128_cce_microcode[] = {
|
|||
};
|
||||
|
||||
|
||||
#define DO_IOREMAP(_m) (_m)->handle = drm_ioremap((_m)->offset, (_m)->size)
|
||||
|
||||
#define DO_IOREMAPFREE(_m) \
|
||||
do { \
|
||||
if ((_m)->handle && (_m)->size) \
|
||||
drm_ioremapfree((_m)->handle, (_m)->size); \
|
||||
} while (0)
|
||||
|
||||
#define DO_FIND_MAP(_m, _o) \
|
||||
do { \
|
||||
int _i; \
|
||||
for (_i = 0; _i < dev->map_count; _i++) { \
|
||||
if (dev->maplist[_i]->offset == _o) { \
|
||||
_m = dev->maplist[_i]; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
int R128_READ_PLL(drm_device_t *dev, int addr)
|
||||
{
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
|
|
@ -203,7 +223,7 @@ static void r128_do_cce_flush( drm_r128_private_t *dev_priv )
|
|||
|
||||
/* Wait for the CCE to go idle.
|
||||
*/
|
||||
int r128_do_cce_idle( drm_r128_private_t *dev_priv )
|
||||
static int r128_do_cce_idle( drm_r128_private_t *dev_priv )
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -413,30 +433,13 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
|
|||
break;
|
||||
}
|
||||
|
||||
switch ( init->fb_bpp ) {
|
||||
case 16:
|
||||
dev_priv->color_fmt = R128_DATATYPE_RGB565;
|
||||
break;
|
||||
case 32:
|
||||
default:
|
||||
dev_priv->color_fmt = R128_DATATYPE_ARGB8888;
|
||||
break;
|
||||
}
|
||||
dev_priv->fb_bpp = init->fb_bpp;
|
||||
dev_priv->front_offset = init->front_offset;
|
||||
dev_priv->front_pitch = init->front_pitch;
|
||||
dev_priv->back_offset = init->back_offset;
|
||||
dev_priv->back_pitch = init->back_pitch;
|
||||
|
||||
switch ( init->depth_bpp ) {
|
||||
case 16:
|
||||
dev_priv->depth_fmt = R128_DATATYPE_RGB565;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
default:
|
||||
dev_priv->depth_fmt = R128_DATATYPE_ARGB8888;
|
||||
break;
|
||||
}
|
||||
dev_priv->depth_bpp = init->depth_bpp;
|
||||
dev_priv->depth_offset = init->depth_offset;
|
||||
dev_priv->depth_pitch = init->depth_pitch;
|
||||
dev_priv->span_offset = init->span_offset;
|
||||
|
|
@ -461,24 +464,29 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
|
|||
}
|
||||
}
|
||||
|
||||
DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
|
||||
DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
|
||||
DRM_FIND_MAP( dev_priv->cce_ring, init->ring_offset );
|
||||
DRM_FIND_MAP( dev_priv->ring_rptr, init->ring_rptr_offset );
|
||||
DRM_FIND_MAP( dev_priv->buffers, init->buffers_offset );
|
||||
DO_FIND_MAP( dev_priv->fb, init->fb_offset );
|
||||
DO_FIND_MAP( dev_priv->mmio, init->mmio_offset );
|
||||
DO_FIND_MAP( dev_priv->cce_ring, init->ring_offset );
|
||||
DO_FIND_MAP( dev_priv->ring_rptr, init->ring_rptr_offset );
|
||||
DO_FIND_MAP( dev_priv->buffers, init->buffers_offset );
|
||||
|
||||
if ( !dev_priv->is_pci ) {
|
||||
DRM_FIND_MAP( dev_priv->agp_textures,
|
||||
init->agp_textures_offset );
|
||||
DO_FIND_MAP( dev_priv->agp_textures,
|
||||
init->agp_textures_offset );
|
||||
}
|
||||
|
||||
dev_priv->sarea_priv =
|
||||
(drm_r128_sarea_t *)((u8 *)dev_priv->sarea->handle +
|
||||
init->sarea_priv_offset);
|
||||
|
||||
DRM_IOREMAP( dev_priv->cce_ring );
|
||||
DRM_IOREMAP( dev_priv->ring_rptr );
|
||||
DRM_IOREMAP( dev_priv->buffers );
|
||||
DO_IOREMAP( dev_priv->cce_ring );
|
||||
DO_IOREMAP( dev_priv->ring_rptr );
|
||||
DO_IOREMAP( dev_priv->buffers );
|
||||
#if 0
|
||||
if ( !dev_priv->is_pci ) {
|
||||
DO_IOREMAP( dev_priv->agp_textures );
|
||||
}
|
||||
#endif
|
||||
|
||||
dev_priv->ring.head = ((__volatile__ u32 *)
|
||||
dev_priv->ring_rptr->handle);
|
||||
|
|
@ -492,8 +500,6 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
|
|||
dev_priv->ring.tail_mask =
|
||||
(dev_priv->ring.size / sizeof(u32)) - 1;
|
||||
|
||||
dev_priv->ring.high_mark = 128;
|
||||
|
||||
dev_priv->sarea_priv->last_frame = 0;
|
||||
R128_WRITE( R128_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame );
|
||||
|
||||
|
|
@ -513,9 +519,14 @@ static int r128_do_cleanup_cce( drm_device_t *dev )
|
|||
if ( dev->dev_private ) {
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
|
||||
DRM_IOREMAPFREE( dev_priv->cce_ring );
|
||||
DRM_IOREMAPFREE( dev_priv->ring_rptr );
|
||||
DRM_IOREMAPFREE( dev_priv->buffers );
|
||||
DO_IOREMAPFREE( dev_priv->cce_ring );
|
||||
DO_IOREMAPFREE( dev_priv->ring_rptr );
|
||||
DO_IOREMAPFREE( dev_priv->buffers );
|
||||
#if 0
|
||||
if ( !dev_priv->is_pci ) {
|
||||
DO_IOREMAPFREE( dev_priv->agp_textures );
|
||||
}
|
||||
#endif
|
||||
|
||||
drm_free( dev->dev_private, sizeof(drm_r128_private_t),
|
||||
DRM_MEM_DRIVER );
|
||||
|
|
@ -553,8 +564,11 @@ int r128_cce_start( struct inode *inode, struct file *filp,
|
|||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
if ( dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4 ) {
|
||||
DRM_DEBUG( "%s while CCE running\n", __FUNCTION__ );
|
||||
return 0;
|
||||
|
|
@ -578,7 +592,11 @@ int r128_cce_stop( struct inode *inode, struct file *filp,
|
|||
int ret;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( copy_from_user( &stop, (drm_r128_init_t *)arg, sizeof(stop) ) )
|
||||
return -EFAULT;
|
||||
|
|
@ -620,8 +638,11 @@ int r128_cce_reset( struct inode *inode, struct file *filp,
|
|||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
if ( !dev_priv ) {
|
||||
DRM_DEBUG( "%s called before init done\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
|
|
@ -643,7 +664,11 @@ int r128_cce_idle( struct inode *inode, struct file *filp,
|
|||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( dev_priv->cce_running ) {
|
||||
r128_do_cce_flush( dev_priv );
|
||||
|
|
@ -659,7 +684,11 @@ int r128_engine_reset( struct inode *inode, struct file *filp,
|
|||
drm_device_t *dev = priv->dev;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return r128_do_engine_reset( dev );
|
||||
}
|
||||
|
|
@ -708,7 +737,11 @@ int r128_fullscreen( struct inode *inode, struct file *filp,
|
|||
drm_device_t *dev = priv->dev;
|
||||
drm_r128_fullscreen_t fs;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( copy_from_user( &fs, (drm_r128_fullscreen_t *)arg, sizeof(fs) ) )
|
||||
return -EFAULT;
|
||||
|
|
@ -899,11 +932,15 @@ int r128_cce_buffers( struct inode *inode, struct file *filp,
|
|||
int ret = 0;
|
||||
drm_dma_t d;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
|
||||
if ( copy_from_user( &d, (drm_dma_t *) arg, sizeof(d) ) )
|
||||
return -EFAULT;
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Please don't send us buffers.
|
||||
*/
|
||||
if ( d.send_count != 0 ) {
|
||||
|
|
|
|||
|
|
@ -142,12 +142,6 @@ typedef struct {
|
|||
} drm_r128_texture_regs_t;
|
||||
|
||||
|
||||
typedef struct drm_tex_region {
|
||||
unsigned char next, prev;
|
||||
unsigned char in_use;
|
||||
int age;
|
||||
} drm_tex_region_t;
|
||||
|
||||
typedef struct drm_r128_sarea {
|
||||
/* The channel for communication of state information to the kernel
|
||||
* on firing a vertex buffer.
|
||||
|
|
@ -218,10 +212,9 @@ typedef struct drm_r128_fullscreen {
|
|||
|
||||
typedef struct drm_r128_clear {
|
||||
unsigned int flags;
|
||||
int x, y, w, h;
|
||||
unsigned int clear_color;
|
||||
unsigned int clear_depth;
|
||||
unsigned int color_mask;
|
||||
unsigned int depth_mask;
|
||||
} drm_r128_clear_t;
|
||||
|
||||
typedef struct drm_r128_vertex {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#define R128_NAME "r128"
|
||||
#define R128_DESC "ATI Rage 128"
|
||||
#define R128_DATE "20010125"
|
||||
#define R128_DATE "20010101"
|
||||
#define R128_MAJOR 2
|
||||
#define R128_MINOR 1
|
||||
#define R128_PATCHLEVEL 4
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ typedef struct drm_r128_ring_buffer {
|
|||
u32 tail;
|
||||
u32 tail_mask;
|
||||
int space;
|
||||
|
||||
int high_mark;
|
||||
} drm_r128_ring_buffer_t;
|
||||
|
||||
typedef struct drm_r128_private {
|
||||
|
|
@ -76,13 +74,13 @@ typedef struct drm_r128_private {
|
|||
u32 crtc_offset;
|
||||
u32 crtc_offset_cntl;
|
||||
|
||||
u32 color_fmt;
|
||||
unsigned int fb_bpp;
|
||||
unsigned int front_offset;
|
||||
unsigned int front_pitch;
|
||||
unsigned int back_offset;
|
||||
unsigned int back_pitch;
|
||||
|
||||
u32 depth_fmt;
|
||||
unsigned int depth_bpp;
|
||||
unsigned int depth_offset;
|
||||
unsigned int depth_pitch;
|
||||
unsigned int span_offset;
|
||||
|
|
@ -145,7 +143,6 @@ extern drm_buf_t *r128_freelist_get( drm_device_t *dev );
|
|||
extern int r128_wait_ring( drm_r128_private_t *dev_priv, int n );
|
||||
extern void r128_update_ring_snapshot( drm_r128_private_t *dev_priv );
|
||||
|
||||
extern int r128_do_cce_idle( drm_r128_private_t *dev_priv );
|
||||
extern int r128_do_cleanup_pageflip( drm_device_t *dev );
|
||||
|
||||
/* r128_state.c */
|
||||
|
|
@ -389,24 +386,23 @@ extern int r128_context_switch_complete(drm_device_t *dev, int new);
|
|||
#define R128_WATERMARK_N 8
|
||||
#define R128_WATERMARK_K 128
|
||||
|
||||
#define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */
|
||||
#define R128_MAX_USEC_TIMEOUT 100000 /* 100 ms */
|
||||
|
||||
#define R128_LAST_FRAME_REG R128_GUI_SCRATCH_REG0
|
||||
#define R128_LAST_DISPATCH_REG R128_GUI_SCRATCH_REG1
|
||||
#define R128_MAX_VB_AGE 0xffffffff
|
||||
#define R128_MAX_VB_VERTS (0xffff)
|
||||
|
||||
#define R128_RING_HIGH_MARK 128
|
||||
#define R128_MAX_VB_VERTS (0xffff)
|
||||
|
||||
|
||||
#define R128_BASE(reg) ((u32)(dev_priv->mmio->handle))
|
||||
#define R128_ADDR(reg) (R128_BASE(reg) + reg)
|
||||
|
||||
#define R128_DEREF(reg) *(volatile u32 *)R128_ADDR(reg)
|
||||
#define R128_DEREF(reg) *(__volatile__ int *)R128_ADDR(reg)
|
||||
#define R128_READ(reg) R128_DEREF(reg)
|
||||
#define R128_WRITE(reg,val) do { R128_DEREF(reg) = val; } while (0)
|
||||
|
||||
#define R128_DEREF8(reg) *(volatile u8 *)R128_ADDR(reg)
|
||||
#define R128_DEREF8(reg) *(__volatile__ char *)R128_ADDR(reg)
|
||||
#define R128_READ8(reg) R128_DEREF8(reg)
|
||||
#define R128_WRITE8(reg,val) do { R128_DEREF8(reg) = val; } while (0)
|
||||
|
||||
|
|
@ -418,6 +414,13 @@ do { \
|
|||
|
||||
extern int R128_READ_PLL(drm_device_t *dev, int addr);
|
||||
|
||||
#define R128CCE0(p,r,n) ((p) | ((n) << 16) | ((r) >> 2))
|
||||
#define R128CCE1(p,r1,r2) ((p) | (((r2) >> 2) << 11) | ((r1) >> 2))
|
||||
#define R128CCE2(p) ((p))
|
||||
#define R128CCE3(p,n) ((p) | ((n) << 16))
|
||||
|
||||
|
||||
|
||||
|
||||
#define CCE_PACKET0( reg, n ) (R128_CCE_PACKET0 | \
|
||||
((n) << 16) | ((reg) >> 2))
|
||||
|
|
@ -428,57 +431,7 @@ extern int R128_READ_PLL(drm_device_t *dev, int addr);
|
|||
(pkt) | ((n) << 16))
|
||||
|
||||
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Misc helper macros
|
||||
*/
|
||||
|
||||
#define LOCK_TEST_WITH_RETURN( dev ) \
|
||||
do { \
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
|
||||
dev->lock.pid != current->pid ) { \
|
||||
DRM_ERROR( "%s called without lock held\n", \
|
||||
__FUNCTION__ ); \
|
||||
return -EINVAL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RING_SPACE_TEST_WITH_RETURN( dev_priv ) \
|
||||
do { \
|
||||
drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i; \
|
||||
if ( ring->space < ring->high_mark ) { \
|
||||
for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) { \
|
||||
ring->space = *ring->head - ring->tail; \
|
||||
if ( ring->space <= 0 ) \
|
||||
ring->space += ring->size; \
|
||||
if ( ring->space >= ring->high_mark ) \
|
||||
goto __ring_space_done; \
|
||||
udelay( 1 ); \
|
||||
} \
|
||||
DRM_ERROR( "ring space check failed!\n" ); \
|
||||
return -EBUSY; \
|
||||
} \
|
||||
__ring_space_done: \
|
||||
} while (0)
|
||||
|
||||
#define VB_AGE_TEST_WITH_RETURN( dev_priv ) \
|
||||
do { \
|
||||
drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; \
|
||||
if ( sarea_priv->last_dispatch >= R128_MAX_VB_AGE ) { \
|
||||
int __ret = r128_do_cce_idle( dev_priv ); \
|
||||
if ( __ret < 0 ) return __ret; \
|
||||
sarea_priv->last_dispatch = 0; \
|
||||
r128_freelist_reset( dev ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* ================================================================
|
||||
* Ring control
|
||||
*/
|
||||
|
||||
#define r128_flush_write_combine() mb()
|
||||
#define r128_flush_write_combine() mb()
|
||||
|
||||
|
||||
#define R128_VERBOSE 0
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
#include "drmP.h"
|
||||
#include "r128_drv.h"
|
||||
#include "drm.h"
|
||||
#include <linux/delay.h>
|
||||
|
||||
|
||||
/* ================================================================
|
||||
|
|
@ -361,20 +360,45 @@ static void r128_print_dirty( const char *msg, unsigned int flags )
|
|||
}
|
||||
|
||||
static void r128_cce_dispatch_clear( drm_device_t *dev,
|
||||
drm_r128_clear_t *clear )
|
||||
unsigned int flags,
|
||||
int cx, int cy, int cw, int ch,
|
||||
unsigned int clear_color,
|
||||
unsigned int clear_depth )
|
||||
{
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
|
||||
int nbox = sarea_priv->nbox;
|
||||
drm_clip_rect_t *pbox = sarea_priv->boxes;
|
||||
unsigned int flags = clear->flags;
|
||||
u32 fb_bpp, depth_bpp;
|
||||
int i;
|
||||
RING_LOCALS;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
r128_update_ring_snapshot( dev_priv );
|
||||
|
||||
if ( dev_priv->page_flipping && dev_priv->current_page == 1 ) {
|
||||
switch ( dev_priv->fb_bpp ) {
|
||||
case 16:
|
||||
fb_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 32:
|
||||
fb_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
switch ( dev_priv->depth_bpp ) {
|
||||
case 16:
|
||||
depth_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
depth_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if ( dev_priv->page_flipping && dev_priv->current_page == 1) {
|
||||
unsigned int tmp = flags;
|
||||
|
||||
flags &= ~(R128_FRONT | R128_BACK);
|
||||
|
|
@ -396,7 +420,7 @@ static void r128_cce_dispatch_clear( drm_device_t *dev,
|
|||
BEGIN_RING( 2 );
|
||||
|
||||
OUT_RING( CCE_PACKET0( R128_DP_WRITE_MASK, 0 ) );
|
||||
OUT_RING( clear->color_mask );
|
||||
OUT_RING( sarea_priv->context_state.plane_3d_mask_c );
|
||||
|
||||
ADVANCE_RING();
|
||||
}
|
||||
|
|
@ -407,14 +431,14 @@ static void r128_cce_dispatch_clear( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->color_fmt << 8) |
|
||||
fb_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
R128_GMC_AUX_CLIP_DIS );
|
||||
|
||||
OUT_RING( dev_priv->front_pitch_offset_c );
|
||||
OUT_RING( clear->clear_color );
|
||||
OUT_RING( clear_color );
|
||||
|
||||
OUT_RING( (x << 16) | y );
|
||||
OUT_RING( (w << 16) | h );
|
||||
|
|
@ -428,14 +452,14 @@ static void r128_cce_dispatch_clear( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->color_fmt << 8) |
|
||||
fb_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
R128_GMC_AUX_CLIP_DIS );
|
||||
|
||||
OUT_RING( dev_priv->back_pitch_offset_c );
|
||||
OUT_RING( clear->clear_color );
|
||||
OUT_RING( clear_color );
|
||||
|
||||
OUT_RING( (x << 16) | y );
|
||||
OUT_RING( (w << 16) | h );
|
||||
|
|
@ -449,7 +473,7 @@ static void r128_cce_dispatch_clear( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
|
|
@ -457,7 +481,7 @@ static void r128_cce_dispatch_clear( drm_device_t *dev,
|
|||
R128_GMC_WR_MSK_DIS );
|
||||
|
||||
OUT_RING( dev_priv->depth_pitch_offset_c );
|
||||
OUT_RING( clear->clear_depth );
|
||||
OUT_RING( clear_depth );
|
||||
|
||||
OUT_RING( (x << 16) | y );
|
||||
OUT_RING( (w << 16) | h );
|
||||
|
|
@ -473,6 +497,7 @@ static void r128_cce_dispatch_swap( drm_device_t *dev )
|
|||
drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
|
||||
int nbox = sarea_priv->nbox;
|
||||
drm_clip_rect_t *pbox = sarea_priv->boxes;
|
||||
u32 fb_bpp;
|
||||
int i;
|
||||
RING_LOCALS;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
|
@ -485,6 +510,16 @@ static void r128_cce_dispatch_swap( drm_device_t *dev )
|
|||
r128_cce_performance_boxes( dev_priv );
|
||||
#endif
|
||||
|
||||
switch ( dev_priv->fb_bpp ) {
|
||||
case 16:
|
||||
fb_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 32:
|
||||
default:
|
||||
fb_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < nbox ; i++ ) {
|
||||
int x = pbox[i].x1;
|
||||
int y = pbox[i].y1;
|
||||
|
|
@ -497,7 +532,7 @@ static void r128_cce_dispatch_swap( drm_device_t *dev )
|
|||
OUT_RING( R128_GMC_SRC_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_NONE |
|
||||
(dev_priv->color_fmt << 8) |
|
||||
fb_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_S |
|
||||
R128_DP_SRC_SOURCE_MEMORY |
|
||||
|
|
@ -641,6 +676,15 @@ static void r128_cce_dispatch_vertex( drm_device_t *dev,
|
|||
|
||||
dev_priv->sarea_priv->last_dispatch++;
|
||||
|
||||
#if 0
|
||||
if ( dev_priv->submit_age == R128_MAX_VB_AGE ) {
|
||||
ret = r128_do_cce_idle( dev_priv );
|
||||
if ( ret < 0 ) return ret;
|
||||
dev_priv->submit_age = 0;
|
||||
r128_freelist_reset( dev );
|
||||
}
|
||||
#endif
|
||||
|
||||
sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
|
||||
sarea_priv->nbox = 0;
|
||||
}
|
||||
|
|
@ -706,6 +750,15 @@ static void r128_cce_dispatch_indirect( drm_device_t *dev,
|
|||
}
|
||||
|
||||
dev_priv->sarea_priv->last_dispatch++;
|
||||
|
||||
#if 0
|
||||
if ( dev_priv->submit_age == R128_MAX_VB_AGE ) {
|
||||
ret = r128_do_cce_idle( dev_priv );
|
||||
if ( ret < 0 ) return ret;
|
||||
dev_priv->submit_age = 0;
|
||||
r128_freelist_reset( dev );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void r128_cce_dispatch_indices( drm_device_t *dev,
|
||||
|
|
@ -786,6 +839,15 @@ static void r128_cce_dispatch_indices( drm_device_t *dev,
|
|||
|
||||
dev_priv->sarea_priv->last_dispatch++;
|
||||
|
||||
#if 0
|
||||
if ( dev_priv->submit_age == R128_MAX_VB_AGE ) {
|
||||
ret = r128_do_cce_idle( dev_priv );
|
||||
if ( ret < 0 ) return ret;
|
||||
dev_priv->submit_age = 0;
|
||||
r128_freelist_reset( dev );
|
||||
}
|
||||
#endif
|
||||
|
||||
sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
|
||||
sarea_priv->nbox = 0;
|
||||
}
|
||||
|
|
@ -910,12 +972,25 @@ static int r128_cce_dispatch_write_span( drm_device_t *dev,
|
|||
int count, x, y;
|
||||
u32 *buffer;
|
||||
u8 *mask;
|
||||
u32 depth_bpp;
|
||||
int i;
|
||||
RING_LOCALS;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
r128_update_ring_snapshot( dev_priv );
|
||||
|
||||
switch ( dev_priv->depth_bpp ) {
|
||||
case 16:
|
||||
depth_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
depth_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
count = depth->n;
|
||||
if ( copy_from_user( &x, depth->x, sizeof(x) ) ) {
|
||||
return -EFAULT;
|
||||
|
|
@ -953,7 +1028,7 @@ static int r128_cce_dispatch_write_span( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
|
|
@ -977,7 +1052,7 @@ static int r128_cce_dispatch_write_span( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
|
|
@ -1005,12 +1080,25 @@ static int r128_cce_dispatch_write_pixels( drm_device_t *dev,
|
|||
int count, *x, *y;
|
||||
u32 *buffer;
|
||||
u8 *mask;
|
||||
u32 depth_bpp;
|
||||
int i;
|
||||
RING_LOCALS;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
r128_update_ring_snapshot( dev_priv );
|
||||
|
||||
switch ( dev_priv->depth_bpp ) {
|
||||
case 16:
|
||||
depth_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
depth_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
count = depth->n;
|
||||
|
||||
x = kmalloc( count * sizeof(*x), 0 );
|
||||
|
|
@ -1071,7 +1159,7 @@ static int r128_cce_dispatch_write_pixels( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
|
|
@ -1095,7 +1183,7 @@ static int r128_cce_dispatch_write_pixels( drm_device_t *dev,
|
|||
OUT_RING( CCE_PACKET3( R128_CNTL_PAINT_MULTI, 4 ) );
|
||||
OUT_RING( R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_SOLID_COLOR |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_P |
|
||||
R128_GMC_CLR_CMP_CNTL_DIS |
|
||||
|
|
@ -1123,11 +1211,24 @@ static int r128_cce_dispatch_read_span( drm_device_t *dev,
|
|||
{
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
int count, x, y;
|
||||
u32 depth_bpp;
|
||||
RING_LOCALS;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
r128_update_ring_snapshot( dev_priv );
|
||||
|
||||
switch ( dev_priv->depth_bpp ) {
|
||||
case 16:
|
||||
depth_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
depth_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
count = depth->n;
|
||||
if ( copy_from_user( &x, depth->x, sizeof(x) ) ) {
|
||||
return -EFAULT;
|
||||
|
|
@ -1142,7 +1243,7 @@ static int r128_cce_dispatch_read_span( drm_device_t *dev,
|
|||
OUT_RING( R128_GMC_SRC_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_NONE |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_S |
|
||||
R128_DP_SRC_SOURCE_MEMORY |
|
||||
|
|
@ -1166,12 +1267,25 @@ static int r128_cce_dispatch_read_pixels( drm_device_t *dev,
|
|||
{
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
int count, *x, *y;
|
||||
u32 depth_bpp;
|
||||
int i;
|
||||
RING_LOCALS;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
r128_update_ring_snapshot( dev_priv );
|
||||
|
||||
switch ( dev_priv->depth_bpp ) {
|
||||
case 16:
|
||||
depth_bpp = R128_GMC_DST_16BPP;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
depth_bpp = R128_GMC_DST_32BPP;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
count = depth->n;
|
||||
if ( count > dev_priv->depth_pitch ) {
|
||||
count = dev_priv->depth_pitch;
|
||||
|
|
@ -1204,7 +1318,7 @@ static int r128_cce_dispatch_read_pixels( drm_device_t *dev,
|
|||
OUT_RING( R128_GMC_SRC_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_DST_PITCH_OFFSET_CNTL |
|
||||
R128_GMC_BRUSH_NONE |
|
||||
(dev_priv->depth_fmt << 8) |
|
||||
depth_bpp |
|
||||
R128_GMC_SRC_DATATYPE_COLOR |
|
||||
R128_ROP3_S |
|
||||
R128_DP_SRC_SOURCE_MEMORY |
|
||||
|
|
@ -1266,18 +1380,22 @@ int r128_cce_clear( struct inode *inode, struct file *filp,
|
|||
drm_r128_clear_t clear;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "r128_cce_clear called without lock held\n" );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( copy_from_user( &clear, (drm_r128_clear_t *) arg,
|
||||
sizeof(clear) ) )
|
||||
return -EFAULT;
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
|
||||
if ( sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS )
|
||||
sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS;
|
||||
|
||||
r128_cce_dispatch_clear( dev, &clear );
|
||||
r128_cce_dispatch_clear( dev, clear.flags,
|
||||
clear.x, clear.y, clear.w, clear.h,
|
||||
clear.clear_color, clear.clear_depth );
|
||||
|
||||
/* Make sure we restore the 3D state next time.
|
||||
*/
|
||||
|
|
@ -1295,9 +1413,11 @@ int r128_cce_swap( struct inode *inode, struct file *filp,
|
|||
drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
|
||||
DRM_DEBUG( "%s\n", __FUNCTION__ );
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "r128_cce_swap called without lock held\n" );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS )
|
||||
sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS;
|
||||
|
|
@ -1324,8 +1444,11 @@ int r128_cce_vertex( struct inode *inode, struct file *filp,
|
|||
drm_r128_buf_priv_t *buf_priv;
|
||||
drm_r128_vertex_t vertex;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
if ( !dev_priv || dev_priv->is_pci ) {
|
||||
DRM_ERROR( "%s called with a PCI card\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
|
|
@ -1350,9 +1473,6 @@ int r128_cce_vertex( struct inode *inode, struct file *filp,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
VB_AGE_TEST_WITH_RETURN( dev_priv );
|
||||
|
||||
buf = dma->buflist[vertex.idx];
|
||||
buf_priv = buf->dev_private;
|
||||
|
||||
|
|
@ -1387,8 +1507,11 @@ int r128_cce_indices( struct inode *inode, struct file *filp,
|
|||
drm_r128_indices_t elts;
|
||||
int count;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
if ( !dev_priv || dev_priv->is_pci ) {
|
||||
DRM_ERROR( "%s called with a PCI card\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
|
|
@ -1413,9 +1536,6 @@ int r128_cce_indices( struct inode *inode, struct file *filp,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
VB_AGE_TEST_WITH_RETURN( dev_priv );
|
||||
|
||||
buf = dma->buflist[elts.idx];
|
||||
buf_priv = buf->dev_private;
|
||||
|
||||
|
|
@ -1456,10 +1576,13 @@ int r128_cce_blit( struct inode *inode, struct file *filp,
|
|||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_device_dma_t *dma = dev->dma;
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
drm_r128_blit_t blit;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( copy_from_user( &blit, (drm_r128_blit_t *)arg,
|
||||
sizeof(blit) ) )
|
||||
|
|
@ -1474,9 +1597,6 @@ int r128_cce_blit( struct inode *inode, struct file *filp,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
VB_AGE_TEST_WITH_RETURN( dev_priv );
|
||||
|
||||
return r128_cce_dispatch_blit( dev, &blit );
|
||||
}
|
||||
|
||||
|
|
@ -1485,17 +1605,18 @@ int r128_cce_depth( struct inode *inode, struct file *filp,
|
|||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
drm_r128_depth_t depth;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( copy_from_user( &depth, (drm_r128_depth_t *)arg,
|
||||
sizeof(depth) ) )
|
||||
return -EFAULT;
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
|
||||
switch ( depth.func ) {
|
||||
case R128_WRITE_SPAN:
|
||||
return r128_cce_dispatch_write_span( dev, &depth );
|
||||
|
|
@ -1515,11 +1636,14 @@ int r128_cce_stipple( struct inode *inode, struct file *filp,
|
|||
{
|
||||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
drm_r128_private_t *dev_priv = dev->dev_private;
|
||||
drm_r128_stipple_t stipple;
|
||||
u32 mask[32];
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ( copy_from_user( &stipple, (drm_r128_stipple_t *)arg,
|
||||
sizeof(stipple) ) )
|
||||
|
|
@ -1529,8 +1653,6 @@ int r128_cce_stipple( struct inode *inode, struct file *filp,
|
|||
32 * sizeof(u32) ) )
|
||||
return -EFAULT;
|
||||
|
||||
RING_SPACE_TEST_WITH_RETURN( dev_priv );
|
||||
|
||||
r128_cce_dispatch_stipple( dev, mask );
|
||||
|
||||
return 0;
|
||||
|
|
@ -1542,7 +1664,11 @@ int r128_cce_indirect( struct inode *inode, struct file *filp,
|
|||
drm_file_t *priv = filp->private_data;
|
||||
drm_device_t *dev = priv->dev;
|
||||
|
||||
LOCK_TEST_WITH_RETURN( dev );
|
||||
if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||
|
||||
dev->lock.pid != current->pid ) {
|
||||
DRM_ERROR( "%s called without lock held\n", __FUNCTION__ );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Indirect buffer firing is not supported at this time.
|
||||
*/
|
||||
|
|
|
|||
1294
linux/radeon_cp.c
1294
linux/radeon_cp.c
File diff suppressed because it is too large
Load diff
|
|
@ -1,327 +0,0 @@
|
|||
/* radeon_drm.h -- Public header for the radeon driver -*- linux-c -*-
|
||||
*
|
||||
* Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
|
||||
* Copyright 2000 VA Linux Systems, Inc., Fremont, 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:
|
||||
* Kevin E. Martin <martin@valinux.com>
|
||||
* Gareth Hughes <gareth@valinux.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __RADEON_DRM_H__
|
||||
#define __RADEON_DRM_H__
|
||||
|
||||
/* WARNING: If you change any of these defines, make sure to change the
|
||||
* defines in the X server file (radeon_sarea.h)
|
||||
*/
|
||||
#ifndef __RADEON_SAREA_DEFINES__
|
||||
#define __RADEON_SAREA_DEFINES__
|
||||
|
||||
/* What needs to be changed for the current vertex buffer?
|
||||
*/
|
||||
#define RADEON_UPLOAD_CONTEXT 0x00000001
|
||||
#define RADEON_UPLOAD_VERTFMT 0x00000002
|
||||
#define RADEON_UPLOAD_LINE 0x00000004
|
||||
#define RADEON_UPLOAD_BUMPMAP 0x00000008
|
||||
#define RADEON_UPLOAD_MASKS 0x00000010
|
||||
#define RADEON_UPLOAD_VIEWPORT 0x00000020
|
||||
#define RADEON_UPLOAD_SETUP 0x00000040
|
||||
#define RADEON_UPLOAD_TCL 0x00000080
|
||||
#define RADEON_UPLOAD_MISC 0x00000100
|
||||
#define RADEON_UPLOAD_TEX0 0x00000200
|
||||
#define RADEON_UPLOAD_TEX1 0x00000400
|
||||
#define RADEON_UPLOAD_TEX2 0x00000800
|
||||
#define RADEON_UPLOAD_TEX0IMAGES 0x00001000
|
||||
#define RADEON_UPLOAD_TEX1IMAGES 0x00002000
|
||||
#define RADEON_UPLOAD_TEX2IMAGES 0x00004000
|
||||
#define RADEON_UPLOAD_CLIPRECTS 0x00008000 /* handled client-side */
|
||||
#define RADEON_REQUIRE_QUIESCENCE 0x00010000
|
||||
#define RADEON_UPLOAD_ALL 0x0001ffff
|
||||
|
||||
#define RADEON_FRONT 0x1
|
||||
#define RADEON_BACK 0x2
|
||||
#define RADEON_DEPTH 0x4
|
||||
|
||||
/* Primitive types
|
||||
*/
|
||||
#define RADEON_POINTS 0x1
|
||||
#define RADEON_LINES 0x2
|
||||
#define RADEON_LINE_STRIP 0x3
|
||||
#define RADEON_TRIANGLES 0x4
|
||||
#define RADEON_TRIANGLE_FAN 0x5
|
||||
#define RADEON_TRIANGLE_STRIP 0x6
|
||||
|
||||
/* Vertex/indirect buffer size
|
||||
*/
|
||||
#define RADEON_BUFFER_SIZE 16384
|
||||
|
||||
/* Byte offsets for indirect buffer data
|
||||
*/
|
||||
#define RADEON_INDEX_PRIM_OFFSET 20
|
||||
#define RADEON_HOSTDATA_BLIT_OFFSET 32
|
||||
|
||||
#define RADEON_SCRATCH_REG_OFFSET 32
|
||||
|
||||
/* Keep these small for testing
|
||||
*/
|
||||
#define RADEON_NR_SAREA_CLIPRECTS 12
|
||||
|
||||
/* There are 2 heaps (local/AGP). Each region within a heap is a
|
||||
* minimum of 64k, and there are at most 64 of them per heap.
|
||||
*/
|
||||
#define RADEON_LOCAL_TEX_HEAP 0
|
||||
#define RADEON_AGP_TEX_HEAP 1
|
||||
#define RADEON_NR_TEX_HEAPS 2
|
||||
#define RADEON_NR_TEX_REGIONS 64
|
||||
#define RADEON_LOG_TEX_GRANULARITY 16
|
||||
|
||||
#define RADEON_MAX_TEXTURE_LEVELS 11
|
||||
#define RADEON_MAX_TEXTURE_UNITS 3
|
||||
|
||||
#endif /* __RADEON_SAREA_DEFINES__ */
|
||||
|
||||
typedef struct {
|
||||
unsigned int red;
|
||||
unsigned int green;
|
||||
unsigned int blue;
|
||||
unsigned int alpha;
|
||||
} radeon_color_regs_t;
|
||||
|
||||
typedef struct {
|
||||
/* Context state */
|
||||
unsigned int pp_misc; /* 0x1c14 */
|
||||
unsigned int pp_fog_color;
|
||||
unsigned int re_solid_color;
|
||||
unsigned int rb3d_blendcntl;
|
||||
unsigned int rb3d_depthoffset;
|
||||
unsigned int rb3d_depthpitch;
|
||||
unsigned int rb3d_zstencilcntl;
|
||||
|
||||
unsigned int pp_cntl; /* 0x1c38 */
|
||||
unsigned int rb3d_cntl;
|
||||
unsigned int rb3d_coloroffset;
|
||||
unsigned int re_width_height;
|
||||
unsigned int rb3d_colorpitch;
|
||||
unsigned int se_cntl;
|
||||
|
||||
/* Vertex format state */
|
||||
unsigned int se_coord_fmt; /* 0x1c50 */
|
||||
|
||||
/* Line state */
|
||||
unsigned int re_line_pattern; /* 0x1cd0 */
|
||||
unsigned int re_line_state;
|
||||
|
||||
unsigned int se_line_width; /* 0x1db8 */
|
||||
|
||||
/* Bumpmap state */
|
||||
unsigned int pp_lum_matrix; /* 0x1d00 */
|
||||
|
||||
unsigned int pp_rot_matrix_0; /* 0x1d58 */
|
||||
unsigned int pp_rot_matrix_1;
|
||||
|
||||
/* Mask state */
|
||||
unsigned int rb3d_stencilrefmask; /* 0x1d7c */
|
||||
unsigned int rb3d_ropcntl;
|
||||
unsigned int rb3d_planemask;
|
||||
|
||||
/* Viewport state */
|
||||
unsigned int se_vport_xscale; /* 0x1d98 */
|
||||
unsigned int se_vport_xoffset;
|
||||
unsigned int se_vport_yscale;
|
||||
unsigned int se_vport_yoffset;
|
||||
unsigned int se_vport_zscale;
|
||||
unsigned int se_vport_zoffset;
|
||||
|
||||
/* Setup state */
|
||||
unsigned int se_cntl_status; /* 0x2140 */
|
||||
|
||||
#ifdef TCL_ENABLE
|
||||
/* TCL state */
|
||||
radeon_color_regs_t se_tcl_material_emmissive; /* 0x2210 */
|
||||
radeon_color_regs_t se_tcl_material_ambient;
|
||||
radeon_color_regs_t se_tcl_material_diffuse;
|
||||
radeon_color_regs_t se_tcl_material_specular;
|
||||
unsigned int se_tcl_shininess;
|
||||
unsigned int se_tcl_output_vtx_fmt;
|
||||
unsigned int se_tcl_output_vtx_sel;
|
||||
unsigned int se_tcl_matrix_select_0;
|
||||
unsigned int se_tcl_matrix_select_1;
|
||||
unsigned int se_tcl_ucp_vert_blend_ctl;
|
||||
unsigned int se_tcl_texture_proc_ctl;
|
||||
unsigned int se_tcl_light_model_ctl;
|
||||
unsigned int se_tcl_per_light_ctl[4];
|
||||
#endif
|
||||
|
||||
/* Misc state */
|
||||
unsigned int re_top_left; /* 0x26c0 */
|
||||
unsigned int re_misc;
|
||||
} drm_radeon_context_regs_t;
|
||||
|
||||
/* Setup registers for each texture unit
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int pp_txfilter;
|
||||
unsigned int pp_txformat;
|
||||
unsigned int pp_txoffset;
|
||||
unsigned int pp_txcblend;
|
||||
unsigned int pp_txablend;
|
||||
unsigned int pp_tfactor;
|
||||
|
||||
unsigned int pp_border_color;
|
||||
|
||||
#ifdef CUBIC_ENABLE
|
||||
unsigned int pp_cubic_faces;
|
||||
unsigned int pp_cubic_offset[5];
|
||||
#endif
|
||||
} drm_radeon_texture_regs_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char next, prev;
|
||||
unsigned char in_use;
|
||||
int age;
|
||||
} drm_radeon_tex_region_t;
|
||||
|
||||
typedef struct {
|
||||
/* The channel for communication of state information to the kernel
|
||||
* on firing a vertex buffer.
|
||||
*/
|
||||
drm_radeon_context_regs_t context_state;
|
||||
drm_radeon_texture_regs_t tex_state[RADEON_MAX_TEXTURE_UNITS];
|
||||
unsigned int dirty;
|
||||
unsigned int vertsize;
|
||||
unsigned int vc_format;
|
||||
|
||||
/* The current cliprects, or a subset thereof.
|
||||
*/
|
||||
drm_clip_rect_t boxes[RADEON_NR_SAREA_CLIPRECTS];
|
||||
unsigned int nbox;
|
||||
|
||||
/* Counters for client-side throttling of rendering clients.
|
||||
*/
|
||||
unsigned int last_frame;
|
||||
unsigned int last_dispatch;
|
||||
unsigned int last_clear;
|
||||
|
||||
drm_radeon_tex_region_t tex_list[RADEON_NR_TEX_HEAPS][RADEON_NR_TEX_REGIONS+1];
|
||||
int tex_age[RADEON_NR_TEX_HEAPS];
|
||||
int ctx_owner;
|
||||
} drm_radeon_sarea_t;
|
||||
|
||||
|
||||
/* WARNING: If you change any of these defines, make sure to change the
|
||||
* defines in the Xserver file (xf86drmRadeon.h)
|
||||
*/
|
||||
typedef struct drm_radeon_init {
|
||||
enum {
|
||||
RADEON_INIT_CP = 0x01,
|
||||
RADEON_CLEANUP_CP = 0x02
|
||||
} func;
|
||||
int sarea_priv_offset;
|
||||
int is_pci;
|
||||
int cp_mode;
|
||||
int agp_size;
|
||||
int ring_size;
|
||||
int usec_timeout;
|
||||
|
||||
unsigned int fb_bpp;
|
||||
unsigned int front_offset, front_pitch;
|
||||
unsigned int back_offset, back_pitch;
|
||||
unsigned int depth_bpp;
|
||||
unsigned int depth_offset, depth_pitch;
|
||||
|
||||
unsigned int fb_offset;
|
||||
unsigned int mmio_offset;
|
||||
unsigned int ring_offset;
|
||||
unsigned int ring_rptr_offset;
|
||||
unsigned int buffers_offset;
|
||||
unsigned int agp_textures_offset;
|
||||
} drm_radeon_init_t;
|
||||
|
||||
typedef struct drm_radeon_cp_stop {
|
||||
int flush;
|
||||
int idle;
|
||||
} drm_radeon_cp_stop_t;
|
||||
|
||||
typedef struct drm_radeon_fullscreen {
|
||||
enum {
|
||||
RADEON_INIT_FULLSCREEN = 0x01,
|
||||
RADEON_CLEANUP_FULLSCREEN = 0x02
|
||||
} func;
|
||||
} drm_radeon_fullscreen_t;
|
||||
|
||||
#define CLEAR_X1 0
|
||||
#define CLEAR_Y1 1
|
||||
#define CLEAR_X2 2
|
||||
#define CLEAR_Y2 3
|
||||
#define CLEAR_DEPTH 4
|
||||
|
||||
typedef struct drm_radeon_clear {
|
||||
unsigned int flags;
|
||||
int x, y, w, h;
|
||||
unsigned int clear_color;
|
||||
unsigned int clear_depth;
|
||||
unsigned int color_mask;
|
||||
unsigned int depth_mask;
|
||||
union {
|
||||
float f[5];
|
||||
unsigned int ui[5];
|
||||
} rect;
|
||||
} drm_radeon_clear_t;
|
||||
|
||||
typedef struct drm_radeon_vertex {
|
||||
int prim;
|
||||
int idx; /* Index of vertex buffer */
|
||||
int count; /* Number of vertices in buffer */
|
||||
int discard; /* Client finished with buffer? */
|
||||
} drm_radeon_vertex_t;
|
||||
|
||||
typedef struct drm_radeon_indices {
|
||||
int prim;
|
||||
int idx;
|
||||
int start;
|
||||
int end;
|
||||
int discard; /* Client finished with buffer? */
|
||||
} drm_radeon_indices_t;
|
||||
|
||||
typedef struct drm_radeon_blit {
|
||||
int idx;
|
||||
int pitch;
|
||||
int offset;
|
||||
int format;
|
||||
unsigned short x, y;
|
||||
unsigned short width, height;
|
||||
} drm_radeon_blit_t;
|
||||
|
||||
typedef struct drm_radeon_stipple {
|
||||
unsigned int *mask;
|
||||
} drm_radeon_stipple_t;
|
||||
|
||||
typedef struct drm_radeon_indirect {
|
||||
int idx;
|
||||
int start;
|
||||
int end;
|
||||
int discard;
|
||||
} drm_radeon_indirect_t;
|
||||
|
||||
#endif
|
||||
1457
linux/radeon_state.c
1457
linux/radeon_state.c
File diff suppressed because it is too large
Load diff
|
|
@ -72,12 +72,20 @@ typedef unsigned int drm_magic_t;
|
|||
* XF86DRIClipRectRec in the server as well */
|
||||
|
||||
typedef struct drm_clip_rect {
|
||||
unsigned short x1;
|
||||
unsigned short y1;
|
||||
unsigned short x2;
|
||||
unsigned short y2;
|
||||
unsigned short x1;
|
||||
unsigned short y1;
|
||||
unsigned short x2;
|
||||
unsigned short y2;
|
||||
} drm_clip_rect_t;
|
||||
|
||||
typedef struct drm_tex_region {
|
||||
unsigned char next;
|
||||
unsigned char prev;
|
||||
unsigned char in_use;
|
||||
unsigned char padding;
|
||||
unsigned int age;
|
||||
} drm_tex_region_t;
|
||||
|
||||
/* Seperate include files for the i810/mga/r128 specific structures */
|
||||
#include "mga_drm.h"
|
||||
#include "i810_drm.h"
|
||||
|
|
@ -345,17 +353,19 @@ typedef struct drm_agp_info {
|
|||
#define DRM_IOCTL_AGP_BIND DRM_IOW( 0x36, drm_agp_binding_t)
|
||||
#define DRM_IOCTL_AGP_UNBIND DRM_IOW( 0x37, drm_agp_binding_t)
|
||||
|
||||
/* Mga specific ioctls */
|
||||
/* MGA specific ioctls */
|
||||
#define DRM_IOCTL_MGA_INIT DRM_IOW( 0x40, drm_mga_init_t)
|
||||
#define DRM_IOCTL_MGA_SWAP DRM_IOW( 0x41, drm_mga_swap_t)
|
||||
#define DRM_IOCTL_MGA_CLEAR DRM_IOW( 0x42, drm_mga_clear_t)
|
||||
#define DRM_IOCTL_MGA_ILOAD DRM_IOW( 0x43, drm_mga_iload_t)
|
||||
#define DRM_IOCTL_MGA_VERTEX DRM_IOW( 0x44, drm_mga_vertex_t)
|
||||
#define DRM_IOCTL_MGA_FLUSH DRM_IOW( 0x45, drm_lock_t )
|
||||
#define DRM_IOCTL_MGA_INDICES DRM_IOW( 0x46, drm_mga_indices_t)
|
||||
#define DRM_IOCTL_MGA_BLIT DRM_IOW( 0x47, drm_mga_blit_t)
|
||||
#define DRM_IOCTL_MGA_FLUSH DRM_IOW( 0x41, drm_lock_t)
|
||||
#define DRM_IOCTL_MGA_RESET DRM_IO( 0x42)
|
||||
#define DRM_IOCTL_MGA_SWAP DRM_IO( 0x43)
|
||||
#define DRM_IOCTL_MGA_CLEAR DRM_IOW( 0x44, drm_mga_clear_t)
|
||||
|
||||
/* I810 specific ioctls */
|
||||
#define DRM_IOCTL_MGA_ILOAD DRM_IOW( 0x45, drm_mga_iload_t)
|
||||
#define DRM_IOCTL_MGA_VERTEX DRM_IOW( 0x46, drm_mga_vertex_t)
|
||||
#define DRM_IOCTL_MGA_INDICES DRM_IOW( 0x47, drm_mga_indices_t)
|
||||
#define DRM_IOCTL_MGA_BLIT DRM_IOW( 0x48, drm_mga_blit_t)
|
||||
|
||||
/* i810 specific ioctls */
|
||||
#define DRM_IOCTL_I810_INIT DRM_IOW( 0x40, drm_i810_init_t)
|
||||
#define DRM_IOCTL_I810_VERTEX DRM_IOW( 0x41, drm_i810_vertex_t)
|
||||
#define DRM_IOCTL_I810_CLEAR DRM_IOW( 0x42, drm_i810_clear_t)
|
||||
|
|
|
|||
36
shared/drm.h
36
shared/drm.h
|
|
@ -72,12 +72,20 @@ typedef unsigned int drm_magic_t;
|
|||
* XF86DRIClipRectRec in the server as well */
|
||||
|
||||
typedef struct drm_clip_rect {
|
||||
unsigned short x1;
|
||||
unsigned short y1;
|
||||
unsigned short x2;
|
||||
unsigned short y2;
|
||||
unsigned short x1;
|
||||
unsigned short y1;
|
||||
unsigned short x2;
|
||||
unsigned short y2;
|
||||
} drm_clip_rect_t;
|
||||
|
||||
typedef struct drm_tex_region {
|
||||
unsigned char next;
|
||||
unsigned char prev;
|
||||
unsigned char in_use;
|
||||
unsigned char padding;
|
||||
unsigned int age;
|
||||
} drm_tex_region_t;
|
||||
|
||||
/* Seperate include files for the i810/mga/r128 specific structures */
|
||||
#include "mga_drm.h"
|
||||
#include "i810_drm.h"
|
||||
|
|
@ -345,17 +353,19 @@ typedef struct drm_agp_info {
|
|||
#define DRM_IOCTL_AGP_BIND DRM_IOW( 0x36, drm_agp_binding_t)
|
||||
#define DRM_IOCTL_AGP_UNBIND DRM_IOW( 0x37, drm_agp_binding_t)
|
||||
|
||||
/* Mga specific ioctls */
|
||||
/* MGA specific ioctls */
|
||||
#define DRM_IOCTL_MGA_INIT DRM_IOW( 0x40, drm_mga_init_t)
|
||||
#define DRM_IOCTL_MGA_SWAP DRM_IOW( 0x41, drm_mga_swap_t)
|
||||
#define DRM_IOCTL_MGA_CLEAR DRM_IOW( 0x42, drm_mga_clear_t)
|
||||
#define DRM_IOCTL_MGA_ILOAD DRM_IOW( 0x43, drm_mga_iload_t)
|
||||
#define DRM_IOCTL_MGA_VERTEX DRM_IOW( 0x44, drm_mga_vertex_t)
|
||||
#define DRM_IOCTL_MGA_FLUSH DRM_IOW( 0x45, drm_lock_t )
|
||||
#define DRM_IOCTL_MGA_INDICES DRM_IOW( 0x46, drm_mga_indices_t)
|
||||
#define DRM_IOCTL_MGA_BLIT DRM_IOW( 0x47, drm_mga_blit_t)
|
||||
#define DRM_IOCTL_MGA_FLUSH DRM_IOW( 0x41, drm_lock_t)
|
||||
#define DRM_IOCTL_MGA_RESET DRM_IO( 0x42)
|
||||
#define DRM_IOCTL_MGA_SWAP DRM_IO( 0x43)
|
||||
#define DRM_IOCTL_MGA_CLEAR DRM_IOW( 0x44, drm_mga_clear_t)
|
||||
|
||||
/* I810 specific ioctls */
|
||||
#define DRM_IOCTL_MGA_ILOAD DRM_IOW( 0x45, drm_mga_iload_t)
|
||||
#define DRM_IOCTL_MGA_VERTEX DRM_IOW( 0x46, drm_mga_vertex_t)
|
||||
#define DRM_IOCTL_MGA_INDICES DRM_IOW( 0x47, drm_mga_indices_t)
|
||||
#define DRM_IOCTL_MGA_BLIT DRM_IOW( 0x48, drm_mga_blit_t)
|
||||
|
||||
/* i810 specific ioctls */
|
||||
#define DRM_IOCTL_I810_INIT DRM_IOW( 0x40, drm_i810_init_t)
|
||||
#define DRM_IOCTL_I810_VERTEX DRM_IOW( 0x41, drm_i810_vertex_t)
|
||||
#define DRM_IOCTL_I810_CLEAR DRM_IOW( 0x42, drm_i810_clear_t)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue