Date: Thu, 23 Oct 2003 20:46:26 -0700 (PDT) From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 40364 for review Message-ID: <200310240346.h9O3kQiV015907@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=40364 Change 40364 by sam@sam_ebb on 2003/10/23 20:46:24 IFC Affected files ... .. //depot/projects/hostcache/sys/amd64/include/stdarg.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/ati_pcigart.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drmP.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_auth.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_bufs.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_context.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_dma.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_drv.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_fops.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_ioctl.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_irq.h#1 branch .. //depot/projects/hostcache/sys/dev/drm/drm_memory.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_memory_debug.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_os_freebsd.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_pci.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_sysctl.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/drm_vm.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/mga.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/mga_dma.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/mga_drv.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/mga_irq.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/r128.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/r128_cce.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/r128_drv.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/r128_drv.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/r128_irq.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/r128_state.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/radeon.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/radeon_cp.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/radeon_drv.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/radeon_irq.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/sis.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/sis_drv.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/sis_mm.c#2 integrate .. //depot/projects/hostcache/sys/dev/drm/tdfx.h#2 integrate .. //depot/projects/hostcache/sys/dev/drm/tdfx_drv.c#2 integrate .. //depot/projects/hostcache/sys/ia64/disasm/disasm.h#2 integrate .. //depot/projects/hostcache/sys/ia64/ia64/unaligned.c#2 integrate .. //depot/projects/hostcache/sys/kern/kern_prot.c#2 integrate .. //depot/projects/hostcache/sys/kern/vfs_bio.c#2 integrate .. //depot/projects/hostcache/sys/netinet/ip_mroute.c#2 integrate .. //depot/projects/hostcache/sys/netinet6/in6_src.c#2 integrate .. //depot/projects/hostcache/sys/sys/proc.h#2 integrate .. //depot/projects/hostcache/sys/ufs/ffs/ffs_snapshot.c#2 integrate .. //depot/projects/hostcache/sys/ufs/ffs/ffs_softdep.c#2 integrate Differences ... ==== //depot/projects/hostcache/sys/amd64/include/stdarg.h#2 (text+ko) ==== @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/amd64/include/stdarg.h,v 1.5 2003/05/10 00:55:15 peter Exp $ + * $FreeBSD: src/sys/amd64/include/stdarg.h,v 1.6 2003/10/24 02:50:39 peter Exp $ */ #ifndef _MACHINE_STDARG_H_ @@ -46,9 +46,12 @@ #define va_arg(ap, type) \ __builtin_va_arg((ap), type) +#define __va_copy(dest, src) \ + __builtin_va_copy((dest), (src)) + #if __ISO_C_VISIBLE >= 1999 #define va_copy(dest, src) \ - __builtin_va_copy((dest), (src)) + __va_copy(dest, src) #endif #define va_end(ap) \ ==== //depot/projects/hostcache/sys/dev/drm/ati_pcigart.h#2 (text+ko) ==== @@ -26,7 +26,7 @@ * Authors: * Gareth Hughes <gareth@valinux.com> * - * $FreeBSD: src/sys/dev/drm/ati_pcigart.h,v 1.2 2003/08/19 02:57:31 anholt Exp $ + * $FreeBSD: src/sys/dev/drm/ati_pcigart.h,v 1.3 2003/10/24 01:48:16 anholt Exp $ */ #include "dev/drm/drmP.h" @@ -60,7 +60,7 @@ } address = (long)contigmalloc((1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE, - DRM(M_DRM), M_WAITOK, 0ul, 0xfffffffful, PAGE_SIZE, 0); + DRM(M_DRM), M_NOWAIT, 0ul, 0xfffffffful, PAGE_SIZE, 0); if ( !address ) { DRM_ERROR( "cannot allocate PCI GART page!\n" ); goto done; ==== //depot/projects/hostcache/sys/dev/drm/drm.h#2 (text+ko) ==== @@ -30,7 +30,7 @@ * Acknowledgements: * Dec 1999, Richard Henderson <rth@twiddle.net>, move to generic cmpxchg. * - * $FreeBSD: src/sys/dev/drm/drm.h,v 1.4 2003/08/19 02:57:31 anholt Exp $ + * $FreeBSD: src/sys/dev/drm/drm.h,v 1.5 2003/10/24 01:48:16 anholt Exp $ */ #ifndef _DRM_H_ @@ -46,7 +46,7 @@ #define DRM_IOC_READWRITE _IOC_READ|_IOC_WRITE #define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size) #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) -#if defined(__FreeBSD__) && defined(XFree86Server) +#if defined(__FreeBSD__) && defined(IN_MODULE) /* Prevent name collision when including sys/ioccom.h */ #undef ioctl #include <sys/ioccom.h> @@ -79,10 +79,6 @@ #define DRM_DEV_GID 0 #endif -#if CONFIG_XFREE86_VERSION >= XFREE86_VERSION(4,1,0,0) -#define DRM_MAJOR 226 -#define DRM_MAX_MINOR 15 -#endif #define DRM_NAME "drm" /* Name in kernel, /dev, and /proc */ #define DRM_MIN_ORDER 5 /* At least 2^5 bytes = 32 bytes */ #define DRM_MAX_ORDER 22 /* Up to 2^22 bytes = 4MB */ @@ -409,6 +405,13 @@ unsigned long handle; /* Used for mapping / unmapping */ } drm_scatter_gather_t; +typedef struct drm_set_version { + int drm_di_major; + int drm_di_minor; + int drm_dd_major; + int drm_dd_minor; +} drm_set_version_t; + #define DRM_IOCTL_BASE 'd' #define DRM_IO(nr) _IO(DRM_IOCTL_BASE,nr) #define DRM_IOR(nr,type) _IOR(DRM_IOCTL_BASE,nr,type) @@ -422,6 +425,7 @@ #define DRM_IOCTL_GET_MAP DRM_IOWR(0x04, drm_map_t) #define DRM_IOCTL_GET_CLIENT DRM_IOWR(0x05, drm_client_t) #define DRM_IOCTL_GET_STATS DRM_IOR( 0x06, drm_stats_t) +#define DRM_IOCTL_SET_VERSION DRM_IOWR(0x07, drm_set_version_t) #define DRM_IOCTL_SET_UNIQUE DRM_IOW( 0x10, drm_unique_t) #define DRM_IOCTL_AUTH_MAGIC DRM_IOW( 0x11, drm_auth_t) ==== //depot/projects/hostcache/sys/dev/drm/drmP.h#2 (text+ko) ==== @@ -28,7 +28,7 @@ * Rickard E. (Rik) Faith <faith@valinux.com> * Gareth Hughes <gareth@valinux.com> * - * $FreeBSD: src/sys/dev/drm/drmP.h,v 1.6 2003/09/09 00:24:31 anholt Exp $ + * $FreeBSD: src/sys/dev/drm/drmP.h,v 1.7 2003/10/24 01:48:16 anholt Exp $ */ #ifndef _DRM_P_H_ @@ -50,8 +50,8 @@ #ifndef __HAVE_DMA #define __HAVE_DMA 0 #endif -#ifndef __HAVE_DMA_IRQ -#define __HAVE_DMA_IRQ 0 +#ifndef __HAVE_IRQ +#define __HAVE_IRQ 0 #endif #define DRM_DEBUG_CODE 0 /* Include debugging code (if > 1, then @@ -119,15 +119,19 @@ #define DRM_MIN(a,b) ((a)<(b)?(a):(b)) #define DRM_MAX(a,b) ((a)>(b)?(a):(b)) -#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1)) -#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x)) -#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist) - #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ (_map) = (_dev)->context_sareas[_ctx]; \ } while(0) +typedef struct drm_pci_id_list +{ + int vendor; + int device; + long driver_private; + char *name; +} drm_pci_id_list_t; + typedef struct drm_ioctl_desc { int (*func)(DRM_IOCTL_ARGS); int auth_needed; @@ -170,17 +174,6 @@ void *dev_private; /* Per-buffer private storage */ } drm_buf_t; - /* bufs is one longer than it has to be */ -typedef struct drm_waitlist { - int count; /* Number of possible buffers */ - drm_buf_t **bufs; /* List of pointers to buffers */ - drm_buf_t **rp; /* Read pointer */ - drm_buf_t **wp; /* Write pointer */ - drm_buf_t **end; /* End pointer */ - DRM_SPINTYPE read_lock; - DRM_SPINTYPE write_lock; -} drm_waitlist_t; - typedef struct drm_freelist { int initialized; /* Freelist in use */ atomic_t count; /* Number of free buffers */ @@ -188,7 +181,6 @@ int low_mark; /* Low water mark */ int high_mark; /* High water mark */ - DRM_SPINTYPE lock; } drm_freelist_t; typedef struct drm_buf_entry { @@ -224,10 +216,17 @@ typedef struct drm_lock_data { drm_hw_lock_t *hw_lock; /* Hardware lock */ DRMFILE filp; /* Unique identifier of holding process (NULL is kernel)*/ - wait_queue_head_t lock_queue; /* Queue of blocked processes */ + int lock_queue; /* Queue of blocked processes */ unsigned long lock_time; /* Time of last lock in jiffies */ } drm_lock_data_t; +/* This structure, in the drm_device_t, is always initialized while the device + * is open. dev->dma_lock protects the incrementing of dev->buf_use, which + * when set marks that no further bufs may be allocated until device teardown + * occurs (when the last open of the device has closed). The high/low + * watermarks of bufs are only touched by the X Server, and thus not + * concurrently accessed, so no locking is needed. + */ typedef struct drm_device_dma { drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; int buf_count; @@ -319,8 +318,15 @@ int flags; /* Flags to open(2) */ /* Locks */ - DRM_SPINTYPE count_lock; /* For open_count, buf_use, buf_alloc */ - struct lock dev_lock; /* For others */ +#if defined(__FreeBSD__) && __FreeBSD_version > 500000 +#if __HAVE_DMA + struct mtx dma_lock; /* protects dev->dma */ +#endif +#if __HAVE_IRQ + struct mtx irq_lock; /* protects irq condition checks */ +#endif + struct mtx dev_lock; /* protects everything else */ +#endif /* Usage Counters */ int open_count; /* Outstanding files open */ int buf_use; /* Buffers in use -- cannot alloc */ @@ -335,8 +341,8 @@ drm_file_list_t files; drm_magic_head_t magiclist[DRM_HASH_SIZE]; - /* Memory management */ - drm_map_list_t *maplist; /* Linked list of regions */ + /* Linked list of mappable regions. Protected by dev_lock */ + drm_map_list_t *maplist; drm_local_map_t **context_sareas; int max_context; @@ -357,19 +363,14 @@ #endif void *irqh; /* Handle from bus_setup_intr */ atomic_t context_flag; /* Context swapping flag */ - struct callout timer; /* Timer for delaying ctx switch */ int last_context; /* Last current context */ #if __FreeBSD_version >= 400005 struct task task; #endif #if __HAVE_VBL_IRQ - wait_queue_head_t vbl_queue; /* vbl wait channel */ + int vbl_queue; /* vbl wait channel */ atomic_t vbl_received; -#if 0 /* vbl signals are untested */ - struct drm_vbl_sig_list vbl_sig_list; - DRM_SPINTYPE vbl_lock; #endif -#endif #ifdef __FreeBSD__ struct sigio *buf_sigio; /* Processes waiting for SIGIO */ @@ -390,14 +391,6 @@ extern int DRM(flags); - /* Authentication (drm_auth.h) */ -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); - - /* Driver support (drm_drv.h) */ -extern int DRM(version)( DRM_IOCTL_ARGS ); - /* Memory management support (drm_memory.h) */ extern void DRM(mem_init)(void); extern void DRM(mem_uninit)(void); @@ -408,6 +401,8 @@ extern void DRM(free)(void *pt, size_t size, int area); extern void *DRM(ioremap)(drm_device_t *dev, drm_local_map_t *map); extern void DRM(ioremapfree)(drm_local_map_t *map); +extern int DRM(mtrr_add)(unsigned long offset, size_t size, int flags); +extern int DRM(mtrr_del)(unsigned long offset, size_t size, int flags); #if __REALLY_HAVE_AGP extern agp_memory *DRM(alloc_agp)(int pages, u32 type); @@ -445,26 +440,21 @@ 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, DRMFILE filp); -#if __HAVE_DMA_IRQ +#endif + +#if __HAVE_IRQ + /* IRQ support (drm_irq.h) */ extern int DRM(irq_install)( drm_device_t *dev, int irq ); extern int DRM(irq_uninstall)( drm_device_t *dev ); -extern irqreturn_t DRM(dma_service)( DRM_IRQ_ARGS ); +extern irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS ); extern void DRM(driver_irq_preinstall)( drm_device_t *dev ); extern void DRM(driver_irq_postinstall)( drm_device_t *dev ); extern void DRM(driver_irq_uninstall)( drm_device_t *dev ); -#if __HAVE_DMA_IRQ_BH -extern void DRM(dma_immediate_bh)( DRM_TASKQUEUE_ARGS ); +#if __HAVE_IRQ_BH +extern void DRM(irq_immediate_bh)( DRM_TASKQUEUE_ARGS ); #endif #endif - /* Buffer list support (drm_lists.h) */ -#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 -#endif /* __HAVE_DMA */ #if __HAVE_VBL_IRQ extern int DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq); extern void DRM(vbl_send_signals)( drm_device_t *dev ); @@ -499,6 +489,8 @@ /* Locking IOCTL support (drm_drv.h) */ extern int DRM(lock)(DRM_IOCTL_ARGS); extern int DRM(unlock)(DRM_IOCTL_ARGS); +extern int DRM(version)( DRM_IOCTL_ARGS ); +extern int DRM(setversion)( DRM_IOCTL_ARGS ); /* Misc. IOCTL support (drm_ioctl.h) */ extern int DRM(irq_busid)(DRM_IOCTL_ARGS); @@ -539,8 +531,8 @@ extern int DRM(mapbufs)(DRM_IOCTL_ARGS); #endif -/* DMA support (drm_dma.h) */ -#if __HAVE_DMA +/* IRQ support (drm_irq.h) */ +#if __HAVE_IRQ || __HAVE_DMA extern int DRM(control)(DRM_IOCTL_ARGS); #endif #if __HAVE_VBL_IRQ ==== //depot/projects/hostcache/sys/dev/drm/drm_auth.h#2 (text+ko) ==== @@ -28,7 +28,7 @@ * Rickard E. (Rik) Faith <faith@valinux.com> * Gareth Hughes <gareth@valinux.com> * - * $FreeBSD: src/sys/dev/drm/drm_auth.h,v 1.4 2003/08/19 02:57:31 anholt Exp $ + * $FreeBSD: src/sys/dev/drm/drm_auth.h,v 1.5 2003/10/24 01:48:16 anholt Exp $ */ #include "dev/drm/drmP.h" @@ -44,18 +44,18 @@ drm_magic_entry_t *pt; int hash = DRM(hash_magic)(magic); - DRM_LOCK; + DRM_LOCK(); for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { if (pt->magic == magic) { retval = pt->priv; break; } } - DRM_UNLOCK; + DRM_UNLOCK(); return retval; } -int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) +static int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv, drm_magic_t magic) { int hash; drm_magic_entry_t *entry; @@ -70,7 +70,7 @@ entry->priv = priv; entry->next = NULL; - DRM_LOCK; + DRM_LOCK(); if (dev->magiclist[hash].tail) { dev->magiclist[hash].tail->next = entry; dev->magiclist[hash].tail = entry; @@ -78,12 +78,12 @@ dev->magiclist[hash].head = entry; dev->magiclist[hash].tail = entry; } - DRM_UNLOCK; + DRM_UNLOCK(); return 0; } -int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic) +static int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic) { drm_magic_entry_t *prev = NULL; drm_magic_entry_t *pt; @@ -92,7 +92,7 @@ DRM_DEBUG("%d\n", magic); hash = DRM(hash_magic)(magic); - DRM_LOCK; + DRM_LOCK(); for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) { if (pt->magic == magic) { if (dev->magiclist[hash].head == pt) { @@ -104,11 +104,11 @@ if (prev) { prev->next = pt->next; } - DRM_UNLOCK; + DRM_UNLOCK(); return 0; } } - DRM_UNLOCK; + DRM_UNLOCK(); DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC); return DRM_ERR(EINVAL); @@ -117,9 +117,11 @@ int DRM(getmagic)(DRM_IOCTL_ARGS) { static drm_magic_t sequence = 0; - drm_auth_t auth; + drm_auth_t auth; + drm_file_t *priv; DRM_DEVICE; - DRM_PRIV; + + DRM_GET_PRIV_WITH_RETURN(priv, filp); /* Find unique magic */ if (priv->magic) { @@ -153,6 +155,7 @@ DRM_COPY_FROM_USER_IOCTL(auth, (drm_auth_t *)data, sizeof(auth)); DRM_DEBUG("%u\n", auth.magic); + if ((file = DRM(find_file)(dev, auth.magic))) { file->authenticated = 1; DRM(remove_magic)(dev, auth.magic); ==== //depot/projects/hostcache/sys/dev/drm/drm_bufs.h#2 (text+ko) ==== @@ -28,7 +28,7 @@ * Rickard E. (Rik) Faith <faith@valinux.com> * Gareth Hughes <gareth@valinux.com> * - * $FreeBSD: src/sys/dev/drm/drm_bufs.h,v 1.6 2003/08/19 02:57:31 anholt Exp $ + * $FreeBSD: src/sys/dev/drm/drm_bufs.h,v 1.7 2003/10/24 01:48:16 anholt Exp $ */ #include "dev/drm/drmP.h" @@ -116,25 +116,12 @@ #if __REALLY_HAVE_MTRR if ( map->type == _DRM_FRAME_BUFFER || (map->flags & _DRM_WRITE_COMBINING) ) { -#ifdef __FreeBSD__ - int retcode = 0, act; - struct mem_range_desc mrdesc; - mrdesc.mr_base = map->offset; - mrdesc.mr_len = map->size; - mrdesc.mr_flags = MDF_WRITECOMBINE; - act = MEMRANGE_SET_UPDATE; - bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME)); - retcode = mem_range_attr_set(&mrdesc, &act); - map->mtrr=1; -#elif defined __NetBSD__ - struct mtrr mtrrmap; - int one = 1; - mtrrmap.base = map->offset; - mtrrmap.len = map->size; - mtrrmap.type = MTRR_TYPE_WC; - mtrrmap.flags = MTRR_VALID; - map->mtrr = mtrr_set( &mtrrmap, &one, p, MTRR_GETSET_KERNEL ); -#endif + int mtrr; + + mtrr = DRM(mtrr_add)(map->offset, map->size, + DRM_MTRR_WC); + if (mtrr == 0) + map->mtrr = 1; } #endif /* __REALLY_HAVE_MTRR */ DRM_IOREMAP(map, dev); @@ -172,17 +159,16 @@ return DRM_ERR(EINVAL); } - list = DRM(alloc)(sizeof(*list), DRM_MEM_MAPS); - if(!list) { + list = DRM(calloc)(1, sizeof(*list), DRM_MEM_MAPS); + if (list == NULL) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); return DRM_ERR(EINVAL); } - memset(list, 0, sizeof(*list)); list->map = map; - DRM_LOCK; + DRM_LOCK(); TAILQ_INSERT_TAIL(dev->maplist, list, link); - DRM_UNLOCK; + DRM_UNLOCK(); request.offset = map->offset; request.size = map->size; @@ -211,69 +197,49 @@ drm_map_list_entry_t *list; drm_local_map_t *map; drm_map_t request; - int found_maps = 0; DRM_COPY_FROM_USER_IOCTL( request, (drm_map_t *)data, sizeof(request) ); - DRM_LOCK; + DRM_LOCK(); TAILQ_FOREACH(list, dev->maplist, link) { map = list->map; - if(map->handle == request.handle && - map->flags & _DRM_REMOVABLE) break; + if (map->handle == request.handle && + map->flags & _DRM_REMOVABLE) + break; } - /* List has wrapped around to the head pointer, or its empty we didn't - * find anything. - */ - if(list == NULL) { - DRM_UNLOCK; + /* No match found. */ + if (list == NULL) { + DRM_UNLOCK(); return DRM_ERR(EINVAL); } TAILQ_REMOVE(dev->maplist, list, link); + DRM_UNLOCK(); + DRM(free)(list, sizeof(*list), DRM_MEM_MAPS); - - if(!found_maps) { - switch (map->type) { - case _DRM_REGISTERS: - case _DRM_FRAME_BUFFER: + switch (map->type) { + case _DRM_REGISTERS: + case _DRM_FRAME_BUFFER: #if __REALLY_HAVE_MTRR - if (map->mtrr >= 0) { - int retcode; -#ifdef __FreeBSD__ - int act; - struct mem_range_desc mrdesc; - mrdesc.mr_base = map->offset; - mrdesc.mr_len = map->size; - mrdesc.mr_flags = MDF_WRITECOMBINE; - act = MEMRANGE_SET_REMOVE; - bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME)); - retcode = mem_range_attr_set(&mrdesc, &act); -#elif defined __NetBSD__ - struct mtrr mtrrmap; - int one = 1; - mtrrmap.base = map->offset; - mtrrmap.len = map->size; - mtrrmap.type = 0; - mtrrmap.flags = 0; - mtrrmap.owner = p->p_pid; - retcode = mtrr_set( &mtrrmap, &one, p, MTRR_GETSET_KERNEL); - DRM_DEBUG("mtrr_del = %d\n", retcode); + if (map->mtrr >= 0) { + int __unused mtrr; + + mtrr = DRM(mtrr_del)(map->offset, map->size, + DRM_MTRR_WC); + DRM_DEBUG("mtrr_del = %d\n", mtrr); + } #endif - } -#endif - DRM(ioremapfree)( map ); - break; - case _DRM_SHM: - DRM(free)( map->handle, map->size, DRM_MEM_SAREA ); - break; - case _DRM_AGP: - case _DRM_SCATTER_GATHER: - break; - } - DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); + DRM(ioremapfree)(map); + break; + case _DRM_SHM: + DRM(free)(map->handle, map->size, DRM_MEM_SAREA); + break; + case _DRM_AGP: + case _DRM_SCATTER_GATHER: + break; } - DRM_UNLOCK; + DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); return 0; } @@ -355,20 +321,11 @@ DRM_DEBUG( "page_order: %d\n", page_order ); DRM_DEBUG( "total: %d\n", total ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) - return DRM_ERR(EINVAL); - - DRM_LOCK; entry = &dma->bufs[order]; - if ( entry->buf_count ) { - DRM_UNLOCK; - return DRM_ERR(ENOMEM); /* May only call once for each order */ - } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - DRM_UNLOCK; return DRM_ERR(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -393,16 +350,14 @@ buf->filp = NULL; buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T); - buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T), - DRM_MEM_BUFS ); - if(!buf->dev_private) { + buf->dev_private = DRM(calloc)(1, buf->dev_priv_size, + DRM_MEM_BUFS); + if (buf->dev_private == NULL) { /* Set count correctly so we free the proper amount. */ entry->buf_count = count; DRM(cleanup_buf_error)(dev, entry); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } - memset( buf->dev_private, 0, buf->dev_priv_size ); offset += alignment; entry->buf_count++; @@ -416,10 +371,9 @@ (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), DRM_MEM_BUFS ); - if(!temp_buflist) { + if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ DRM(cleanup_buf_error)(dev, entry); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } dma->buflist = temp_buflist; @@ -434,8 +388,6 @@ DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count ); DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count ); - DRM_UNLOCK; - request->count = entry->buf_count; request->size = size; @@ -473,20 +425,12 @@ DRM_DEBUG( "count=%d, size=%d (%d), order=%d\n", request->count, request->size, size, order ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) - return DRM_ERR(EINVAL); - alignment = (request->flags & _DRM_PAGE_ALIGN) ? round_page(size) : size; page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0; total = PAGE_SIZE << page_order; - DRM_LOCK; entry = &dma->bufs[order]; - if ( entry->buf_count ) { - DRM_UNLOCK; - return DRM_ERR(ENOMEM); /* May only call once for each order */ - } entry->buflist = DRM(alloc)(count * sizeof(*entry->buflist), DRM_MEM_BUFS); @@ -509,7 +453,6 @@ DRM_MEM_SEGS); DRM(free)(entry->seglist_bus, count * sizeof(*entry->seglist_bus), DRM_MEM_SEGS); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } @@ -538,7 +481,6 @@ DRM(free)(temp_pagelist, (dma->page_count + (count << page_order)) * sizeof(*dma->pagelist), DRM_MEM_PAGES); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } @@ -577,7 +519,6 @@ DRM(free)(temp_pagelist, (dma->page_count + (count << page_order)) * sizeof(*dma->pagelist), DRM_MEM_PAGES ); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } bzero(buf->dev_private, buf->dev_priv_size); @@ -599,7 +540,6 @@ DRM(free)(temp_pagelist, (dma->page_count + (count << page_order)) * sizeof(*dma->pagelist), DRM_MEM_PAGES); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } dma->buflist = temp_buflist; @@ -620,8 +560,6 @@ dma->page_count += entry->seg_count << page_order; dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order); - DRM_UNLOCK; - request->count = entry->buf_count; request->size = size; @@ -668,23 +606,12 @@ DRM_DEBUG( "page_order: %d\n", page_order ); DRM_DEBUG( "total: %d\n", total ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) - return DRM_ERR(EINVAL); - - DRM_LOCK; entry = &dma->bufs[order]; - if ( entry->buf_count ) { - DRM_UNLOCK; - return DRM_ERR(ENOMEM); /* May only call once for each order */ - } - entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), - DRM_MEM_BUFS ); - if ( !entry->buflist ) { - DRM_UNLOCK; + entry->buflist = DRM(calloc)(1, count * sizeof(*entry->buflist), + DRM_MEM_BUFS); + if (entry->buflist == NULL) return DRM_ERR(ENOMEM); - } - memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); entry->buf_size = size; entry->page_order = page_order; @@ -706,18 +633,15 @@ buf->filp = NULL; buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T); - buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T), - DRM_MEM_BUFS ); - if(!buf->dev_private) { + buf->dev_private = DRM(calloc)(1, buf->dev_priv_size, + DRM_MEM_BUFS); + if (buf->dev_private == NULL) { /* Set count correctly so we free the proper amount. */ entry->buf_count = count; DRM(cleanup_buf_error)(dev, entry); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } - memset( buf->dev_private, 0, buf->dev_priv_size ); - DRM_DEBUG( "buffer %d @ %p\n", entry->buf_count, buf->address ); @@ -733,10 +657,9 @@ (dma->buf_count + entry->buf_count) * sizeof(*dma->buflist), DRM_MEM_BUFS ); - if(!temp_buflist) { + if (temp_buflist == NULL) { /* Free the entry because it isn't valid */ DRM(cleanup_buf_error)(dev, entry); - DRM_UNLOCK; return DRM_ERR(ENOMEM); } dma->buflist = temp_buflist; @@ -751,8 +674,6 @@ DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count ); DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count ); - DRM_UNLOCK; - request->count = entry->buf_count; request->size = size; @@ -767,26 +688,29 @@ DRM_DEVICE; drm_buf_desc_t request; int err; + int order; DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) ); - if (dev->dma == NULL) + if (request.count < 0 || request.count > 4096) return DRM_ERR(EINVAL); - if (request.count < 0 || request.count > 4096) + order = DRM(order)(request.size); + if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER) return DRM_ERR(EINVAL); - DRM_SPINLOCK(&dev->count_lock); - if (dev->buf_use) { - DRM_SPINUNLOCK(&dev->count_lock); + DRM_SPINLOCK(&dev->dma_lock); + /* No more allocations after first buffer-using ioctl. */ + if (dev->buf_use != 0) { + DRM_SPINUNLOCK(&dev->dma_lock); return DRM_ERR(EBUSY); } - /* dev->buf_alloc acts as a lock to prevent infobufs/mapbufs from - * trying to read from the dma->bufs while buffers are being allocated */ - dev->buf_alloc++; - DRM_SPINUNLOCK(&dev->count_lock); + /* No more than one allocation per order */ + if (dev->dma->bufs[order].buf_count != 0) { + DRM_SPINUNLOCK(&dev->dma_lock); + return DRM_ERR(ENOMEM); + } - #if __REALLY_HAVE_AGP if ( request.flags & _DRM_AGP_BUFFER ) err = DRM(addbufs_agp)(dev, &request); @@ -802,13 +726,10 @@ #else err = DRM_ERR(EINVAL); #endif + DRM_SPINUNLOCK(&dev->dma_lock); DRM_COPY_TO_USER_IOCTL((drm_buf_desc_t *)data, request, sizeof(request)); - DRM_SPINLOCK(&dev->count_lock); - dev->buf_alloc--; - DRM_SPINUNLOCK(&dev->count_lock); - return err; } @@ -819,18 +740,13 @@ drm_buf_info_t request; int i; int count; + int retcode = 0; - if ( !dma ) return DRM_ERR(EINVAL); + DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_info_t *)data, sizeof(request) ); - DRM_SPINLOCK( &dev->count_lock ); - if (dev->buf_alloc != 0) { - DRM_SPINUNLOCK( &dev->count_lock ); - return DRM_ERR(EBUSY); - } + DRM_SPINLOCK(&dev->dma_lock); ++dev->buf_use; /* Can't allocate more after this call */ - DRM_SPINUNLOCK( &dev->count_lock ); - - DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_info_t *)data, sizeof(request) ); + DRM_SPINUNLOCK(&dev->dma_lock); for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) { if ( dma->bufs[i].buf_count ) ++count; @@ -849,8 +765,10 @@ from.high_mark = dma->bufs[i].freelist.high_mark; if (DRM_COPY_TO_USER(&request.list[count], &from, - sizeof(drm_buf_desc_t)) != 0) - return DRM_ERR(EFAULT); + sizeof(drm_buf_desc_t)) != 0) { + retcode = DRM_ERR(EFAULT); + break; + } DRM_DEBUG( "%d %d %d %d %d\n", i, @@ -866,7 +784,7 @@ DRM_COPY_TO_USER_IOCTL( (drm_buf_info_t *)data, request, sizeof(request) ); - return 0; + return retcode; } int DRM(markbufs)( DRM_IOCTL_ARGS ) @@ -875,26 +793,28 @@ drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; int order; - drm_buf_entry_t *entry; - - if ( !dma ) return DRM_ERR(EINVAL); DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) ); 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 ) + + + order = DRM(order)(request.size); + if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER || + request.low_mark < 0 || request.high_mark < 0) { return DRM_ERR(EINVAL); - entry = &dma->bufs[order]; + } - if ( request.low_mark < 0 || request.low_mark > entry->buf_count ) + DRM_SPINLOCK(&dev->dma_lock); + if (request.low_mark > dma->bufs[order].buf_count || + request.high_mark > dma->bufs[order].buf_count) { return DRM_ERR(EINVAL); - if ( request.high_mark < 0 || request.high_mark > entry->buf_count ) - return DRM_ERR(EINVAL); + } - entry->freelist.low_mark = request.low_mark; - entry->freelist.high_mark = request.high_mark; + dma->bufs[order].freelist.low_mark = request.low_mark; + dma->bufs[order].freelist.high_mark = request.high_mark; + DRM_SPINUNLOCK(&dev->dma_lock); return 0; } @@ -907,32 +827,36 @@ int i; int idx; drm_buf_t *buf; - - if ( !dma ) return DRM_ERR(EINVAL); + int retcode = 0; DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_free_t *)data, sizeof(request) ); DRM_DEBUG( "%d\n", request.count ); + + DRM_SPINLOCK(&dev->dma_lock); for ( i = 0 ; i < request.count ; i++ ) { - if ( DRM_COPY_FROM_USER( &idx, - &request.list[i], - sizeof(idx) ) ) - return DRM_ERR(EFAULT); + if (DRM_COPY_FROM_USER(&idx, &request.list[i], sizeof(idx))) { + retcode = DRM_ERR(EFAULT); + break; + } if ( idx < 0 || idx >= dma->buf_count ) { DRM_ERROR( "Index %d (of %d max)\n", >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200310240346.h9O3kQiV015907>