just a preliminary post -- i submitted a short patch to add a
generic order_base_2() macro to <linux/log2.h>, which would allow the
following simplification to drm code.  is there anything obviously
wrong with what follows?

  the macro added to log2.h was simply:

#define order_base_2(n) ilog2(roundup_pow_of_two(n))

 drivers/char/drm/ati_pcigart.c |    7 +++--
 drivers/char/drm/drmP.h        |    1
 drivers/char/drm/drm_bufs.c    |   38 +++++--------------------------
 drivers/char/drm/r128_cce.c    |    3 +-
 drivers/char/drm/radeon_cp.c   |    3 +-
 5 files changed, 15 insertions(+), 37 deletions(-)

diff --git a/drivers/char/drm/ati_pcigart.c b/drivers/char/drm/ati_pcigart.c
index 3345641..b579e6d 100644
--- a/drivers/char/drm/ati_pcigart.c
+++ b/drivers/char/drm/ati_pcigart.c
@@ -31,6 +31,7 @@
  * DEALINGS IN THE SOFTWARE.
  */

+#include <linux/log2.h>
 #include "drmP.h"

 # define ATI_PCIGART_PAGE_SIZE         4096    /**< PCI GART page size */
@@ -87,7 +88,7 @@ int drm_ati_pcigart_cleanup(struct drm_device *dev, struct 
drm_ati_pcigart_info
                return 0;
        }

-       order = drm_order((gart_info->table_size + (PAGE_SIZE-1)) / PAGE_SIZE);
+       order = order_base_2((gart_info->table_size + (PAGE_SIZE-1)) / 
PAGE_SIZE);
        num_pages = 1 << order;

        if (gart_info->bus_addr) {
@@ -141,7 +142,7 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct 
drm_ati_pcigart_info *ga
        if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
                DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");

-               order = drm_order((gart_info->table_size +
+               order = order_base_2((gart_info->table_size +
                                   (PAGE_SIZE-1)) / PAGE_SIZE);
                num_pages = 1 << order;
                address = drm_ati_alloc_pcigart_table(order);
@@ -160,7 +161,7 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct 
drm_ati_pcigart_info *ga
                                             PCI_DMA_TODEVICE);
                if (bus_address == 0) {
                        DRM_ERROR("unable to map PCIGART pages!\n");
-                       order = drm_order((gart_info->table_size +
+                       order = order_base_2((gart_info->table_size +
                                           (PAGE_SIZE-1)) / PAGE_SIZE);
                        drm_ati_free_pcigart_table(address, order);
                        address = NULL;
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index dde02a1..0fd4e1c 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -960,7 +960,6 @@ extern int drm_freebufs(struct drm_device *dev, void *data,
                        struct drm_file *file_priv);
 extern int drm_mapbufs(struct drm_device *dev, void *data,
                       struct drm_file *file_priv);
-extern int drm_order(unsigned long size);
 extern unsigned long drm_get_resource_start(struct drm_device *dev,
                                            unsigned int resource);
 extern unsigned long drm_get_resource_len(struct drm_device *dev,
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index d24a6c2..ad04d6e 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -34,6 +34,7 @@
  */

 #include <linux/vmalloc.h>
+#include <linux/log2.h>
 #include "drmP.h"

 unsigned long drm_get_resource_start(struct drm_device *dev, unsigned int 
resource)
@@ -202,7 +203,7 @@ static int drm_addmap_core(struct drm_device * dev, 
unsigned int offset,
                }
                map->handle = vmalloc_user(map->size);
                DRM_DEBUG("%lu %d %p\n",
-                         map->size, drm_order(map->size), map->handle);
+                         map->size, order_base_2(map->size), map->handle);
                if (!map->handle) {
                        drm_free(map, sizeof(*map), DRM_MEM_MAPS);
                        return -ENOMEM;
@@ -554,7 +555,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct 
drm_buf_desc * request)
                return -EINVAL;

        count = request->count;
-       order = drm_order(request->size);
+       order = order_base_2(request->size);
        size = 1 << order;

        alignment = (request->flags & _DRM_PAGE_ALIGN)
@@ -731,7 +732,7 @@ int drm_addbufs_pci(struct drm_device * dev, struct 
drm_buf_desc * request)
                return -EPERM;

        count = request->count;
-       order = drm_order(request->size);
+       order = order_base_2(request->size);
        size = 1 << order;

        DRM_DEBUG("count=%d, size=%d (%d), order=%d, queue_count=%d\n",
@@ -955,7 +956,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct 
drm_buf_desc * request
                return -EPERM;

        count = request->count;
-       order = drm_order(request->size);
+       order = order_base_2(request->size);
        size = 1 << order;

        alignment = (request->flags & _DRM_PAGE_ALIGN)
@@ -1117,7 +1118,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct 
drm_buf_desc * request
                return -EPERM;

        count = request->count;
-       order = drm_order(request->size);
+       order = order_base_2(request->size);
        size = 1 << order;

        alignment = (request->flags & _DRM_PAGE_ALIGN)
@@ -1401,7 +1402,7 @@ int drm_markbufs(struct drm_device *dev, void *data,

        DRM_DEBUG("%d, %d, %d\n",
                  request->size, request->low_mark, request->high_mark);
-       order = drm_order(request->size);
+       order = order_base_2(request->size);
        if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
                return -EINVAL;
        entry = &dma->bufs[order];
@@ -1569,28 +1570,3 @@ int drm_mapbufs(struct drm_device *dev, void *data,

        return retcode;
 }
-
-/**
- * Compute size order.  Returns the exponent of the smaller power of two which
- * is greater or equal to given number.
- *
- * \param size size.
- * \return order.
- *
- * \todo Can be made faster.
- */
-int drm_order(unsigned long size)
-{
-       int order;
-       unsigned long tmp;
-
-       for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ;
-
-       if (size & (size - 1))
-               ++order;
-
-       return order;
-}
-EXPORT_SYMBOL(drm_order);
-
-
diff --git a/drivers/char/drm/r128_cce.c b/drivers/char/drm/r128_cce.c
index 7d550ab..82930f8 100644
--- a/drivers/char/drm/r128_cce.c
+++ b/drivers/char/drm/r128_cce.c
@@ -29,6 +29,7 @@
  *    Gareth Hughes <[EMAIL PROTECTED]>
  */

+#include <linux/log2.h>
 #include "drmP.h"
 #include "drm.h"
 #include "r128_drm.h"
@@ -543,7 +544,7 @@ static int r128_do_init_cce(struct drm_device * dev, 
drm_r128_init_t * init)
        dev_priv->ring.end = ((u32 *) dev_priv->cce_ring->handle
                              + init->ring_size / sizeof(u32));
        dev_priv->ring.size = init->ring_size;
-       dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
+       dev_priv->ring.size_l2qw = order_base_2(init->ring_size / 8);

        dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;

diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index 24fca8e..ce35882 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -28,6 +28,7 @@
  *    Gareth Hughes <[EMAIL PROTECTED]>
  */

+#include <linux/log2.h>
 #include "drmP.h"
 #include "drm.h"
 #include "radeon_drm.h"
@@ -1661,7 +1662,7 @@ static int radeon_do_init_cp(struct drm_device * dev, 
drm_radeon_init_t * init)
        dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
                              + init->ring_size / sizeof(u32));
        dev_priv->ring.size = init->ring_size;
-       dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
+       dev_priv->ring.size_l2qw = order_base_2(init->ring_size / 8);

        dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;


 --
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

Reply via email to