Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Aug 2005 01:22:27 GMT
From:      Eric Anholt <anholt@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 82574 for review
Message-ID:  <200508260122.j7Q1MR6s003408@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82574

Change 82574 by anholt@anholt_leguin on 2005/08/26 01:21:31

	Initial merge of 2005-08-25 DRM vendor branch.	

Affected files ...

.. //depot/projects/drm-merge/sys/dev/drm/ati_pcigart.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm.h#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drmP.h#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_agpsupport.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_bufs.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_context.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_dma.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_drv.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_fops.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_ioctl.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_irq.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_lock.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_pci.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_pciids.h#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_scatter.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_sysctl.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/drm_vm.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/i915_dma.c#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/i915_drm.h#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/i915_drv.c#4 integrate
.. //depot/projects/drm-merge/sys/dev/drm/i915_drv.h#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/i915_irq.c#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/i915_mem.c#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mach64_dma.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mach64_drv.c#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mach64_drv.h#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mach64_state.c#4 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_dma.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_drm.h#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_drv.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_drv.h#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_irq.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_state.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/mga_warp.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/r128_cce.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/r128_drm.h#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/r128_drv.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/r128_drv.h#5 integrate
.. //depot/projects/drm-merge/sys/dev/drm/r128_state.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/radeon_cp.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/radeon_drm.h#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/radeon_drv.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/radeon_drv.h#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/radeon_irq.c#6 integrate
.. //depot/projects/drm-merge/sys/dev/drm/radeon_state.c#8 integrate
.. //depot/projects/drm-merge/sys/dev/drm/savage_bci.c#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/savage_drv.c#4 integrate
.. //depot/projects/drm-merge/sys/dev/drm/savage_drv.h#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/savage_state.c#3 integrate
.. //depot/projects/drm-merge/sys/dev/drm/sis_drv.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/sis_mm.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/tdfx_drv.c#7 integrate
.. //depot/projects/drm-merge/sys/dev/drm/via_3d_reg.h#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_dma.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_drm.h#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_drv.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_drv.h#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_ds.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_ds.h#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_irq.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_map.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_mm.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_mm.h#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_verifier.c#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_verifier.h#1 branch
.. //depot/projects/drm-merge/sys/dev/drm/via_video.c#1 branch

Differences ...

==== //depot/projects/drm-merge/sys/dev/drm/ati_pcigart.c#5 (text+ko) ====

@@ -32,85 +32,72 @@
 
 #include "dev/drm/drmP.h"
 
-#if PAGE_SIZE == 8192
-# define ATI_PCIGART_TABLE_ORDER 	2
-# define ATI_PCIGART_TABLE_PAGES 	(1 << 2)
-#elif PAGE_SIZE == 4096
-# define ATI_PCIGART_TABLE_ORDER 	3
-# define ATI_PCIGART_TABLE_PAGES 	(1 << 3)
-#elif
-# error - PAGE_SIZE not 8K or 4K
-#endif
+#define ATI_PCIGART_PAGE_SIZE		4096	/* PCI GART page size */
+#define ATI_MAX_PCIGART_PAGES		8192	/* 32 MB aperture, 4K pages */
+#define ATI_PCIGART_TABLE_SIZE		32768
 
-# define ATI_MAX_PCIGART_PAGES		8192	/* 32 MB aperture, 4K pages */
-# define ATI_PCIGART_PAGE_SIZE		4096	/* PCI GART page size */
-
 int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
-			 dma_addr_t *bus_addr)
+			 dma_addr_t *bus_addr, int is_pcie)
 {
-	drm_sg_mem_t *entry = dev->sg;
-	unsigned long address = 0;
 	unsigned long pages;
-	u32 *pci_gart=0, page_base, bus_address = 0;
-	int i, j, ret = 0;
+	u32 *pci_gart = 0, page_base;
+	int i, j;
+
+	*addr = 0;
+	*bus_addr = 0;
 
-	if ( !entry ) {
+	if (dev->sg == NULL) {
 		DRM_ERROR( "no scatter/gather memory!\n" );
-		goto done;
+		return 0;
 	}
 
-	address = (long)contigmalloc((1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE, 
-	    M_DRM, M_NOWAIT, 0ul, 0xfffffffful, PAGE_SIZE, 0);
-	if ( !address ) {
-		DRM_ERROR( "cannot allocate PCI GART page!\n" );
-		goto done;
+	dev->sg->dmah = drm_pci_alloc(dev, ATI_PCIGART_TABLE_SIZE, 0,
+	    0xfffffffful);
+	if (dev->sg->dmah == NULL) {
+		DRM_ERROR("cannot allocate PCI GART table!\n");
+		return 0;
 	}
 
-	/* XXX: we need to busdma this */
-	bus_address = vtophys( address );
+	*addr = (long)dev->sg->dmah->vaddr;
+	*bus_addr = dev->sg->dmah->busaddr;
+	pci_gart = (u32 *)dev->sg->dmah->vaddr;
 
-	pci_gart = (u32 *)address;
+	pages = DRM_MIN(dev->sg->pages, ATI_MAX_PCIGART_PAGES);
 
-	pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
-		? entry->pages : ATI_MAX_PCIGART_PAGES;
+	bzero(pci_gart, ATI_PCIGART_TABLE_SIZE);
 
-	bzero( pci_gart, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
+	KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE, "page size too small");
 
 	for ( i = 0 ; i < pages ; i++ ) {
-		entry->busaddr[i] = vtophys( entry->handle + (i*PAGE_SIZE) );
-		page_base = (u32) entry->busaddr[i];
+		page_base = (u32) dev->sg->busaddr[i];
 
 		for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
-			*pci_gart++ = cpu_to_le32( page_base );
+			if (is_pcie) {
+				*pci_gart = (cpu_to_le32(page_base)>>8) | 0xc;
+				DRM_DEBUG("PCIE: %d %08X %08X to %p\n", i,
+				    page_base, (cpu_to_le32(page_base)>>8)|0xc,
+				    pci_gart);
+			} else
+				*pci_gart = cpu_to_le32(page_base);
+			pci_gart++;
 			page_base += ATI_PCIGART_PAGE_SIZE;
 		}
 	}
 
 	DRM_MEMORYBARRIER();
 
-	ret = 1;
-
-done:
-	*addr = address;
-	*bus_addr = bus_address;
-	return ret;
+	return 1;
 }
 
 int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr,
 			    dma_addr_t bus_addr)
 {
-	drm_sg_mem_t *entry = dev->sg;
-
-	/* we need to support large memory configurations */
-	if ( !entry ) {
+	if (dev->sg == NULL) {
 		DRM_ERROR( "no scatter/gather memory!\n" );
 		return 0;
 	}
 
-#if __FreeBSD_version > 500000
-	/* Not available on 4.x */
-	contigfree((void *)addr, (1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE,
-		   M_DRM);
-#endif
+	drm_pci_free(dev, dev->sg->dmah);
+
 	return 1;
 }

==== //depot/projects/drm-merge/sys/dev/drm/drm.h#5 (text+ko) ====

@@ -64,8 +64,16 @@
 #define __user
 #endif
 
+#ifdef __GNUC__
+# define DEPRECATED  __attribute__ ((deprecated))
+#else
+# define DEPRECATED
+#endif
+
 #if defined(__linux__)
+#if defined(__KERNEL__)
 #include <linux/config.h>
+#endif
 #include <asm/ioctl.h>		/* For _IO* macros */
 #define DRM_IOCTL_NR(n)		_IOC_NR(n)
 #define DRM_IOC_VOID		_IOC_NONE
@@ -73,7 +81,7 @@
 #define DRM_IOC_WRITE		_IOC_WRITE
 #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__)
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
 #if defined(__FreeBSD__) && defined(IN_MODULE)
 /* Prevent name collision when including sys/ioccom.h */
 #undef ioctl
@@ -127,7 +135,11 @@
 #define _DRM_LOCK_IS_CONT(lock)	   ((lock) & _DRM_LOCK_CONT)
 #define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
 
+#if defined(__linux__)
+typedef unsigned int drm_handle_t;
+#else
 typedef unsigned long drm_handle_t;	/**< To mapped regions */
+#endif
 typedef unsigned int drm_context_t;	/**< GLXContext handle */
 typedef unsigned int drm_drawable_t;
 typedef unsigned int drm_magic_t;	/**< Magic for authentication */
@@ -439,7 +451,11 @@
  */
 typedef struct drm_buf_map {
 	int count;		/**< Length of the buffer list */
+#if defined(__cplusplus)
+	void __user *c_virtual;
+#else
 	void __user *virtual;		/**< Mmap'd area in user-virtual */
+#endif
 	drm_buf_pub_t __user *list;	/**< Buffer information */
 } drm_buf_map_t;
 

==== //depot/projects/drm-merge/sys/dev/drm/drmP.h#7 (text+ko) ====

@@ -216,6 +216,13 @@
 #define IRQ_HANDLED		/* nothing */
 #define IRQ_NONE		/* nothing */
 
+enum {
+	DRM_IS_NOT_AGP,
+	DRM_MIGHT_BE_AGP,
+	DRM_IS_AGP
+};
+#define DRM_AGP_MEM		struct agp_memory_info
+
 #if defined(__FreeBSD__)
 #define DRM_DEVICE							\
 	drm_device_t *dev = kdev->si_drv1
@@ -223,7 +230,8 @@
 				int flags, DRM_STRUCTPROC *p, DRMFILE filp
 
 #define PAGE_ALIGN(addr) round_page(addr)
-#define DRM_SUSER(p)		suser(p)
+/* DRM_SUSER returns true if the user is superuser */
+#define DRM_SUSER(p)		(suser(p) == 0)
 #define DRM_AGP_FIND_DEVICE()	agp_find_device()
 #define DRM_MTRR_WC		MDF_WRITECOMBINE
 #define jiffies			ticks
@@ -243,7 +251,8 @@
 
 #define CDEV_MAJOR		34
 #define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
-#define DRM_SUSER(p)		suser(p->p_ucred, &p->p_acflag)
+/* DRM_SUSER returns true if the user is superuser */
+#define DRM_SUSER(p)		(suser(p->p_ucred, &p->p_acflag) == 0)
 #define DRM_AGP_FIND_DEVICE()	agp_find_device(0)
 #define DRM_MTRR_WC		MTRR_TYPE_WC
 #define jiffies			hardclock_ticks
@@ -443,6 +452,7 @@
 typedef struct drm_ioctl_desc {
 	int		     (*func)(DRM_IOCTL_ARGS);
 	int		     auth_needed;
+	int		     master;
 	int		     root_only;
 } drm_ioctl_desc_t;
 
@@ -491,14 +501,24 @@
 	int		  high_mark;   /* High water mark		   */
 } drm_freelist_t;
 
+typedef struct drm_dma_handle {
+	void *vaddr;
+	bus_addr_t busaddr;
+#if defined(__FreeBSD__)
+	bus_dma_tag_t tag;
+	bus_dmamap_t map;
+#elif defined(__NetBSD__)
+	bus_dma_segment_t seg;
+#endif
+} drm_dma_handle_t;
+
 typedef struct drm_buf_entry {
 	int		  buf_size;
 	int		  buf_count;
 	drm_buf_t	  *buflist;
 	int		  seg_count;
+	drm_dma_handle_t  **seglist;
 	int		  page_order;
-	vm_offset_t	  *seglist;
-	dma_addr_t	  *seglist_bus;
 
 	drm_freelist_t	  freelist;
 } drm_buf_entry_t;
@@ -507,6 +527,7 @@
 struct drm_file {
 	TAILQ_ENTRY(drm_file) link;
 	int		  authenticated;
+	int		  master;
 	int		  minor;
 	pid_t		  pid;
 	uid_t		  uid;
@@ -571,6 +592,7 @@
 	void            *virtual;
 	int             pages;
 	dma_addr_t	*busaddr;
+	drm_dma_handle_t *dmah;	/* Handle to PCI memory for ATI PCIGART table */
 } drm_sg_mem_t;
 
 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
@@ -585,10 +607,10 @@
 	int		mtrr;	 /* Boolean: MTRR used */
 				 /* Private data			    */
 	int		rid;	 /* PCI resource ID for bus_space */
-	int		kernel_owned; /* Boolean: 1 = initmapped, 0 = addmapped */
 	struct resource *bsr;
 	bus_space_tag_t bst;
 	bus_space_handle_t bsh;
+	drm_dma_handle_t *dmah;
 	TAILQ_ENTRY(drm_local_map) link;
 } drm_local_map_t;
 
@@ -600,25 +622,15 @@
 	int		pid;
 } drm_vbl_sig_t;
 
-/** 
- * DRM device functions structure
- */
-struct drm_device {
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-	struct device	  device; /* softc is an extension of struct device */
-#endif
-
-	/* Beginning of driver-config section */
-	int	(*preinit)(struct drm_device *, unsigned long flags);
-	int	(*postinit)(struct drm_device *, unsigned long flags);
-	void	(*prerelease)(struct drm_device *, void *filp);
-	void	(*pretakedown)(struct drm_device *);
-	int	(*postcleanup)(struct drm_device *);
-	int	(*presetup)(struct drm_device *);
-	int	(*postsetup)(struct drm_device *);
-	int	(*open_helper)(struct drm_device *, drm_file_t *);
-	void	(*free_filp_priv)(struct drm_device *, drm_file_t *);
-	void	(*release)(struct drm_device *, void *filp);
+struct drm_driver_info {
+	int	(*load)(struct drm_device *, unsigned long flags);
+	int	(*firstopen)(struct drm_device *);
+	int	(*open)(struct drm_device *, drm_file_t *);
+	void	(*preclose)(struct drm_device *, void *filp);
+	void	(*postclose)(struct drm_device *, drm_file_t *);
+	void	(*lastclose)(struct drm_device *);
+	int	(*unload)(struct drm_device *);
+	void	(*reclaim_buffers_locked)(struct drm_device *, void *filp);
 	int	(*dma_ioctl)(DRM_IOCTL_ARGS);
 	void	(*dma_ready)(struct drm_device *);
 	int	(*dma_quiescent)(struct drm_device *);
@@ -637,17 +649,32 @@
 	void	(*irq_handler)(DRM_IRQ_ARGS);
 	int	(*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
 
-	drm_ioctl_desc_t *driver_ioctls;
-	int	max_driver_ioctl;
+	drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
+
+	/**
+	 * Called by \c drm_device_is_agp.  Typically used to determine if a
+	 * card is really attached to AGP or not.
+	 *
+	 * \param dev  DRM device handle
+	 *
+	 * \returns 
+	 * One of three values is returned depending on whether or not the
+	 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
+	 * (return of 1), or may or may not be AGP (return of 2).
+	 */
+	int	(*device_is_agp) (struct drm_device * dev);
+
+	drm_ioctl_desc_t *ioctls;
+	int	max_ioctl;
 
-	int	dev_priv_size;
+	int	buf_priv_size;
 
-	int	driver_major;
-	int	driver_minor;
-	int	driver_patchlevel;
-	const char *driver_name;	/* Simple driver name		   */
-	const char *driver_desc;	/* Longer driver name		   */
-	const char *driver_date;	/* Date of last major changes.	   */
+	int	major;
+	int	minor;
+	int	patchlevel;
+	const char *name;		/* Simple driver name		   */
+	const char *desc;		/* Longer driver name		   */
+	const char *date;		/* Date of last major changes.	   */
 
 	unsigned use_agp :1;
 	unsigned require_agp :1;
@@ -658,7 +685,18 @@
 	unsigned use_irq :1;
 	unsigned use_vbl_irq :1;
 	unsigned use_mtrr :1;
-	/* End of driver-config section */
+};
+
+/** 
+ * DRM device functions structure
+ */
+struct drm_device {
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+	struct device	  device; /* softc is an extension of struct device */
+#endif
+
+	struct drm_driver_info driver;
+	drm_pci_id_list_t *id_entry;	/* PCI ID, name, and chipset private */
 
 	char		  *unique;	/* Unique identifier: e.g., busid  */
 	int		  unique_len;	/* Length of unique field	   */
@@ -708,7 +746,6 @@
 	struct resource   *irqr;	/* Resource for interrupt used by board	   */
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
 	struct pci_attach_args  pa;
-	pci_intr_handle_t	ih;
 #endif
 	void		  *irqh;	/* Handle from bus_setup_intr      */
 
@@ -735,6 +772,7 @@
 	drm_sg_mem_t      *sg;  /* Scatter gather memory */
 	atomic_t          *ctx_bitmap;
 	void		  *dev_private;
+	unsigned int	  agp_buffer_token;
 	drm_local_map_t   *agp_buffer_map;
 };
 
@@ -809,10 +847,14 @@
 /* Buffer management support (drm_bufs.c) */
 unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
-int	drm_initmap(drm_device_t *dev, unsigned long start, unsigned long len,
-		    unsigned int resource, int type, int flags);
-void	drm_remove_map(drm_device_t *dev, drm_local_map_t *map);
+void	drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
 int	drm_order(unsigned long size);
+int	drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
+		   drm_map_type_t type, drm_map_flags_t flags,
+		   drm_local_map_t **map_ptr);
+int	drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
+int	drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request);
+int	drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
 
 /* DMA support (drm_dma.c) */
 int	drm_dma_setup(drm_device_t *dev);
@@ -835,11 +877,18 @@
 int	drm_device_is_pcie(drm_device_t *dev);
 drm_agp_head_t *drm_agp_init(void);
 void	drm_agp_uninit(void);
-void	drm_agp_do_release(void);
+int	drm_agp_acquire(drm_device_t *dev);
+int	drm_agp_release(drm_device_t *dev);
+int	drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
+int	drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
 void	*drm_agp_allocate_memory(size_t pages, u32 type);
 int	drm_agp_free_memory(void *handle);
 int	drm_agp_bind_memory(void *handle, off_t start);
 int	drm_agp_unbind_memory(void *handle);
+#define drm_alloc_agp(dev, pages, type) drm_agp_allocate_memory(pages, type)
+#define drm_free_agp(handle, pages) drm_agp_free_memory(handle)
+#define drm_bind_agp(handle, start) drm_agp_bind_memory(handle, start)
+#define drm_unbind_agp(handle) drm_agp_unbind_memory(handle)
 
 /* Scatter Gather Support (drm_scatter.c) */
 void	drm_sg_cleanup(drm_sg_mem_t *entry);
@@ -852,7 +901,7 @@
 
 /* ATI PCIGART support (ati_pcigart.c) */
 int	drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
-			     dma_addr_t *bus_addr);
+			     dma_addr_t *bus_addr, int is_pcie);
 int	drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr,
 				dma_addr_t bus_addr);
 
@@ -891,9 +940,9 @@
 int	drm_authmagic(DRM_IOCTL_ARGS);
 
 /* Buffer management support (drm_bufs.c) */
-int	drm_addmap(DRM_IOCTL_ARGS);
-int	drm_rmmap(DRM_IOCTL_ARGS);
-int	drm_addbufs(DRM_IOCTL_ARGS);
+int	drm_addmap_ioctl(DRM_IOCTL_ARGS);
+int	drm_rmmap_ioctl(DRM_IOCTL_ARGS);
+int	drm_addbufs_ioctl(DRM_IOCTL_ARGS);
 int	drm_infobufs(DRM_IOCTL_ARGS);
 int	drm_markbufs(DRM_IOCTL_ARGS);
 int	drm_freebufs(DRM_IOCTL_ARGS);
@@ -907,10 +956,10 @@
 int	drm_wait_vblank(DRM_IOCTL_ARGS);
 
 /* AGP/GART support (drm_agpsupport.c) */
-int	drm_agp_acquire(DRM_IOCTL_ARGS);
-int	drm_agp_release(DRM_IOCTL_ARGS);
-int	drm_agp_enable(DRM_IOCTL_ARGS);
-int	drm_agp_info(DRM_IOCTL_ARGS);
+int	drm_agp_acquire_ioctl(DRM_IOCTL_ARGS);
+int	drm_agp_release_ioctl(DRM_IOCTL_ARGS);
+int	drm_agp_enable_ioctl(DRM_IOCTL_ARGS);
+int	drm_agp_info_ioctl(DRM_IOCTL_ARGS);
 int	drm_agp_alloc(DRM_IOCTL_ARGS);
 int	drm_agp_free(DRM_IOCTL_ARGS);
 int	drm_agp_unbind(DRM_IOCTL_ARGS);
@@ -921,10 +970,9 @@
 int	drm_sg_free(DRM_IOCTL_ARGS);
 
 /* consistent PCI memory functions (drm_pci.c) */
-void	*drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
-		       dma_addr_t maxaddr, dma_addr_t *busaddr);
-void	drm_pci_free(drm_device_t *dev, size_t size, void *vaddr,
-		     dma_addr_t busaddr);
+drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
+				dma_addr_t maxaddr);
+void	drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
 
 /* Inline replacements for DRM_IOREMAP macros */
 static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)

==== //depot/projects/drm-merge/sys/dev/drm/drm_agpsupport.c#5 (text+ko) ====

@@ -39,9 +39,20 @@
 #include <dev/pci/pcireg.h>
 #endif
 
-int
-drm_device_is_agp(drm_device_t *dev)
+/* Returns 1 if AGP or 0 if not. */
+static int
+drm_device_find_capability(drm_device_t *dev, int cap)
 {
+	int ret;
+
+	if (dev->driver.device_is_agp != NULL) {
+		ret = (*dev->driver.device_is_agp)(dev);
+		
+		if (ret != DRM_MIGHT_BE_AGP) {
+			return ret == 2;
+		}
+	}
+
 #ifdef __FreeBSD__
 	/* Code taken from agp.c.  IWBNI that was a public interface. */
 	u_int32_t status;
@@ -64,9 +75,9 @@
 		next = AGP_CAPID_GET_NEXT_PTR(capid);
 
 		/*
-		 * If this capability entry ID is 2, then we are done.
+		 * If this capability entry ID is cap, then we are done.
 		 */
-		if (AGP_CAPID_GET_CAP_ID(capid) == 2)
+		if (AGP_CAPID_GET_CAP_ID(capid) == cap)
 			return 1;
 	}
 
@@ -77,75 +88,95 @@
 #endif
 }
 
-int drm_agp_info(DRM_IOCTL_ARGS)
+int drm_device_is_agp(drm_device_t *dev)
+{
+	return (drm_device_find_capability(dev, PCIY_AGP));
+}
+
+int drm_device_is_pcie(drm_device_t *dev)
+{
+	return (drm_device_find_capability(dev, PCIY_EXPRESS));
+}
+
+int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info)
 {
-	DRM_DEVICE;
 	struct agp_info *kern;
-	drm_agp_info_t   info;
 
 	if (!dev->agp || !dev->agp->acquired)
 		return EINVAL;
 
 	kern                   = &dev->agp->info;
 	agp_get_info(dev->agp->agpdev, kern);
-	info.agp_version_major = 1;
-	info.agp_version_minor = 0;
-	info.mode              = kern->ai_mode;
-	info.aperture_base     = kern->ai_aperture_base;
-	info.aperture_size     = kern->ai_aperture_size;
-	info.memory_allowed    = kern->ai_memory_allowed;
-	info.memory_used       = kern->ai_memory_used;
-	info.id_vendor         = kern->ai_devid & 0xffff;
-	info.id_device         = kern->ai_devid >> 16;
+	info->agp_version_major = 1;
+	info->agp_version_minor = 0;
+	info->mode              = kern->ai_mode;
+	info->aperture_base     = kern->ai_aperture_base;
+	info->aperture_size     = kern->ai_aperture_size;
+	info->memory_allowed    = kern->ai_memory_allowed;
+	info->memory_used       = kern->ai_memory_used;
+	info->id_vendor         = kern->ai_devid & 0xffff;
+	info->id_device         = kern->ai_devid >> 16;
+
+	return 0;
+}
+
+int drm_agp_info_ioctl(DRM_IOCTL_ARGS)
+{
+	int err;
+	drm_agp_info_t info;
+	DRM_DEVICE;
+
+	err = drm_agp_info(dev, &info);
+	if (err != 0)
+		return err;
 
 	*(drm_agp_info_t *) data = info;
 	return 0;
 }
 
-int drm_agp_acquire(DRM_IOCTL_ARGS)
+int drm_agp_acquire_ioctl(DRM_IOCTL_ARGS)
 {
 	DRM_DEVICE;
-	int          retcode;
+
+	return drm_agp_acquire(dev);
+}
+
+int drm_agp_acquire(drm_device_t *dev)
+{
+	int retcode;
 
 	if (!dev->agp || dev->agp->acquired)
 		return EINVAL;
+
 	retcode = agp_acquire(dev->agp->agpdev);
 	if (retcode)
 		return retcode;
+
 	dev->agp->acquired = 1;
 	return 0;
 }
 
-int drm_agp_release(DRM_IOCTL_ARGS)
+int drm_agp_release_ioctl(DRM_IOCTL_ARGS)
 {
 	DRM_DEVICE;
 
+	return drm_agp_release(dev);
+}
+
+int drm_agp_release(drm_device_t * dev)
+{
 	if (!dev->agp || !dev->agp->acquired)
 		return EINVAL;
 	agp_release(dev->agp->agpdev);
 	dev->agp->acquired = 0;
 	return 0;
-	
 }
 
-void drm_agp_do_release(void)
+int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode)
 {
-	device_t agpdev;
-
-	agpdev = DRM_AGP_FIND_DEVICE();
-	if (agpdev)
-		agp_release(agpdev);
-}
 
-int drm_agp_enable(DRM_IOCTL_ARGS)
-{
-	DRM_DEVICE;
-	drm_agp_mode_t mode;
-
 	if (!dev->agp || !dev->agp->acquired)
 		return EINVAL;
-
-	mode = *(drm_agp_mode_t *) data;
 	
 	dev->agp->mode    = mode.mode;
 	agp_enable(dev->agp->agpdev, mode.mode);
@@ -154,6 +185,16 @@
 	return 0;
 }
 
+int drm_agp_enable_ioctl(DRM_IOCTL_ARGS)
+{
+	drm_agp_mode_t mode;
+	DRM_DEVICE;
+
+	mode = *(drm_agp_mode_t *) data;
+
+	return drm_agp_enable(dev, mode);
+}
+
 int drm_agp_alloc(DRM_IOCTL_ARGS)
 {
 	DRM_DEVICE;

==== //depot/projects/drm-merge/sys/dev/drm/drm_bufs.c#6 (text+ko) ====

@@ -92,99 +92,36 @@
 	return len;
 }
 
-int drm_initmap(drm_device_t *dev, unsigned long start, unsigned long len,
-		unsigned int resource, int type, int flags)
+int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
+    drm_map_type_t type, drm_map_flags_t flags, drm_local_map_t **map_ptr)
 {
 	drm_local_map_t *map;
-	struct resource *bsr;
-
-	if (type != _DRM_REGISTERS && type != _DRM_FRAME_BUFFER)
-		return EINVAL;
-	if (len == 0)
-		return EINVAL;
 
-	map = malloc(sizeof(*map), M_DRM, M_ZERO | M_NOWAIT);
-	if (map == NULL)
-		return ENOMEM;
-
-	map->rid = resource * 4 + 0x10;
-	bsr = bus_alloc_resource_any(dev->device, SYS_RES_MEMORY, &map->rid,
-	    RF_ACTIVE | RF_SHAREABLE);
-	if (bsr == NULL) {
-		DRM_ERROR("Couldn't allocate %s resource\n",
-		    ((type == _DRM_REGISTERS) ? "mmio" : "framebuffer"));
-		free(map, M_DRM);
-		return ENOMEM;
-	}
-
-	map->kernel_owned = 1;
-	map->type = type;
-	map->flags = flags;
-	map->bsr = bsr;
-	map->bst = rman_get_bustag(bsr);
-	map->bsh = rman_get_bushandle(bsr);
-	map->offset = start;
-	map->size = len;
-
-	if (type == _DRM_REGISTERS)
-		map->handle = rman_get_virtual(bsr);
-
-	DRM_DEBUG("initmap %d,0x%x@0x%lx/0x%lx\n", map->type, map->flags,
-	    map->offset, map->size);
-
-	if (map->flags & _DRM_WRITE_COMBINING) {
-		int err;
-
-		err = drm_mtrr_add(map->offset, map->size, DRM_MTRR_WC);
-		if (err == 0)
-			map->mtrr = 1;
-	}
-
-	DRM_LOCK();
-	TAILQ_INSERT_TAIL(&dev->maplist, map, link);
-	DRM_UNLOCK();
-
-	return 0;
-}
-
-int drm_addmap(DRM_IOCTL_ARGS)
-{
-	DRM_DEVICE;
-	drm_map_t request;
-	drm_local_map_t *map;
-	dma_addr_t bus_addr;
-	
-	if (!(dev->flags & (FREAD|FWRITE)))
-		return DRM_ERR(EACCES); /* Require read/write */
-
-	DRM_COPY_FROM_USER_IOCTL( request, (drm_map_t *)data, sizeof(drm_map_t) );
-
 	/* Only allow shared memory to be removable since we only keep enough
 	 * book keeping information about shared memory to allow for removal
 	 * when processes fork.
 	 */
-	if ((request.flags & _DRM_REMOVABLE) && request.type != _DRM_SHM)
+	if ((flags & _DRM_REMOVABLE) && type != _DRM_SHM)
 		return EINVAL;
-	if ((request.offset & PAGE_MASK) || (request.size & PAGE_MASK))
+	if ((offset & PAGE_MASK) || (size & PAGE_MASK))
 		return EINVAL;
-	if (request.offset + request.size < request.offset)
+	if (offset + size < offset)
 		return EINVAL;
 
-	DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n",
-	    request.offset, request.size, request.type);
+	DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n", offset,
+	    size, type);
 
 	/* Check if this is just another version of a kernel-allocated map, and
 	 * just hand that back if so.
 	 */
-	if (request.type == _DRM_REGISTERS || request.type == _DRM_FRAME_BUFFER)
-	{
+	if (type == _DRM_REGISTERS || type == _DRM_FRAME_BUFFER ||
+	    type == _DRM_SHM) {
 		DRM_LOCK();
 		TAILQ_FOREACH(map, &dev->maplist, link) {
-			if (map->kernel_owned && map->type == request.type &&
-			    map->offset == request.offset) {
-				/* XXX: this size setting is questionable. */
-				map->size = request.size;
-				DRM_DEBUG("Found kernel map %d\n", request.type);
+			if (map->type == type &&
+			    (map->offset == offset || map->type == _DRM_SHM)) {
+				map->size = size;
+				DRM_DEBUG("Found kernel map %d\n", type);
 				goto done;
 			}
 		}
@@ -198,14 +135,14 @@
 	if ( !map )
 		return DRM_ERR(ENOMEM);
 
-	map->offset = request.offset;
-	map->size = request.size;
-	map->type = request.type;
-	map->flags = request.flags;
+	map->offset = offset;
+	map->size = size;
+	map->type = type;
+	map->flags = flags;
 
 	switch ( map->type ) {
 	case _DRM_REGISTERS:
-		drm_ioremap(dev, map);
+		map->handle = drm_ioremap(dev, map);
 		if (!(map->flags & _DRM_WRITE_COMBINING))
 			break;
 		/* FALLTHROUGH */
@@ -236,8 +173,25 @@
 		}
 		break;
 	case _DRM_AGP:
-		map->offset += dev->agp->base;
-		map->mtrr   = dev->agp->mtrr; /* for getmap */
+		{
+			drm_agp_mem_t *entry;
+			int valid = 0;
+
+			map->offset += dev->agp->base;
+			map->mtrr   = dev->agp->mtrr; /* for getmap */
+			for (entry = dev->agp->memory; entry;
+			    entry = entry->next)
+				if ((map->offset >= entry->bound) &&
+				    (map->offset + map->size <=
+				    entry->bound + entry->pages * PAGE_SIZE)) {
+					valid = 1;
+					break;
+				}
+			if (!valid) {
+				free(map, M_DRM);
+				return DRM_ERR(EACCES);
+			}
+		}
 		break;
 	case _DRM_SCATTER_GATHER:
 		if (!dev->sg) {
@@ -247,13 +201,14 @@
 		map->offset = map->offset + dev->sg->handle;
 		break;
 	case _DRM_CONSISTENT:
-		map->handle = drm_pci_alloc(dev, map->size, map->size,
-		    0xfffffffful, &bus_addr);
-		if (map->handle == NULL) {
+		map->dmah = drm_pci_alloc(dev, map->size, map->size,
+		    0xfffffffful);
+		if (map->dmah == NULL) {
 			free(map, M_DRM);
-			return ENOMEM;
+			return DRM_ERR(ENOMEM);
 		}
-		map->offset = (unsigned long)bus_addr;
+		map->handle = map->dmah->vaddr;
+		map->offset = map->dmah->busaddr;
 		break;
 	default:
 		free(map, M_DRM);
@@ -265,26 +220,52 @@
 
 done:
 	/* Jumped to, with lock held, when a kernel map is found. */
+	DRM_UNLOCK();
+
+	DRM_DEBUG("Added map %d 0x%lx/0x%lx\n", map->type, map->offset,
+	    map->size);
+
+	*map_ptr = map;
+
+	return 0;
+}
+
+int drm_addmap_ioctl(DRM_IOCTL_ARGS)
+{
+	drm_map_t request;
+	drm_local_map_t *map;
+	int err;
+	DRM_DEVICE;
+
+	if (!(dev->flags & (FREAD|FWRITE)))
+		return DRM_ERR(EACCES); /* Require read/write */
+
+	DRM_COPY_FROM_USER_IOCTL(request, (drm_map_t *)data, sizeof(drm_map_t));
+
+	if (!DRM_SUSER(p) && request.type != _DRM_AGP)
+		return DRM_ERR(EACCES);
+
+	err = drm_addmap(dev, request.offset, request.size, request.type,
+	    request.flags, &map);
+	if (err != 0)
+		return err;
+
 	request.offset = map->offset;
 	request.size = map->size;
 	request.type = map->type;
 	request.flags = map->flags;
 	request.mtrr   = map->mtrr;
 	request.handle = map->handle;
-	DRM_UNLOCK();
 
-	DRM_DEBUG("Added map %d 0x%lx/0x%lx\n", request.type, request.offset, request.size);
-
-	if ( request.type != _DRM_SHM ) {
+	if (request.type != _DRM_SHM) {
 		request.handle = (void *)request.offset;
 	}
-
-	DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, request, sizeof(drm_map_t) );
+	DRM_COPY_TO_USER_IOCTL((drm_map_t *)data, request, sizeof(drm_map_t));
 
 	return 0;
 }
 
-void drm_remove_map(drm_device_t *dev, drm_local_map_t *map)
+void drm_rmmap(drm_device_t *dev, drm_local_map_t *map)
 {
 	DRM_SPINLOCK_ASSERT(&dev->dev_lock);
 
@@ -311,7 +292,7 @@
 	case _DRM_SCATTER_GATHER:
 		break;
 	case _DRM_CONSISTENT:
-		drm_pci_free(dev, map->size, map->handle, map->offset);
+		drm_pci_free(dev, map->dmah);
 		break;
 	}
 
@@ -327,7 +308,7 @@
  * isn't in use.
  */
 
-int drm_rmmap(DRM_IOCTL_ARGS)
+int drm_rmmap_ioctl(DRM_IOCTL_ARGS)
 {
 	DRM_DEVICE;
 	drm_local_map_t *map;
@@ -348,7 +329,7 @@
 		return DRM_ERR(EINVAL);
 	}
 

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508260122.j7Q1MR6s003408>