Linux-kernel mailing list archive 2000-07,: [PATCH] get_order() centralization

# [PATCH] get_order() centralization

Jakub Jelinek (jakub@redhat.com)
Mon, 14 Feb 2000 17:05:58 +0100

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Richard B. Johnson: "Re: Port of 3c575_cb to 2.3.43pre8"
- Previous message: Richard A Nelson: "Re: [PATCH] isa_{read,write}{w,l} fixed"

--Y/WcH0a6A93yCHGr
Content-Type: text/plain; charset=us-ascii

Hi!

Since my last patch related to this, a couple more get_order implementations
appeared in the kernel source (currently there are 22 of them) and IMHO
it really makes sense to provide get_order(size) from asm headers, so that
the code is more readable and architectures (like ia64) are able to optimize
get_order() as they wish (including choosing to implement it out-of-line).
I removed the bsrl implementation for Intel since the last patch because it
really seems it is slower than a simple loop.

Please apply.

Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.45 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

--Y/WcH0a6A93yCHGr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="linux-2.3.45-getorder.patch"

--- linux/arch/alpha/kernel/pci_iommu.c.jj Mon Feb 14 08:40:28 2000
+++ linux/arch/alpha/kernel/pci_iommu.c Mon Feb 14 15:51:34 2000
@@ -39,20 +39,6 @@ calc_npages(long bytes)
{
return (bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
}
-
-static inline long
-calc_order(long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
struct pci_iommu_arena *
iommu_arena_new(dma_addr_t base, unsigned long window_size,
@@ -248,7 +234,7 @@ void *
pci_alloc_consistent(struct pci_dev *pdev, long size, dma_addr_t *dma_addrp)
{
void *cpu_addr;
- long order = calc_order(size);
+ long order = get_order(size);
cpu_addr = (void *)__get_free_pages(GFP_ATOMIC, order);
if (! cpu_addr) {
@@ -285,7 +271,7 @@ pci_free_consistent(struct pci_dev *pdev
dma_addr_t dma_addr)
{
pci_unmap_single(pdev, dma_addr, size);
- free_pages((unsigned long)cpu_addr, calc_order(size));
+ free_pages((unsigned long)cpu_addr, get_order(size));
DBGA2("pci_free_consistent: [%x,%lx] from %p\n",
dma_addr, size, __builtin_return_address(0));
--- linux/arch/arm/mm/consistent.c.jj Mon Feb 14 03:49:19 2000
+++ linux/arch/arm/mm/consistent.c Mon Feb 14 15:51:34 2000
@@ -12,20 +12,6 @@
#include <asm/io.h>
#include <asm/pgalloc.h>
-/* Pure 2^n version of get_order */
-extern __inline__ int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
/*
* This allocates one page of cache-coherent memory space and returns
* both the virtual and a "dma" address to that space. It is not clear
@@ -43,7 +29,7 @@ void *consistent_alloc(int gfp, size_t s
if (in_interrupt())
BUG();
- order = __get_order(size);
+ order = get_order(size);
page = __get_free_pages(gfp, order);
if (!page)
--- linux/arch/i386/kernel/pci-dma.c.jj Fri Jan 28 18:20:50 2000
+++ linux/arch/i386/kernel/pci-dma.c Mon Feb 14 15:51:34 2000
@@ -13,20 +13,6 @@
#include <linux/pci.h>
#include <asm/io.h>
-/* Pure 2^n version of get_order */
-extern __inline__ int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
dma_addr_t *dma_handle)
{
@@ -35,7 +21,7 @@ void *pci_alloc_consistent(struct pci_de
if (hwdev == NULL || hwdev->dma_mask != 0xffffffff)
gfp |= GFP_DMA;
- ret = (void *)__get_free_pages(gfp, __get_order(size));
+ ret = (void *)__get_free_pages(gfp, get_order(size));
if (ret != NULL) {
memset(ret, 0, size);
@@ -47,5 +33,5 @@ void *pci_alloc_consistent(struct pci_de
void pci_free_consistent(struct pci_dev *hwdev, size_t size,
void *vaddr, dma_addr_t dma_handle)
{
- free_pages((unsigned long)vaddr, __get_order(size));
+ free_pages((unsigned long)vaddr, get_order(size));
}
--- linux/arch/ia64/kernel/pci-dma.c.jj Mon Feb 14 08:42:03 2000
+++ linux/arch/ia64/kernel/pci-dma.c Mon Feb 14 15:51:34 2000
@@ -17,21 +17,6 @@
#include <asm/io.h>
-/* Pure 2^n version of get_order */
-extern __inline__ unsigned long
-get_order (unsigned long size)
-{
- unsigned long order = ia64_fls(size - 1) + 1;
-
- printk ("get_order: size=%lu, order=%lu\n", size, order);
-
- if (order > PAGE_SHIFT)
- order -= PAGE_SHIFT;
- else
- order = 0;
- return order;
-}
-
void *
pci_alloc_consistent (struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle)
{
--- linux/arch/mips/jazz/floppy-jazz.c.jj Wed Oct 13 07:44:28 1999
+++ linux/arch/mips/jazz/floppy-jazz.c Mon Feb 14 15:51:34 2000
@@ -94,26 +94,11 @@ static unsigned long jazz_fd_getfdaddr1(
return JAZZ_FDC_BASE;
}
-/* Pure 2^n version of get_order */
-extern inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
static unsigned long jazz_fd_dma_mem_alloc(unsigned long size)
{
- int order = __get_order(size);
unsigned long mem;
- mem = __get_dma_pages(GFP_KERNEL, order);
+ mem = __get_dma_pages(GFP_KERNEL, get_order(size));
if(!mem)
return 0;
vdma_alloc(PHYSADDR(mem), size); /* XXX error checking */
@@ -125,7 +110,7 @@ static void jazz_fd_dma_mem_free(unsigne
unsigned long size)
{
vdma_free(vdma_phys2log(PHYSADDR(addr)));
- free_pages(addr, __get_order(size));
+ free_pages(addr, get_order(size));
}
static unsigned long jazz_fd_drive_type(unsigned long n)
--- linux/arch/mips/lib/floppy-std.c.jj Wed Oct 13 07:44:43 1999
+++ linux/arch/mips/lib/floppy-std.c Mon Feb 14 15:51:34 2000
@@ -102,33 +102,18 @@ static unsigned long std_fd_getfdaddr1(v
return 0x3f0;
}
-/* Pure 2^n version of get_order */
-static int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
static unsigned long std_fd_dma_mem_alloc(unsigned long size)
{
- int order = __get_order(size);
unsigned long mem;
- mem = __get_dma_pages(GFP_KERNEL,order);
+ mem = __get_dma_pages(GFP_KERNEL,get_order(size));
return mem;
}
static void std_fd_dma_mem_free(unsigned long addr, unsigned long size)
{
- free_pages(addr, __get_order(size));
+ free_pages(addr, get_order(size));
}
static unsigned long std_fd_drive_type(unsigned long n)
--- linux/arch/ppc/kernel/pci-dma.c.jj Thu Feb 10 03:49:43 2000
+++ linux/arch/ppc/kernel/pci-dma.c Mon Feb 14 15:51:34 2000
@@ -14,20 +14,6 @@
#include <linux/pci.h>
#include <asm/io.h>
-/* Pure 2^n version of get_order */
-extern __inline__ int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
dma_addr_t *dma_handle)
{
@@ -36,7 +22,7 @@ void *pci_alloc_consistent(struct pci_de
if (hwdev == NULL || hwdev->dma_mask != 0xffffffff)
gfp |= GFP_DMA;
- ret = (void *)__get_free_pages(gfp, __get_order(size));
+ ret = (void *)__get_free_pages(gfp, get_order(size));
if (ret != NULL) {
memset(ret, 0, size);
@@ -48,5 +34,5 @@ void *pci_alloc_consistent(struct pci_de
void pci_free_consistent(struct pci_dev *hwdev, size_t size,
void *vaddr, dma_addr_t dma_handle)
{
- free_pages((unsigned long)vaddr, __get_order(size));
+ free_pages((unsigned long)vaddr, get_order(size));
}
--- linux/arch/sparc/kernel/ioport.c.jj Sat Feb 12 13:56:09 2000
+++ linux/arch/sparc/kernel/ioport.c Mon Feb 14 15:51:34 2000
@@ -44,7 +44,6 @@
#include <asm/pgtable.h>
struct resource *_sparc_find_resource(struct resource *r, unsigned long);
-int _sparc_len2order(unsigned long len);
static void *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
static void *_sparc_alloc_io(unsigned int busno, unsigned long phys,
@@ -280,7 +279,7 @@ void *sbus_alloc_consistent(struct sbus_
return NULL;
}
- order = _sparc_len2order(len_total);
+ order = get_order(len_total);
va = __get_free_pages(GFP_KERNEL, order);
if (va == 0) {
/*
@@ -341,7 +340,7 @@ void sbus_free_consistent(struct sbus_de
pgp = (unsigned long) phys_to_virt(mmu_translate_dvma(ba));
mmu_unmap_dma_area(ba, n);
- free_pages(pgp, _sparc_len2order(n));
+ free_pages(pgp, get_order(n));
}
/*
@@ -482,7 +481,7 @@ void *pci_alloc_consistent(struct pci_de
return NULL;
}
- order = _sparc_len2order(len_total);
+ order = get_order(len_total);
va = __get_free_pages(GFP_KERNEL, order);
if (va == 0) {
printk("pci_alloc_consistent: no %ld pages\n", len_total>>PAGE_SHIFT);
@@ -569,7 +568,7 @@ void pci_free_consistent(struct pci_dev
release_resource(res);
kfree(res);
- free_pages(pgp, _sparc_len2order(n));
+ free_pages(pgp, get_order(n));
}
/* Map a single buffer of the indicated size for DMA in streaming mode.
@@ -737,19 +736,6 @@ _sparc_find_resource(struct resource *ro
return tmp;
}
return NULL;
-}
-
-int
-_sparc_len2order(unsigned long len)
-{
- int order;
-
- for (order = 0; order < 7; order++) /* 2^6 pages == 256K */
- if ((1 << (order + PAGE_SHIFT)) >= len)
- return order;
- printk("len2order: from %p: len %lu(0x%lx) yields order >=7.\n",
- __builtin_return_address(0), len, len);
- return 1;
}
/*
--- linux/arch/sparc64/kernel/pci_iommu.c.jj Fri Jan 28 14:41:59 2000
+++ linux/arch/sparc64/kernel/pci_iommu.c Mon Feb 14 15:51:34 2000
@@ -123,11 +123,8 @@ void *pci_alloc_consistent(struct pci_de
int npages;
size = PAGE_ALIGN(size);
- for (order = 0; order < 10; order++) {
- if ((PAGE_SIZE << order) >= size)
- break;
- }
- if (order == 10)
+ order = get_order(size);
+ if (order >= 10)
return NULL;
/* We still don't support devices which don't recognize at least 30 bits
@@ -210,10 +207,7 @@ void pci_free_consistent(struct pci_dev
spin_unlock_irqrestore(&iommu->lock, flags);
- for (order = 0; order < 10; order++) {
- if ((PAGE_SIZE << order) >= size)
- break;
- }
+ order = get_order(size);
if (order < 10)
free_pages((unsigned long)cpu, order);
}
--- linux/arch/sparc64/kernel/sbus.c.jj Fri Jan 28 14:41:58 2000
+++ linux/arch/sparc64/kernel/sbus.c Mon Feb 14 15:51:34 2000
@@ -255,11 +255,8 @@ void *sbus_alloc_consistent(struct sbus_
return NULL;
size = PAGE_ALIGN(size);
- for (order = 0; order < 10; order++) {
- if ((PAGE_SIZE << order) >= size)
- break;
- }
- if (order == 10)
+ order = get_order(size);
+ if (order >= 10)
return NULL;
first_page = __get_free_pages(GFP_KERNEL, order);
if (first_page == 0UL)
@@ -306,10 +303,7 @@ void sbus_free_consistent(struct sbus_de
free_consistent_cluster(iommu, dvma, npages);
spin_unlock_irq(&iommu->lock);
- for (order = 0; order < 10; order++) {
- if ((PAGE_SIZE << order) >= size)
- break;
- }
+ order = get_order(size);
if (order < 10)
free_pages((unsigned long)cpu, order);
}
--- linux/arch/sparc64/kernel/smp.c.jj Fri Jan 21 10:52:17 2000
+++ linux/arch/sparc64/kernel/smp.c Mon Feb 14 15:51:34 2000
@@ -753,9 +753,7 @@ static void __init smp_tune_scheduling (
"ecache-size", (512 * 1024));
if (ecache_size > (4 * 1024 * 1024))
ecache_size = (4 * 1024 * 1024);
- for (order = 0UL; (PAGE_SIZE << order) < ecache_size; order++)
- ;
- flush_base = __get_free_pages(GFP_KERNEL, order);
+ flush_base = __get_free_pages(GFP_KERNEL, order = get_order(ecache_size));
if (flush_base != 0UL) {
__save_and_cli(flags);
--- linux/arch/sparc64/kernel/pci_sabre.c.jj Tue Feb 8 10:26:16 2000
+++ linux/arch/sparc64/kernel/pci_sabre.c Mon Feb 14 16:46:24 2000
@@ -1133,10 +1133,7 @@ static void __init sabre_iommu_init(stru
control &= ~(SABRE_IOMMUCTRL_DENAB);
sabre_write(p->controller_regs + SABRE_IOMMU_CONTROL, control);
- for(order = 0;; order++)
- if((PAGE_SIZE << order) >= ((tsbsize * 1024) * 8))
- break;
- tsbbase = __get_free_pages(GFP_KERNEL, order);
+ tsbbase = __get_free_pages(GFP_KERNEL, order = get_order(tsbsize * 1024 * 8));
if (!tsbbase) {
prom_printf("SABRE_IOMMU: Error, gfp(tsb) failed.\n");
prom_halt();
--- linux/drivers/block/xd.c.jj Fri Jan 21 10:52:51 2000
+++ linux/drivers/block/xd.c Mon Feb 14 15:51:34 2000
@@ -87,21 +87,8 @@ XD_INFO xd_info[XD_MAXDRIVES];
should be able to detect your drive's geometry from this info. (eg: xd=0,5,0x320,3 is the "standard"). */
#include <asm/page.h>
-/* coppied from floppy.c */
-static inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-#define xd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,__get_order(size))
-#define xd_dma_mem_free(addr, size) free_pages(addr, __get_order(size))
+#define xd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,get_order(size))
+#define xd_dma_mem_free(addr, size) free_pages(addr, get_order(size))
static char *xd_dma_buffer = 0;
static XD_SIGNATURE xd_sigs[] __initdata = {
--- linux/drivers/block/floppy.c.jj Thu Feb 10 17:06:19 2000
+++ linux/drivers/block/floppy.c Mon Feb 14 15:51:34 2000
@@ -196,7 +196,6 @@ static int use_virtual_dma=0;
static unsigned short virtual_dma_port=0x3f0;
void floppy_interrupt(int irq, void *dev_id, struct pt_regs * regs);
static int set_dor(int fdc, char mask, char data);
-static inline int __get_order(unsigned long size);
#define K_64 0x10000 /* 64KB */
#include <asm/floppy.h>
@@ -213,26 +212,12 @@ static inline int __get_order(unsigned l
/* Dma Memory related stuff */
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
#ifndef fd_dma_mem_free
-#define fd_dma_mem_free(addr, size) free_pages(addr, __get_order(size))
+#define fd_dma_mem_free(addr, size) free_pages(addr, get_order(size))
#endif
#ifndef fd_dma_mem_alloc
-#define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,__get_order(size))
+#define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,get_order(size))
#endif
static inline void fallback_on_nodma_alloc(char **addr, size_t l)
--- linux/drivers/char/ftape/lowlevel/ftape-buffer.c.jj Wed Oct 13 07:51:29 1999
+++ linux/drivers/char/ftape/lowlevel/ftape-buffer.c Mon Feb 14 15:51:34 2000
@@ -39,20 +39,6 @@
/* DMA'able memory allocation stuff.
*/
-/* Pure 2^n version of get_order */
-static inline int __get_order(size_t size)
-{
- unsigned long order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
static inline void *dmaalloc(size_t size)
{
unsigned long addr;
@@ -60,7 +46,7 @@ static inline void *dmaalloc(size_t size
if (size == 0) {
return NULL;
}
- addr = __get_dma_pages(GFP_KERNEL, __get_order(size));
+ addr = __get_dma_pages(GFP_KERNEL, get_order(size));
if (addr) {
int i;
@@ -80,7 +66,7 @@ static inline void dmafree(void *addr, s
i < MAP_NR((unsigned long)addr+size); i++) {
mem_map_unreserve (i);
}
- free_pages((unsigned long) addr, __get_order(size));
+ free_pages((unsigned long) addr, get_order(size));
}
}
--- linux/drivers/char/esp.c.jj Wed Oct 13 07:49:45 1999
+++ linux/drivers/char/esp.c Mon Feb 14 15:51:34 2000
@@ -203,20 +203,6 @@ static inline void serial_out(struct esp
outb(value, info->port+offset);
}
-static inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size + PAGE_SIZE -1) >> PAGE_SHIFT;
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
-
- return order;
-}
-
/*
* ------------------------------------------------------------
* rs_stop() and rs_start()
@@ -965,14 +951,14 @@ static int startup(struct esp_struct * i
if (!(info->stat_flags & ESP_STAT_USE_PIO) && !dma_buffer) {
dma_buffer = (char *)__get_dma_pages(
- GFP_KERNEL, __get_order(DMA_BUFFER_SZ));
+ GFP_KERNEL, get_order(DMA_BUFFER_SZ));
/* use PIO mode if DMA buf/chan cannot be allocated */
if (!dma_buffer)
info->stat_flags |= ESP_STAT_USE_PIO;
else if (request_dma(dma, "esp serial")) {
free_pages((unsigned int)dma_buffer,
- __get_order(DMA_BUFFER_SZ));
+ get_order(DMA_BUFFER_SZ));
dma_buffer = 0;
info->stat_flags |= ESP_STAT_USE_PIO;
}
@@ -1076,7 +1062,7 @@ static void shutdown(struct esp_struct *
if (!current_port) {
free_dma(dma);
free_pages((unsigned int)dma_buffer,
- __get_order(DMA_BUFFER_SZ));
+ get_order(DMA_BUFFER_SZ));
dma_buffer = 0;
}
}
@@ -2785,7 +2771,7 @@ void cleanup_module(void)
if (dma_buffer)
free_pages((unsigned int)dma_buffer,
- __get_order(DMA_BUFFER_SZ));
+ get_order(DMA_BUFFER_SZ));
if (tmp_buf)
free_page((unsigned long)tmp_buf);
--- linux/drivers/char/tpqic02.c.jj Thu Feb 10 17:07:28 2000
+++ linux/drivers/char/tpqic02.c Mon Feb 14 15:51:34 2000
@@ -2774,23 +2774,6 @@ static struct file_operations qic02_tape
};
-/* Why is this not is one place? */
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size-1) >> (PAGE_SHIFT-1);
- order = -1;
- do
- {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
-
static void qic02_release_resources(void)
{
free_irq(QIC02_TAPE_IRQ, NULL);
@@ -2798,7 +2781,7 @@ static void qic02_release_resources(void
release_region(QIC02_TAPE_PORT, QIC02_TAPE_PORT_RANGE);
if (buffaddr)
{
- free_pages(buffaddr, __get_order(TPQBUF_SIZE));
+ free_pages(buffaddr, get_order(TPQBUF_SIZE));
}
buffaddr = 0; /* Better to cause a panic than overwite someone else */
status_zombie = YES;
@@ -2850,7 +2833,7 @@ static int qic02_get_resources(void)
/* Setup the page-address for the dma transfer. */
/*** TODO: does _get_dma_pages() really return the physical address?? ****/
- buffaddr = __get_dma_pages(GFP_KERNEL,__get_order(TPQBUF_SIZE));
+ buffaddr = __get_dma_pages(GFP_KERNEL,get_order(TPQBUF_SIZE));
if (!buffaddr)
{
--- linux/drivers/char/zr36120_mem.c.jj Mon Jan 3 08:14:03 2000
+++ linux/drivers/char/zr36120_mem.c Mon Feb 14 15:51:34 2000
@@ -35,17 +35,6 @@
/* Memory management functions */
/*******************************/
-inline int __get_order(unsigned long size)
-{
- int order = 0;
- size = (size+PAGE_SIZE-1)/PAGE_SIZE;
- while (size) {
- size /= 2;
- order++;
- }
- return order;
-}
-
void* bmalloc(unsigned long size)
{
void* mem;
@@ -56,7 +45,7 @@ void* bmalloc(unsigned long size)
* The following function got a lot of memory at boottime,
* so we know its always there...
*/
- mem = (void*)__get_free_pages(GFP_USER|GFP_DMA,__get_order(size));
+ mem = (void*)__get_free_pages(GFP_USER|GFP_DMA,get_order(size));
#endif
if (mem) {
unsigned long adr = (unsigned long)mem;
@@ -82,7 +71,7 @@ void bfree(void* mem, unsigned long size
#ifdef CONFIG_BIGPHYS_AREA
bigphysarea_free_pages(mem);
#else
- free_pages((unsigned long)mem,__get_order(size));
+ free_pages((unsigned long)mem,get_order(size));
#endif
}
}
--- linux/drivers/net/ltpc.c.jj Fri Feb 11 10:15:16 2000
+++ linux/drivers/net/ltpc.c Mon Feb 14 15:51:34 2000
@@ -246,23 +246,9 @@ static int sendup_buffer (struct net_dev
/* Dma Memory related stuff, cribbed directly from 3c505.c */
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size - 1) >> (PAGE_SHIFT - 1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
static unsigned long dma_mem_alloc(int size)
{
- int order = __get_order(size);
+ int order = get_order(size);
return __get_dma_pages(GFP_KERNEL, order);
}
@@ -1364,7 +1350,7 @@ void cleanup_module(void)
if(debug&DEBUG_VERBOSE) printk("free_pages\n");
- free_pages( (unsigned long) ltdmabuf, __get_order(1000));
+ free_pages( (unsigned long) ltdmabuf, get_order(1000));
ltdmabuf=NULL;
ltdmacbuf=NULL;
--- linux/drivers/net/3c505.c.jj Mon Feb 14 08:43:07 2000
+++ linux/drivers/net/3c505.c Mon Feb 14 15:51:35 2000
@@ -184,23 +184,9 @@ static const int addr_list[] __initdata
/* Dma Memory related stuff */
-/* Pure 2^n version of get_order */
-static inline int __get_order(unsigned long size)
-{
- int order;
-
- size = (size - 1) >> (PAGE_SHIFT - 1);
- order = -1;
- do {
- size >>= 1;
- order++;
- } while (size);
- return order;
-}
-
static unsigned long dma_mem_alloc(int size)
{
- int order = __get_order(size);
+ int order = get_order(size);
return __get_dma_pages(GFP_KERNEL, order);
}
@@ -1191,7 +1177,7 @@ static int elp_close(struct net_device *
free_irq(dev->irq, dev);
free_dma(dev->dma);
- free_pages((unsigned long) adapter->dma_buffer, __get_order(DMA_BUFFER_SIZE));
+ free_pages((unsigned long) adapter->dma_buffer, get_order(DMA_BUFFER_SIZE));
MOD_DEC_USE_COUNT;
--- linux/include/asm-alpha/page.h.jj Mon Dec 20 09:28:25 1999
+++ linux/include/asm-alpha/page.h Mon Feb 14 15:51:35 2000
@@ -109,6 +109,20 @@ typedef unsigned long pgprot_t;
#define BUG() __asm__ __volatile__("call_pal 129 # bugchk")
#define PAGE_BUG(page) BUG()
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* !ASSEMBLY */
/* to align the pointer to the (next) page boundary */
--- linux/include/asm-arm/page.h.jj Fri Jan 14 09:44:35 2000
+++ linux/include/asm-arm/page.h Mon Feb 14 15:51:35 2000
@@ -65,6 +65,20 @@ extern void __bug(const char *file, int
#define BUG() __bug(__FILE__, __LINE__, NULL)
#define PAGE_BUG(page) __bug(__FILE__, __LINE__, page)
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* !__ASSEMBLY__ */
#include <asm/arch/memory.h>
--- linux/include/asm-i386/page.h.jj Thu Feb 10 17:12:53 2000
+++ linux/include/asm-i386/page.h Mon Feb 14 16:41:55 2000
@@ -94,6 +94,20 @@ extern int console_loglevel;
BUG(); \
} while (0)
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* __ASSEMBLY__ */
#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
--- linux/include/asm-i386/floppy.h.jj Wed Oct 13 08:06:31 1999
+++ linux/include/asm-i386/floppy.h Mon Feb 14 15:52:34 2000
@@ -190,7 +190,7 @@ static int fd_request_irq(void)
static unsigned long dma_mem_alloc(unsigned long size)
{
- return __get_dma_pages(GFP_KERNEL,__get_order(size));
+ return __get_dma_pages(GFP_KERNEL,get_order(size));
}
@@ -207,7 +207,7 @@ static void _fd_dma_mem_free(unsigned lo
if((unsigned int) addr >= (unsigned int) high_memory)
return vfree((void *)addr);
else
- free_pages(addr, __get_order(size));
+ free_pages(addr, get_order(size));
}
#define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
--- linux/include/asm-m68k/page.h.jj Sat Jan 29 21:21:04 2000
+++ linux/include/asm-m68k/page.h Mon Feb 14 15:51:35 2000
@@ -97,6 +97,20 @@ typedef struct { unsigned long pgprot; }
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* !__ASSEMBLY__ */
#include <asm/page_offset.h>
--- linux/include/asm-mips/page.h.jj Wed Oct 13 08:07:26 1999
+++ linux/include/asm-mips/page.h Mon Feb 14 15:51:35 2000
@@ -65,6 +65,20 @@ typedef unsigned long pgprot_t;
#endif /* !defined (STRICT_MM_TYPECHECKS) */
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* _LANGUAGE_ASSEMBLY */
/* to align the pointer to the (next) page boundary */
--- linux/include/asm-ppc/page.h.jj Mon Feb 14 08:49:58 2000
+++ linux/include/asm-ppc/page.h Mon Feb 14 15:51:35 2000
@@ -113,6 +113,21 @@ static inline void* ___va(unsigned long
#define MAP_PAGE_RESERVED (1<<15)
extern unsigned long get_zero_page_fast(void);
+
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */
#endif /* _PPC_PAGE_H */
--- linux/include/asm-sh/page.h.jj Thu Dec 9 12:02:17 1999
+++ linux/include/asm-sh/page.h Mon Feb 14 15:51:35 2000
@@ -76,6 +76,21 @@ extern int console_loglevel;
#define PAGE_BUG(page) do { \
BUG(); \
} while (0)
+
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif
#endif /* __KERNEL__ */
--- linux/include/asm-sparc/page.h.jj Mon Jan 31 17:48:29 2000
+++ linux/include/asm-sparc/page.h Mon Feb 14 15:51:35 2000
@@ -129,6 +129,20 @@ BTFIXUPDEF_SETHI(sparc_unmapped_base)
#define TASK_UNMAPPED_BASE BTFIXUP_SETHI(sparc_unmapped_base)
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#else /* !(__ASSEMBLY__) */
#define __pgprot(x) (x)
--- linux/include/asm-sparc64/page.h.jj Thu Dec 9 12:03:21 1999
+++ linux/include/asm-sparc64/page.h Mon Feb 14 15:51:35 2000
@@ -126,6 +126,20 @@ struct sparc_phys_banks {
extern struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS];
+/* Pure 2^n version of get_order */
+extern __inline__ int get_order(unsigned long size)
+{
+ int order;
+
+ size = (size-1) >> (PAGE_SHIFT-1);
+ order = -1;
+ do {
+ size >>= 1;
+ order++;
+ } while (size);
+ return order;
+}
+
#endif /* !(__ASSEMBLY__) */
#endif /* !(__KERNEL__) */
--- linux/include/asm-ia64/page.h.jj Mon Feb 7 21:58:01 2000
+++ linux/include/asm-ia64/page.h Mon Feb 14 15:51:35 2000
@@ -127,6 +127,18 @@ typedef union ia64_va {
#define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); *(int *)0=0; } while (0)
#define PAGE_BUG(page) do { BUG(); } while (0)
+extern __inline__ int get_order(unsigned long size)
+{
+ double d = size - 1;
+ long order;
+
+ __asm__ ("getf.exp %0=%1" : "=r"(order) : "f"(d));
+ order = order - PAGE_SHIFT - 0xffff + 1;
+ if (order < 0)
+ order = 0;
+ return order;
+}
+
#endif /* !ASSEMBLY */
#define PAGE_OFFSET 0xe000000000000000

--Y/WcH0a6A93yCHGr--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

- Next message: Richard B. Johnson: "Re: Port of 3c575_cb to 2.3.43pre8"
- Previous message: Richard A Nelson: "Re: [PATCH] isa_{read,write}{w,l} fixed"