summaryrefslogtreecommitdiff
path: root/sys/dev/pci/drm
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2008-05-06 19:19:03 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2008-05-06 19:19:03 +0000
commit0d12c3f56a9965c9c1fbab7d8a961c9e121bc885 (patch)
tree1b8da77e839c5cdd95bbfe014dc6f76d6d8f5d4c /sys/dev/pci/drm
parent6326e66a01c7b4d7ac0ec2d749c33423122e90bd (diff)
currently agp_i810 needs to map the same BAR as inteldrm, this obviously
fails. In order to allow this, implement an API so that drm and agp can share mappings for the BARs. Now it works as it should. tested by many. ok kettenis, miod said he'd look at it when it's in tree.
Diffstat (limited to 'sys/dev/pci/drm')
-rw-r--r--sys/dev/pci/drm/drmP.h23
-rw-r--r--sys/dev/pci/drm/drm_bufs.c29
-rw-r--r--sys/dev/pci/drm/drm_drv.c6
-rw-r--r--sys/dev/pci/drm/drm_memory.c52
-rw-r--r--sys/dev/pci/drm/i915_drv.c3
-rw-r--r--sys/dev/pci/drm/mach64_drv.c2
-rw-r--r--sys/dev/pci/drm/mga_drv.c2
-rw-r--r--sys/dev/pci/drm/r128_drv.c2
-rw-r--r--sys/dev/pci/drm/radeon_drv.c2
-rw-r--r--sys/dev/pci/drm/savage_drv.c2
-rw-r--r--sys/dev/pci/drm/sis_drv.c2
-rw-r--r--sys/dev/pci/drm/tdfx_drv.c2
-rw-r--r--sys/dev/pci/drm/via_drv.c2
13 files changed, 69 insertions, 60 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h
index 07fd6976d4a..f93246c0e93 100644
--- a/sys/dev/pci/drm/drmP.h
+++ b/sys/dev/pci/drm/drmP.h
@@ -676,18 +676,6 @@ typedef struct drm_sg_mem {
drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */
} drm_sg_mem_t;
-#if defined(__NetBSD__) || defined(__OpenBSD__)
-typedef struct {
- int mapped;
- int maptype;
- bus_addr_t base;
- bus_size_t size;
- bus_space_handle_t bsh;
- int flags;
- void * vaddr;
-} pci_map_data_t;
-#endif
-
typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
typedef struct drm_local_map {
@@ -703,7 +691,7 @@ typedef struct drm_local_map {
#ifdef __FreeBSD__
struct resource *bsr;
#else
- pci_map_data_t *bsr;
+ struct vga_pci_bar *bsr;
#endif
bus_space_tag_t bst;
bus_space_handle_t bsh;
@@ -832,6 +820,7 @@ struct drm_device {
#endif
#ifdef __OpenBSD__
dev_t kdev; /* used by uvm_mmap, this is just a placeholder */
+ struct vga_pci_softc *vga_softc;
#endif
int if_version; /* Highest interface version set */
@@ -885,10 +874,10 @@ struct drm_device {
/* Storage of resource pointers for drm_get_resource_* */
#ifdef __FreeBSD__
struct resource *pcir[DRM_MAX_PCI_RESOURCE];
+ int pcirid[DRM_MAX_PCI_RESOURCE];
#else
- pci_map_data_t *pcir[DRM_MAX_PCI_RESOURCE];
+ struct vga_pci_bar *pcir[DRM_MAX_PCI_RESOURCE];
#endif
- int pcirid[DRM_MAX_PCI_RESOURCE];
int pci_domain;
int pci_bus;
@@ -950,8 +939,8 @@ d_poll_t drm_poll;
d_mmap_t drm_mmap;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
int drm_probe(struct pci_attach_args *, drm_pci_id_list_t * );
-void drm_attach(struct device *kdev, struct pci_attach_args *pa,
- drm_pci_id_list_t *idlist);
+void drm_attach(struct device *kdev, struct device *parent,
+ struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
int drm_detach(struct device *self, int flags);
int drm_activate(struct device *self, enum devact act);
dev_type_ioctl(drm_ioctl);
diff --git a/sys/dev/pci/drm/drm_bufs.c b/sys/dev/pci/drm/drm_bufs.c
index 64e32082e22..3451b7c63f1 100644
--- a/sys/dev/pci/drm/drm_bufs.c
+++ b/sys/dev/pci/drm/drm_bufs.c
@@ -67,9 +67,6 @@ drm_order(unsigned long size)
int
drm_alloc_resource(drm_device_t *dev, int resource)
{
-#ifdef __OpenBSD__
-#define PCIR_BAR(x) (PCI_MAPS + (x) * 4)
-#endif
if (resource >= DRM_MAX_PCI_RESOURCE) {
DRM_ERROR("Resource %d too large\n", resource);
return 1;
@@ -81,8 +78,8 @@ drm_alloc_resource(drm_device_t *dev, int resource)
return 0;
}
- dev->pcirid[resource] = PCIR_BAR(resource);
#if defined (__FreeBSD__)
+ dev->pcirid[resource] = PCIR_BAR(resource);
dev->pcir[resource] = bus_alloc_resource_any(dev->device,
SYS_RES_MEMORY, &dev->pcirid[resource], RF_SHAREABLE);
@@ -92,27 +89,12 @@ drm_alloc_resource(drm_device_t *dev, int resource)
return 1;
}
#elif defined (__OpenBSD__)
- dev->pcir[resource] = malloc(sizeof(*(dev->pcir)), M_DRM, M_NOWAIT | M_ZERO);
+ dev->pcir[resource] = vga_pci_bar_info(dev->vga_softc, resource);
+ DRM_LOCK();
if (dev->pcir[resource] == NULL) {
- DRM_ERROR("Couldn't allocate memory for resource 0x%x\n", resource);
- DRM_LOCK();
+ DRM_ERROR("Can't get bar info for resource 0x%x\n", resource);
return 1;
}
- dev->pcir[resource]->maptype =
- pci_mapreg_type(dev->pa.pa_pc, dev->pa.pa_tag,
- dev->pcirid[resource]);
- if(pci_mapreg_info(dev->pa.pa_pc, dev->pa.pa_tag,
- dev->pcirid[resource],
- dev->pcir[resource]->maptype,
- &(dev->pcir[resource]->base),
- &(dev->pcir[resource]->size),
- &(dev->pcir[resource]->flags))) {
- dev->pcir[resource]->base = 0;
- dev->pcir[resource]->size = 0;
- }
- if(dev->pcir[resource]->maptype == PCI_MAPREG_TYPE_MEM)
- dev->pcir[resource]->flags |= BUS_SPACE_MAP_LINEAR;
- DRM_LOCK();
#endif
return 0;
@@ -141,7 +123,7 @@ drm_get_resource_len(drm_device_t *dev, unsigned int resource)
#ifdef __FreeBSD__
return rman_get_size(dev->pcir[resource]);
#elif defined(__NetBSD__) || defined(__OpenBSD__)
- return dev->pcir[resource]->size;
+ return dev->pcir[resource]->maxsize;
#endif
}
@@ -211,7 +193,6 @@ drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
switch ( map->type ) {
case _DRM_REGISTERS:
- map->bst = dev->pa.pa_iot;
map->handle = drm_ioremap(dev, map);
if (!map->handle) {
DRM_LOCK();
diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c
index 7eaf8358810..bb0dcc82b7c 100644
--- a/sys/dev/pci/drm/drm_drv.c
+++ b/sys/dev/pci/drm/drm_drv.c
@@ -267,8 +267,8 @@ drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist)
}
void
-drm_attach(struct device *kdev, struct pci_attach_args *pa,
- drm_pci_id_list_t *idlist)
+drm_attach(struct device *parent, struct device *kdev,
+ struct pci_attach_args *pa, drm_pci_id_list_t *idlist)
{
int unit;
drm_device_t *dev;
@@ -288,7 +288,9 @@ drm_attach(struct device *kdev, struct pci_attach_args *pa,
dev = drm_units[unit] = (drm_device_t*)kdev;
dev->unit = unit;
+ /* needed for pci_mapreg_* */
memcpy(&dev->pa, pa, sizeof(dev->pa));
+ dev->vga_softc = (struct vga_pci_softc *)parent;
dev->irq = pa->pa_intrline;
dev->pci_bus = pa->pa_bus;
diff --git a/sys/dev/pci/drm/drm_memory.c b/sys/dev/pci/drm/drm_memory.c
index 8d3ae1d4a5f..5900b431d17 100644
--- a/sys/dev/pci/drm/drm_memory.c
+++ b/sys/dev/pci/drm/drm_memory.c
@@ -97,13 +97,48 @@ drm_ioremap(drm_device_t *dev, drm_local_map_t *map)
#ifdef __FreeBSD__
return pmap_mapdev(map->offset, map->size);
#elif defined(__NetBSD__) || defined(__OpenBSD__)
- int ret;
- if (!map->bst)
- map->bst = dev->pa.pa_memt;
- if ((ret = bus_space_map(map->bst, map->offset, map->size,
- BUS_SPACE_MAP_LINEAR, &map->bsh))) {
- return NULL;
+ struct vga_pci_bar *bar = NULL;
+ int i;
+
+ DRM_DEBUG("offset: 0x%x size: 0x%x type: %d\n", map->offset, map->size,
+ map->type);
+
+ if (map->type == _DRM_AGP || map->type == _DRM_FRAME_BUFFER) {
+ /*
+ * there can be multiple agp maps in the same BAR, agp also
+ * quite possibly isn't the same as the vga device, just try
+ * to map it.
+ */
+ DRM_DEBUG("AGP map\n");
+ map->bst = dev->pa.pa_memt;
+ if (bus_space_map(map->bst, map->offset,
+ map->size, BUS_SPACE_MAP_LINEAR, &map->bsh)) {
+ DRM_ERROR("ioremap fail\n");
+ return (NULL);
+ }
+ goto done;
+ } else {
+ for (i = 0 ; i < DRM_MAX_PCI_RESOURCE; ++i) {
+ bar = vga_pci_bar_info(dev->vga_softc, i);
+ if (bar == NULL)
+ continue;
+
+ if (bar->base == map->offset) {
+ DRM_DEBUG("REGISTERS map\n");
+ map->bsr = vga_pci_bar_map(dev->vga_softc,
+ bar->addr, map->size, BUS_SPACE_MAP_LINEAR);
+ if (map->bsr == NULL) {
+ DRM_ERROR("ioremap fail\n");
+ return (NULL);
+ }
+ map->bst = map->bsr->bst;
+ map->bsh = map->bsr->bsh;
+ goto done;
+ }
+ }
}
+done:
+ /* handles are still supposed to be kernel virtual addresses */
return bus_space_vaddr(map->bst, map->bsh);
#endif
}
@@ -114,7 +149,10 @@ drm_ioremapfree(drm_local_map_t *map)
#ifdef __FreeBSD__
pmap_unmapdev((vm_offset_t) map->handle, map->size);
#elif defined(__NetBSD__) || defined(__OpenBSD__)
- bus_space_unmap(map->bst, map->bsh, map->size);
+ if (map != NULL && map->bsr != NULL)
+ vga_pci_bar_unmap(map->bsr);
+ else
+ bus_space_unmap(map->bst, map->bsh, map->size);
#endif
}
diff --git a/sys/dev/pci/drm/i915_drv.c b/sys/dev/pci/drm/i915_drv.c
index 61a3ba4218b..6b9be6b8200 100644
--- a/sys/dev/pci/drm/i915_drv.c
+++ b/sys/dev/pci/drm/i915_drv.c
@@ -129,7 +129,6 @@ i915drm_probe(struct device *parent, void *match, void *aux)
i915drm_probe(struct device *parent, struct cfdata *match, void *aux)
#endif
{
- DRM_DEBUG("\n");
return drm_probe((struct pci_attach_args *)aux, i915_pciidlist);
}
@@ -141,7 +140,7 @@ i915drm_attach(struct device *parent, struct device *self, void *aux)
i915_configure(dev);
- drm_attach(self, pa, i915_pciidlist);
+ drm_attach(parent, self, pa, i915_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/mach64_drv.c b/sys/dev/pci/drm/mach64_drv.c
index 78ef1bded92..9065840850f 100644
--- a/sys/dev/pci/drm/mach64_drv.c
+++ b/sys/dev/pci/drm/mach64_drv.c
@@ -138,7 +138,7 @@ mach64drm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
mach64_configure(dev);
- return drm_attach(self, pa, mach64_pciidlist);
+ return drm_attach(parent, self, pa, mach64_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/mga_drv.c b/sys/dev/pci/drm/mga_drv.c
index 8732c31aaf5..d18a7845063 100644
--- a/sys/dev/pci/drm/mga_drv.c
+++ b/sys/dev/pci/drm/mga_drv.c
@@ -188,7 +188,7 @@ mgadrm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
mga_configure(dev);
- return drm_attach(self, pa, mga_pciidlist);
+ return drm_attach(parent, self, pa, mga_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/r128_drv.c b/sys/dev/pci/drm/r128_drv.c
index c6b32790ade..9c16396f383 100644
--- a/sys/dev/pci/drm/r128_drv.c
+++ b/sys/dev/pci/drm/r128_drv.c
@@ -138,7 +138,7 @@ r128drm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
r128_configure(dev);
- return drm_attach(self, pa, r128_pciidlist);
+ return drm_attach(parent, self, pa, r128_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/radeon_drv.c b/sys/dev/pci/drm/radeon_drv.c
index 2ccd48818bc..082a4844db5 100644
--- a/sys/dev/pci/drm/radeon_drv.c
+++ b/sys/dev/pci/drm/radeon_drv.c
@@ -143,7 +143,7 @@ radeondrm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
radeon_configure(dev);
- return drm_attach(self, pa, radeon_pciidlist);
+ return drm_attach(parent, self, pa, radeon_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/savage_drv.c b/sys/dev/pci/drm/savage_drv.c
index 557bdbb1775..585fe9a9538 100644
--- a/sys/dev/pci/drm/savage_drv.c
+++ b/sys/dev/pci/drm/savage_drv.c
@@ -128,7 +128,7 @@ savagedrm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
savage_configure(dev);
- return drm_attach(self, pa, savage_pciidlist);
+ return drm_attach(parent, self, pa, savage_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/sis_drv.c b/sys/dev/pci/drm/sis_drv.c
index a986437aac8..072e1afdd0d 100644
--- a/sys/dev/pci/drm/sis_drv.c
+++ b/sys/dev/pci/drm/sis_drv.c
@@ -121,7 +121,7 @@ sisdrm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
sis_configure(dev);
- return drm_attach(self, pa, sis_pciidlist);
+ return drm_attach(parent, self, pa, sis_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/tdfx_drv.c b/sys/dev/pci/drm/tdfx_drv.c
index 954446c475d..37bf6075c16 100644
--- a/sys/dev/pci/drm/tdfx_drv.c
+++ b/sys/dev/pci/drm/tdfx_drv.c
@@ -122,7 +122,7 @@ tdfxdrm_attach(struct device *parent, struct device *self, void *aux)
drm_device_t *dev = (drm_device_t *)self;
tdfx_configure(dev);
- return drm_attach(self, pa, tdfx_pciidlist);
+ return drm_attach(parent, self, pa, tdfx_pciidlist);
}
#if defined(__OpenBSD__)
diff --git a/sys/dev/pci/drm/via_drv.c b/sys/dev/pci/drm/via_drv.c
index 82a2374b296..86aa2b550ec 100644
--- a/sys/dev/pci/drm/via_drv.c
+++ b/sys/dev/pci/drm/via_drv.c
@@ -130,7 +130,7 @@ viadrm_attach(struct device *parent, struct device *self, void *opaque)
drm_device_t *dev = (drm_device_t *)self;
viadrm_configure(dev);
- drm_attach(self, pa, via_pciidlist);
+ drm_attach(parent, self, pa, via_pciidlist);
}
#if defined(__OpenBSD__)