[PATCH 4/4] drm: Make sure the DRM offset matches the CPU

2010-05-27 Thread jcro...@codeaurora.org
From: Jordan Crouse 

The pgoff option in mmap() is defined as an unsigned long
so the offset generated by DRM needs to fit into
BITS_PER_LONG for the CPU in question.

Signed-off-by: Jordan Crouse 
---
 drivers/gpu/drm/drm_gem.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 33dad3f..8601b72 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -68,8 +68,18 @@
  * We make up offsets for buffer objects so we can recognize them at
  * mmap time.
  */
+
+/* pgoff in mmap is an unsigned long, so we need to make sure that
+ * the faked up offset will fit
+ */
+
+#if BITS_PER_LONG == 64
 #define DRM_FILE_PAGE_OFFSET_START ((0xUL >> PAGE_SHIFT) + 1)
 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xUL >> PAGE_SHIFT) * 16)
+#else
+#define DRM_FILE_PAGE_OFFSET_START ((0xFFFUL >> PAGE_SHIFT) + 1)
+#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFUL >> PAGE_SHIFT) * 16)
+#endif

 /**
  * Initialize the GEM device fields
-- 
1.7.0.1



[PATCH 1/4] drm: Remove drm_resource wrappers

2010-05-27 Thread jcro...@codeaurora.org
From: Jordan Crouse 

Remove the drm_resource wrappers and directly use the
actual PCI and/or platform functions in their place.

Signed-off-by: Jordan Crouse 
---
 drivers/gpu/drm/drm_bufs.c|   13 -
 drivers/gpu/drm/i915/i915_dma.c   |6 +++---
 drivers/gpu/drm/mga/mga_dma.c |4 ++--
 drivers/gpu/drm/nouveau/nouveau_bo.c  |2 +-
 drivers/gpu/drm/nouveau/nouveau_channel.c |3 ++-
 drivers/gpu/drm/nouveau/nouveau_mem.c |   16 +---
 drivers/gpu/drm/nouveau/nv20_graph.c  |4 ++--
 drivers/gpu/drm/nouveau/nv40_graph.c  |2 +-
 drivers/gpu/drm/nouveau/nv50_instmem.c|3 ++-
 drivers/gpu/drm/radeon/evergreen.c|4 ++--
 drivers/gpu/drm/radeon/r100.c |4 ++--
 drivers/gpu/drm/radeon/r600.c |4 ++--
 drivers/gpu/drm/radeon/radeon_bios.c  |2 +-
 drivers/gpu/drm/radeon/radeon_cp.c|8 
 drivers/gpu/drm/radeon/radeon_device.c|4 ++--
 drivers/gpu/drm/radeon/rs600.c|4 ++--
 drivers/gpu/drm/radeon/rs690.c|4 ++--
 drivers/gpu/drm/radeon/rv770.c|4 ++--
 drivers/gpu/drm/savage/savage_bci.c   |   24 +---
 include/drm/drmP.h|4 
 20 files changed, 54 insertions(+), 65 deletions(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 2092e7b..3c2c663 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -39,19 +39,6 @@
 #include 
 #include "drmP.h"

-resource_size_t drm_get_resource_start(struct drm_device *dev, unsigned int 
resource)
-{
-   return pci_resource_start(dev->pdev, resource);
-}
-EXPORT_SYMBOL(drm_get_resource_start);
-
-resource_size_t drm_get_resource_len(struct drm_device *dev, unsigned int 
resource)
-{
-   return pci_resource_len(dev->pdev, resource);
-}
-
-EXPORT_SYMBOL(drm_get_resource_len);
-
 static struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
  struct drm_local_map *map)
 {
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 2a6b5de..9fe2d08 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1429,7 +1429,7 @@ static int i915_load_modeset_init(struct drm_device *dev,
int fb_bar = IS_I9XX(dev) ? 2 : 0;
int ret = 0;

-   dev->mode_config.fb_base = drm_get_resource_start(dev, fb_bar) &
+   dev->mode_config.fb_base = pci_resource_start(dev->pdev, fb_bar) &
0xff00;

/* Basic memrange allocator for stolen space (aka vram) */
@@ -1612,8 +1612,8 @@ int i915_driver_load(struct drm_device *dev, unsigned 
long flags)

/* Add register map (needed for suspend/resume) */
mmio_bar = IS_I9XX(dev) ? 0 : 1;
-   base = drm_get_resource_start(dev, mmio_bar);
-   size = drm_get_resource_len(dev, mmio_bar);
+   base = pci_resource_start(dev->pdev, mmio_bar);
+   size = pci_resource_len(dev->pdev, mmio_bar);

if (i915_get_bridge_dev(dev)) {
ret = -EIO;
diff --git a/drivers/gpu/drm/mga/mga_dma.c b/drivers/gpu/drm/mga/mga_dma.c
index 3c917fb..ccc129c 100644
--- a/drivers/gpu/drm/mga/mga_dma.c
+++ b/drivers/gpu/drm/mga/mga_dma.c
@@ -405,8 +405,8 @@ int mga_driver_load(struct drm_device * dev, unsigned long 
flags)
dev_priv->usec_timeout = MGA_DEFAULT_USEC_TIMEOUT;
dev_priv->chipset = flags;

-   dev_priv->mmio_base = drm_get_resource_start(dev, 1);
-   dev_priv->mmio_size = drm_get_resource_len(dev, 1);
+   dev_priv->mmio_base = pci_resource_start(dev->pdev, 1);
+   dev_priv->mmio_size = pci_resource_len(dev->pdev, 1);

dev->counters += 3;
dev->types[6] = _DRM_STAT_IRQ;
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c 
b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 6f3c195..1dad392 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -783,7 +783,7 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, 
struct ttm_mem_reg *mem)
break;
case TTM_PL_VRAM:
mem->bus.offset = mem->mm_node->start << PAGE_SHIFT;
-   mem->bus.base = drm_get_resource_start(dev, 1);
+   man->bus.base = pci_resource_start(dev->pdev, 1);
mem->bus.is_iomem = true;
break;
default:
diff --git a/drivers/gpu/drm/nouveau/nouveau_channel.c 
b/drivers/gpu/drm/nouveau/nouveau_channel.c
index 1fc57ef..06555c7 100644
--- a/drivers/gpu/drm/nouveau/nouveau_channel.c
+++ b/drivers/gpu/drm/nouveau/nouveau_channel.c
@@ -62,7 +62,8 @@ nouveau_channel_pushbuf_ctxdma_init(struct nouveau_channel 
*chan)
 * VRAM.
 */
ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
-drm_get_resource_start(dev, 1),
+  

[PATCH v2] DRM platform device support

2010-05-27 Thread jcro...@codeaurora.org
Here is the second revision implementing platform device
support for DRM.  I've split the original patch into three
and applied most of the comments I got from the previous
go-around.  The first patch removes the resource wrappers from
DRM and switches the drivers to use the bus level functions.
The second patch adds the platform support, and the third patch
adds the ARM specific #ifdefs.

Plus, a bonus patch that ensures that the DRM offset fits into
the pgoff (unsigned long) offset for mmap.  The original code made
a 64 bit value that didn't fly with a 32 bit processor.

Thanks for the comments and keep em coming.

Jordan


[PATCH 3/4] drm: Add __arm defines to DRM

2010-05-27 Thread jcro...@codeaurora.org
From: Jordan Crouse 

Add __arm defines to specify behavior specific for
an ARM processor.

Signed-off-by: Jordan Crouse 
---
 drivers/gpu/drm/drm_bufs.c |2 +-
 drivers/gpu/drm/drm_vm.c   |   14 +-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 3c2c663..a5c9ce9 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -176,7 +176,7 @@ static int drm_addmap_core(struct drm_device * dev, 
resource_size_t offset,
switch (map->type) {
case _DRM_REGISTERS:
case _DRM_FRAME_BUFFER:
-#if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && 
!defined(__powerpc64__) && !defined(__x86_64__)
+#if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && 
!defined(__powerpc64__) && !defined(__x86_64__) && !defined(__arm__)
if (map->offset + (map->size-1) < map->offset ||
map->offset < virt_to_phys(high_memory)) {
kfree(map);
diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
index c3b13fb..3778360 100644
--- a/drivers/gpu/drm/drm_vm.c
+++ b/drivers/gpu/drm/drm_vm.c
@@ -61,7 +61,7 @@ static pgprot_t drm_io_prot(uint32_t map_type, struct 
vm_area_struct *vma)
tmp = pgprot_writecombine(tmp);
else
tmp = pgprot_noncached(tmp);
-#elif defined(__sparc__)
+#elif defined(__sparc__) || defined(__arm__)
tmp = pgprot_noncached(tmp);
 #endif
return tmp;
@@ -601,6 +601,7 @@ int drm_mmap_locked(struct file *filp, struct 
vm_area_struct *vma)
}

switch (map->type) {
+#if !defined(__arm__)
case _DRM_AGP:
if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
/*
@@ -615,20 +616,31 @@ int drm_mmap_locked(struct file *filp, struct 
vm_area_struct *vma)
break;
}
/* fall through to _DRM_FRAME_BUFFER... */
+#endif
case _DRM_FRAME_BUFFER:
case _DRM_REGISTERS:
offset = dev->driver->get_reg_ofs(dev);
vma->vm_flags |= VM_IO; /* not in core dump */
vma->vm_page_prot = drm_io_prot(map->type, vma);
+#if !defined(__arm__)
if (io_remap_pfn_range(vma, vma->vm_start,
   (map->offset + offset) >> PAGE_SHIFT,
   vma->vm_end - vma->vm_start,
   vma->vm_page_prot))
return -EAGAIN;
+#else
+   if (remap_pfn_range(vma, vma->vm_start,
+   (map->offset + offset) >> PAGE_SHIFT,
+   vma->vm_end - vma->vm_start,
+   vma->vm_page_prot))
+   return -EAGAIN;
+#endif
+
DRM_DEBUG("   Type = %d; start = 0x%lx, end = 0x%lx,"
  " offset = 0x%llx\n",
  map->type,
  vma->vm_start, vma->vm_end, (unsigned long 
long)(map->offset + offset));
+
vma->vm_ops = &drm_vm_ops;
break;
case _DRM_CONSISTENT:
-- 
1.7.0.1



[PATCH 2/4] drm: Add support for platform devices to register as DRM devices

2010-05-27 Thread jcro...@codeaurora.org
From: Jordan Crouse 

Allow platform devices without PCI resources to be DRM devices.

Signed-off-by: Jordan Crouse 
---
 drivers/gpu/drm/Kconfig   |4 +-
 drivers/gpu/drm/Makefile  |2 +-
 drivers/gpu/drm/drm_drv.c |   37 +---
 drivers/gpu/drm/drm_edid.c|4 +-
 drivers/gpu/drm/drm_info.c|   23 --
 drivers/gpu/drm/drm_ioctl.c   |   77 --
 drivers/gpu/drm/drm_irq.c |   15 ++--
 drivers/gpu/drm/drm_pci.c |  143 +
 drivers/gpu/drm/drm_platform.c|  122 
 drivers/gpu/drm/drm_stub.c|   89 +
 drivers/gpu/drm/drm_sysfs.c   |3 +-
 drivers/gpu/drm/i915/i915_dma.c   |1 +
 drivers/gpu/drm/i915/i915_drv.c   |2 +-
 drivers/gpu/drm/nouveau/nouveau_drv.c |2 +-
 drivers/gpu/drm/radeon/radeon_drv.c   |2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   |2 +-
 include/drm/drmP.h|   52 ++--
 17 files changed, 405 insertions(+), 175 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_platform.c

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 88910e5..520ab23 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -6,7 +6,7 @@
 #
 menuconfig DRM
tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI 
support)"
-   depends on (AGP || AGP=n) && PCI && !EMULATED_CMPXCHG && MMU
+   depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU
select I2C
select I2C_ALGOBIT
select SLOW_WORK
@@ -17,7 +17,7 @@ menuconfig DRM
  These modules provide support for synchronization, security, and
  DMA transfers. Please see  for more
  details.  You should also select and configure AGP
- (/dev/agpgart) support.
+ (/dev/agpgart) support if it is available for your platform.

 config DRM_KMS_HELPER
tristate
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index abe3f44..b4b2b48 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -9,7 +9,7 @@ drm-y   :=  drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
-   drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
+   drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
drm_crtc.o drm_modes.o drm_edid.o \
drm_info.o drm_debugfs.o drm_encoder_slave.o

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 4a66201..510bc87 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -243,47 +243,20 @@ int drm_lastclose(struct drm_device * dev)
  *
  * Initializes an array of drm_device structures, and attempts to
  * initialize all available devices, using consecutive minors, registering the
- * stubs and initializing the AGP device.
+ * stubs and initializing the device.
  *
  * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
  * after the initialization for driver customization.
  */
 int drm_init(struct drm_driver *driver)
 {
-   struct pci_dev *pdev = NULL;
-   const struct pci_device_id *pid;
-   int i;
-
DRM_DEBUG("\n");
-
INIT_LIST_HEAD(&driver->device_list);

-   if (driver->driver_features & DRIVER_MODESET)
-   return pci_register_driver(&driver->pci_driver);
-
-   /* If not using KMS, fall back to stealth mode manual scanning. */
-   for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
-   pid = &driver->pci_driver.id_table[i];
-
-   /* Loop around setting up a DRM device for each PCI device
-* matching our ID and device class.  If we had the internal
-* function that pci_get_subsys and pci_get_class used, we'd
-* be able to just pass pid in instead of doing a two-stage
-* thing.
-*/
-   pdev = NULL;
-   while ((pdev =
-   pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
-  pid->subdevice, pdev)) != NULL) {
-   if ((pdev->class & pid->class_mask) != pid->class)
-   continue;
-
-   /* stealth mode requires a manual probe */
-   pci_dev_get(pdev);
-   drm_get_dev(pdev, pid, driver);
-   }
-   }
-   return 0;
+   if (driver->driver_features & DRIVER_USE_PLATFORM_DEVICE)
+   return drm_platform_init(driver);
+   else
+   return drm_pci_init(driver);
 }

 EXPORT_SYMBOL(drm_init);
diff --git a/