From 5be3246306e613055505f4950411f5497d97edb0 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sat, 21 May 2011 20:46:39 +0200 Subject: m68k/amiga: Chip RAM - Use tabs for indentation Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index dd0447d..e757fff 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -23,101 +23,105 @@ unsigned long amiga_chip_size; EXPORT_SYMBOL(amiga_chip_size); static struct resource chipram_res = { - .name = "Chip RAM", .start = CHIP_PHYSADDR + .name = "Chip RAM", .start = CHIP_PHYSADDR }; static unsigned long chipavail; void __init amiga_chip_init(void) { - if (!AMIGAHW_PRESENT(CHIP_RAM)) - return; + if (!AMIGAHW_PRESENT(CHIP_RAM)) + return; - chipram_res.end = amiga_chip_size-1; - request_resource(&iomem_resource, &chipram_res); + chipram_res.end = amiga_chip_size-1; + request_resource(&iomem_resource, &chipram_res); - chipavail = amiga_chip_size; + chipavail = amiga_chip_size; } void *amiga_chip_alloc(unsigned long size, const char *name) { - struct resource *res; + struct resource *res; - /* round up */ - size = PAGE_ALIGN(size); + /* round up */ + size = PAGE_ALIGN(size); #ifdef DEBUG - printk("amiga_chip_alloc: allocate %ld bytes\n", size); + printk("amiga_chip_alloc: allocate %ld bytes\n", size); #endif - res = kzalloc(sizeof(struct resource), GFP_KERNEL); - if (!res) - return NULL; - res->name = name; - - if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) { - kfree(res); - return NULL; - } - chipavail -= size; + res = kzalloc(sizeof(struct resource), GFP_KERNEL); + if (!res) + return NULL; + res->name = name; + + if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, + NULL, NULL) < 0) { + kfree(res); + return NULL; + } + chipavail -= size; #ifdef DEBUG - printk("amiga_chip_alloc: returning %lx\n", res->start); + printk("amiga_chip_alloc: returning %lx\n", res->start); #endif - return (void *)ZTWO_VADDR(res->start); + return (void *)ZTWO_VADDR(res->start); } EXPORT_SYMBOL(amiga_chip_alloc); - /* - * Warning: - * amiga_chip_alloc_res is meant only for drivers that need to allocate - * Chip RAM before kmalloc() is functional. As a consequence, those - * drivers must not free that Chip RAM afterwards. - */ + /* + * Warning: + * amiga_chip_alloc_res is meant only for drivers that need to + * allocate Chip RAM before kmalloc() is functional. As a consequence, + * those drivers must not free that Chip RAM afterwards. + */ void * __init amiga_chip_alloc_res(unsigned long size, struct resource *res) { - unsigned long start; + unsigned long start; - /* round up */ - size = PAGE_ALIGN(size); - /* dmesg into chipmem prefers memory at the safe end */ - start = CHIP_PHYSADDR + chipavail - size; + /* round up */ + size = PAGE_ALIGN(size); + /* dmesg into chipmem prefers memory at the safe end */ + start = CHIP_PHYSADDR + chipavail - size; #ifdef DEBUG - printk("amiga_chip_alloc_res: allocate %ld bytes\n", size); + printk("amiga_chip_alloc_res: allocate %ld bytes\n", size); #endif - if (allocate_resource(&chipram_res, res, size, start, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) { - printk("amiga_chip_alloc_res: first alloc failed!\n"); - if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) - return NULL; - } - chipavail -= size; + if (allocate_resource(&chipram_res, res, size, start, UINT_MAX, + PAGE_SIZE, NULL, NULL) < 0) { + printk("amiga_chip_alloc_res: first alloc failed!\n"); + if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, + PAGE_SIZE, NULL, NULL) < 0) + return NULL; + } + chipavail -= size; #ifdef DEBUG - printk("amiga_chip_alloc_res: returning %lx\n", res->start); + printk("amiga_chip_alloc_res: returning %lx\n", res->start); #endif - return (void *)ZTWO_VADDR(res->start); + return (void *)ZTWO_VADDR(res->start); } void amiga_chip_free(void *ptr) { - unsigned long start = ZTWO_PADDR(ptr); - struct resource **p, *res; - unsigned long size; - - for (p = &chipram_res.child; (res = *p); p = &res->sibling) { - if (res->start != start) - continue; - *p = res->sibling; - size = res->end-start; + unsigned long start = ZTWO_PADDR(ptr); + struct resource **p, *res; + unsigned long size; + + for (p = &chipram_res.child; (res = *p); p = &res->sibling) { + if (res->start != start) + continue; + *p = res->sibling; + size = res->end-start; #ifdef DEBUG - printk("amiga_chip_free: free %ld bytes at %p\n", size, ptr); + printk("amiga_chip_free: free %ld bytes at %p\n", size, ptr); #endif - chipavail += size; - kfree(res); - return; - } - printk("amiga_chip_free: trying to free nonexistent region at %p\n", ptr); + chipavail += size; + kfree(res); + return; + } + printk("amiga_chip_free: trying to free nonexistent region at %p\n", + ptr); } EXPORT_SYMBOL(amiga_chip_free); -- cgit v0.10.2 From b4f6f45302a9440e26f71dab0b95906bcc3bd13a Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 24 Apr 2011 22:55:20 +0200 Subject: m68k/amiga: Chip RAM - Convert from printk() to pr_*() and fix a few formattings: - resource sizes are now resource_size_t, use %pR to make it future proof, - use %lu for unsigned long. Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index e757fff..9005fa0 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -47,9 +47,7 @@ void *amiga_chip_alloc(unsigned long size, const char *name) /* round up */ size = PAGE_ALIGN(size); -#ifdef DEBUG - printk("amiga_chip_alloc: allocate %ld bytes\n", size); -#endif + pr_debug("amiga_chip_alloc: allocate %lu bytes\n", size); res = kzalloc(sizeof(struct resource), GFP_KERNEL); if (!res) return NULL; @@ -61,9 +59,7 @@ void *amiga_chip_alloc(unsigned long size, const char *name) return NULL; } chipavail -= size; -#ifdef DEBUG - printk("amiga_chip_alloc: returning %lx\n", res->start); -#endif + pr_debug("amiga_chip_alloc: returning %pR\n", res); return (void *)ZTWO_VADDR(res->start); } EXPORT_SYMBOL(amiga_chip_alloc); @@ -85,20 +81,16 @@ void * __init amiga_chip_alloc_res(unsigned long size, struct resource *res) /* dmesg into chipmem prefers memory at the safe end */ start = CHIP_PHYSADDR + chipavail - size; -#ifdef DEBUG - printk("amiga_chip_alloc_res: allocate %ld bytes\n", size); -#endif + pr_debug("amiga_chip_alloc_res: allocate %lu bytes\n", size); if (allocate_resource(&chipram_res, res, size, start, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) { - printk("amiga_chip_alloc_res: first alloc failed!\n"); + pr_err("amiga_chip_alloc_res: first alloc failed!\n"); if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) return NULL; } chipavail -= size; -#ifdef DEBUG - printk("amiga_chip_alloc_res: returning %lx\n", res->start); -#endif + pr_debug("amiga_chip_alloc_res: returning %pR\n", res); return (void *)ZTWO_VADDR(res->start); } @@ -113,14 +105,12 @@ void amiga_chip_free(void *ptr) continue; *p = res->sibling; size = res->end-start; -#ifdef DEBUG - printk("amiga_chip_free: free %ld bytes at %p\n", size, ptr); -#endif + pr_debug("amiga_chip_free: free %lu bytes at %p\n", size, ptr); chipavail += size; kfree(res); return; } - printk("amiga_chip_free: trying to free nonexistent region at %p\n", + pr_err("amiga_chip_free: trying to free nonexistent region at %p\n", ptr); } EXPORT_SYMBOL(amiga_chip_free); @@ -128,9 +118,7 @@ EXPORT_SYMBOL(amiga_chip_free); unsigned long amiga_chip_avail(void) { -#ifdef DEBUG - printk("amiga_chip_avail : %ld bytes\n", chipavail); -#endif + pr_debug("amiga_chip_avail : %lu bytes\n", chipavail); return chipavail; } EXPORT_SYMBOL(amiga_chip_avail); -- cgit v0.10.2 From 3a17bfa4fb37e7f8e06ef31feafec559bd4c6699 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 24 Apr 2011 23:19:05 +0200 Subject: m68k/amiga: Chip RAM - Always allocate from the start of memory As of commit 5df1abdbd37af2ae317a1c5b5944173284dc55d6 ('m68k/amiga: Fix "debug=mem"'), "debug=mem" no longer uses amiga_chip_alloc_res(), so we can remove the hack to prefer memory at the safe end. This allows to simplify the code and make amiga_chip_alloc() just call amiga_chip_alloc_res() internally. Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index 9005fa0..e5a8dbc 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -43,24 +43,20 @@ void __init amiga_chip_init(void) void *amiga_chip_alloc(unsigned long size, const char *name) { struct resource *res; + void *p; - /* round up */ - size = PAGE_ALIGN(size); - - pr_debug("amiga_chip_alloc: allocate %lu bytes\n", size); res = kzalloc(sizeof(struct resource), GFP_KERNEL); if (!res) return NULL; - res->name = name; - if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, - NULL, NULL) < 0) { + res->name = name; + p = amiga_chip_alloc_res(size, res); + if (!p) { kfree(res); return NULL; } - chipavail -= size; - pr_debug("amiga_chip_alloc: returning %pR\n", res); - return (void *)ZTWO_VADDR(res->start); + + return p; } EXPORT_SYMBOL(amiga_chip_alloc); @@ -72,23 +68,22 @@ EXPORT_SYMBOL(amiga_chip_alloc); * those drivers must not free that Chip RAM afterwards. */ -void * __init amiga_chip_alloc_res(unsigned long size, struct resource *res) +void *amiga_chip_alloc_res(unsigned long size, struct resource *res) { - unsigned long start; + int error; /* round up */ size = PAGE_ALIGN(size); - /* dmesg into chipmem prefers memory at the safe end */ - start = CHIP_PHYSADDR + chipavail - size; pr_debug("amiga_chip_alloc_res: allocate %lu bytes\n", size); - if (allocate_resource(&chipram_res, res, size, start, UINT_MAX, - PAGE_SIZE, NULL, NULL) < 0) { - pr_err("amiga_chip_alloc_res: first alloc failed!\n"); - if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, - PAGE_SIZE, NULL, NULL) < 0) - return NULL; + error = allocate_resource(&chipram_res, res, size, 0, UINT_MAX, + PAGE_SIZE, NULL, NULL); + if (error < 0) { + pr_err("amiga_chip_alloc_res: allocate_resource() failed %d!\n", + error); + return NULL; } + chipavail -= size; pr_debug("amiga_chip_alloc_res: returning %pR\n", res); return (void *)ZTWO_VADDR(res->start); -- cgit v0.10.2 From cab49bc95d848a85d7108f896f6d21283f25f54c Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 24 Apr 2011 23:40:51 +0200 Subject: m68k/amiga: Chip RAM - Change chipavail to an atomic_t While the core resource handling code is safe, our global counter must still be protected against concurrent modifications. Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index e5a8dbc..c3fe451 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -25,7 +26,7 @@ EXPORT_SYMBOL(amiga_chip_size); static struct resource chipram_res = { .name = "Chip RAM", .start = CHIP_PHYSADDR }; -static unsigned long chipavail; +static atomic_t chipavail; void __init amiga_chip_init(void) @@ -36,7 +37,7 @@ void __init amiga_chip_init(void) chipram_res.end = amiga_chip_size-1; request_resource(&iomem_resource, &chipram_res); - chipavail = amiga_chip_size; + atomic_set(&chipavail, amiga_chip_size); } @@ -84,7 +85,7 @@ void *amiga_chip_alloc_res(unsigned long size, struct resource *res) return NULL; } - chipavail -= size; + atomic_sub(size, &chipavail); pr_debug("amiga_chip_alloc_res: returning %pR\n", res); return (void *)ZTWO_VADDR(res->start); } @@ -101,7 +102,7 @@ void amiga_chip_free(void *ptr) *p = res->sibling; size = res->end-start; pr_debug("amiga_chip_free: free %lu bytes at %p\n", size, ptr); - chipavail += size; + atomic_add(size, &chipavail); kfree(res); return; } @@ -113,8 +114,10 @@ EXPORT_SYMBOL(amiga_chip_free); unsigned long amiga_chip_avail(void) { - pr_debug("amiga_chip_avail : %lu bytes\n", chipavail); - return chipavail; + unsigned long n = atomic_read(&chipavail); + + pr_debug("amiga_chip_avail : %lu bytes\n", n); + return n; } EXPORT_SYMBOL(amiga_chip_avail); -- cgit v0.10.2 From cb4f9988f86746fff3183d31381deb2b2a421a3a Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 27 Apr 2011 10:28:19 +0200 Subject: m68k/amiga: Chip RAM - Use resource_size() to fix off-by-one error Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index c3fe451..cfd3b7a 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -100,7 +100,7 @@ void amiga_chip_free(void *ptr) if (res->start != start) continue; *p = res->sibling; - size = res->end-start; + size = resource_size(res); pr_debug("amiga_chip_free: free %lu bytes at %p\n", size, ptr); atomic_add(size, &chipavail); kfree(res); -- cgit v0.10.2 From 1dad6c7bd7dd158ef874f7382615cedc21a1f48d Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 22 May 2011 11:09:02 +0200 Subject: m68k/amiga: Chip RAM - Offset resource end by CHIP_PHYSADDR Technically, the end of Chip RAM should be offset by CHIP_PHYSADDR (which is zero). Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index cfd3b7a..4790f77 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -34,7 +34,7 @@ void __init amiga_chip_init(void) if (!AMIGAHW_PRESENT(CHIP_RAM)) return; - chipram_res.end = amiga_chip_size-1; + chipram_res.end = CHIP_PHYSADDR + amiga_chip_size - 1; request_resource(&iomem_resource, &chipram_res); atomic_set(&chipavail, amiga_chip_size); -- cgit v0.10.2 From 88efd0bbc0fe403a9948e6f94cc48b9f15ee4861 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sat, 7 May 2011 15:08:36 +0200 Subject: sparc: _sparc_find_resource() should check for exact matches The address that's passed to _sparc_find_resource() should always be the start address of a resource: - iounmap() passes a page-aligned virtual address, while the original address was created by adding the in-page offset to the resource's start address, - sbus_free_coherent() and pci32_free_coherent() should be passed an address obtained from sbus_alloc_coherent() resp. pci32_alloc_coherent(), which is always a resource's start address. Hence replace the range check by a check for an exact match. Signed-off-by: Geert Uytterhoeven Acked-by: David S. Miller diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c index 1c9c80a..b5e83be 100644 --- a/arch/sparc/kernel/ioport.c +++ b/arch/sparc/kernel/ioport.c @@ -723,12 +723,12 @@ static const struct file_operations sparc_io_proc_fops = { * This probably warrants some sort of hashing. */ static struct resource *_sparc_find_resource(struct resource *root, - unsigned long hit) + unsigned long start) { struct resource *tmp; for (tmp = root->child; tmp != 0; tmp = tmp->sibling) { - if (tmp->start <= hit && tmp->end >= hit) + if (tmp->start == start) return tmp; } return NULL; -- cgit v0.10.2 From 1c388919d89ca35741e9c4d3255adf87f76f0c06 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sat, 7 May 2011 20:53:16 +0200 Subject: resources: Add lookup_resource() Add a function to find an existing resource by a resource start address. This allows to implement simple allocators (with a malloc/free-alike API) on top of the resource system. Signed-off-by: Geert Uytterhoeven diff --git a/include/linux/ioport.h b/include/linux/ioport.h index e9bb22c..63eb429 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -132,6 +132,7 @@ extern int allocate_resource(struct resource *root, struct resource *new, resource_size_t, resource_size_t), void *alignf_data); +struct resource *lookup_resource(struct resource *root, resource_size_t start); int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size); resource_size_t resource_alignment(struct resource *res); diff --git a/kernel/resource.c b/kernel/resource.c index 3ff4017..3b3cedc 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -553,6 +553,27 @@ int allocate_resource(struct resource *root, struct resource *new, EXPORT_SYMBOL(allocate_resource); +/** + * lookup_resource - find an existing resource by a resource start address + * @root: root resource descriptor + * @start: resource start address + * + * Returns a pointer to the resource if found, NULL otherwise + */ +struct resource *lookup_resource(struct resource *root, resource_size_t start) +{ + struct resource *res; + + read_lock(&resource_lock); + for (res = root->child; res; res = res->sibling) { + if (res->start == start) + break; + } + read_unlock(&resource_lock); + + return res; +} + /* * Insert a resource into the resource tree. If successful, return NULL, * otherwise return the conflicting resource (compare to __request_resource()) -- cgit v0.10.2 From b7785e954348465e1926d9c10ff3e49c207d4ec6 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sat, 7 May 2011 20:56:00 +0200 Subject: m68k/amiga: Chip RAM - Use lookup_resource() Replace a custom implementation (which doesn't lock the resource tree) by a call to lookup_resource() Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c index 4790f77..99449fb 100644 --- a/arch/m68k/amiga/chipram.c +++ b/arch/m68k/amiga/chipram.c @@ -93,21 +93,21 @@ void *amiga_chip_alloc_res(unsigned long size, struct resource *res) void amiga_chip_free(void *ptr) { unsigned long start = ZTWO_PADDR(ptr); - struct resource **p, *res; + struct resource *res; unsigned long size; - for (p = &chipram_res.child; (res = *p); p = &res->sibling) { - if (res->start != start) - continue; - *p = res->sibling; - size = resource_size(res); - pr_debug("amiga_chip_free: free %lu bytes at %p\n", size, ptr); - atomic_add(size, &chipavail); - kfree(res); + res = lookup_resource(&chipram_res, start); + if (!res) { + pr_err("amiga_chip_free: trying to free nonexistent region at " + "%p\n", ptr); return; } - pr_err("amiga_chip_free: trying to free nonexistent region at %p\n", - ptr); + + size = resource_size(res); + pr_debug("amiga_chip_free: free %lu bytes at %p\n", size, ptr); + atomic_add(size, &chipavail); + release_resource(res); + kfree(res); } EXPORT_SYMBOL(amiga_chip_free); -- cgit v0.10.2 From 217bbd81885587b462311fab1b04172926c59f1e Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Mon, 1 Nov 2010 19:54:00 +0100 Subject: m68k/atari: Reserve some ST-RAM early on for device buffer use Based on an original patch from Michael Schmitz: Because mem_init() is now called before device init, devices that rely on ST-RAM may find all ST-RAM already allocated to other users by the time device init happens. In particular, a large initrd RAM disk may use up enough of ST-RAM to cause atari_stram_alloc() to resort to __get_dma_pages() allocation. In the current state of Atari memory management, all of RAM is marked DMA capable, so __get_dma_pages() may well return RAM that is not in actual fact DMA capable. Using this for frame buffer or SCSI DMA buffer causes subtle failure. The ST-RAM allocator has been changed to allocate memory from a pool of reserved ST-RAM of configurable size, set aside on ST-RAM init (i.e. before mem_init()). As long as this pool is not exhausted, allocation of real ST-RAM can be guaranteed. Other changes: - Replace the custom allocator in the ST-RAM pool by the existing allocator in the resource subsystem, - Remove mem_init_done and its hook, as memory init is now done before device init, - Remove /proc/stram, as ST-RAM usage now shows up under /proc/iomem, e.g. 005f2000-006f1fff : ST-RAM Pool 005f2000-0063dfff : atafb 0063e000-00641fff : ataflop 00642000-00642fff : SCSI Signed-off-by: Michael Schmitz [Andreas Schwab : Use memparse()] [Geert: Use the resource subsystem instead of a custom allocator] Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/Kconfig.mmu b/arch/m68k/Kconfig.mmu index 16539b1..13e20bb 100644 --- a/arch/m68k/Kconfig.mmu +++ b/arch/m68k/Kconfig.mmu @@ -372,12 +372,6 @@ config AMIGA_PCMCIA Include support in the kernel for pcmcia on Amiga 1200 and Amiga 600. If you intend to use pcmcia cards say Y; otherwise say N. -config STRAM_PROC - bool "ST-RAM statistics in /proc" - depends on ATARI - help - Say Y here to report ST-RAM usage statistics in /proc/stram. - config HEARTBEAT bool "Use power LED as a heartbeat" if AMIGA || APOLLO || ATARI || MAC ||Q40 default y if !AMIGA && !APOLLO && !ATARI && !MAC && !Q40 && HP300 diff --git a/arch/m68k/atari/stram.c b/arch/m68k/atari/stram.c index 6ec3b7f..0810c8d 100644 --- a/arch/m68k/atari/stram.c +++ b/arch/m68k/atari/stram.c @@ -1,5 +1,5 @@ /* - * arch/m68k/atari/stram.c: Functions for ST-RAM allocations + * Functions for ST-RAM allocations * * Copyright 1994-97 Roman Hodek * @@ -30,91 +30,35 @@ #include #include -#undef DEBUG - -#ifdef DEBUG -#define DPRINTK(fmt,args...) printk( fmt, ##args ) -#else -#define DPRINTK(fmt,args...) -#endif - -#if defined(CONFIG_PROC_FS) && defined(CONFIG_STRAM_PROC) -/* abbrev for the && above... */ -#define DO_PROC -#include -#include -#endif /* - * ++roman: - * - * New version of ST-Ram buffer allocation. Instead of using the - * 1 MB - 4 KB that remain when the ST-Ram chunk starts at $1000 - * (1 MB granularity!), such buffers are reserved like this: - * - * - If the kernel resides in ST-Ram anyway, we can take the buffer - * from behind the current kernel data space the normal way - * (incrementing start_mem). - * - * - If the kernel is in TT-Ram, stram_init() initializes start and - * end of the available region. Buffers are allocated from there - * and mem_init() later marks the such used pages as reserved. - * Since each TT-Ram chunk is at least 4 MB in size, I hope there - * won't be an overrun of the ST-Ram region by normal kernel data - * space. - * - * For that, ST-Ram may only be allocated while kernel initialization - * is going on, or exactly: before mem_init() is called. There is also - * no provision now for freeing ST-Ram buffers. It seems that isn't - * really needed. - * + * The ST-RAM allocator allocates memory from a pool of reserved ST-RAM of + * configurable size, set aside on ST-RAM init. + * As long as this pool is not exhausted, allocation of real ST-RAM can be + * guaranteed. */ -/* Start and end (virtual) of ST-RAM */ -static void *stram_start, *stram_end; - -/* set after memory_init() executed and allocations via start_mem aren't - * possible anymore */ -static int mem_init_done; - /* set if kernel is in ST-RAM */ static int kernel_in_stram; -typedef struct stram_block { - struct stram_block *next; - void *start; - unsigned long size; - unsigned flags; - const char *owner; -} BLOCK; - -/* values for flags field */ -#define BLOCK_FREE 0x01 /* free structure in the BLOCKs pool */ -#define BLOCK_KMALLOCED 0x02 /* structure allocated by kmalloc() */ -#define BLOCK_GFP 0x08 /* block allocated with __get_dma_pages() */ +static struct resource stram_pool = { + .name = "ST-RAM Pool" +}; -/* list of allocated blocks */ -static BLOCK *alloc_list; +static unsigned long pool_size = 1024*1024; -/* We can't always use kmalloc() to allocate BLOCK structures, since - * stram_alloc() can be called rather early. So we need some pool of - * statically allocated structures. 20 of them is more than enough, so in most - * cases we never should need to call kmalloc(). */ -#define N_STATIC_BLOCKS 20 -static BLOCK static_blocks[N_STATIC_BLOCKS]; -/***************************** Prototypes *****************************/ +static int __init atari_stram_setup(char *arg) +{ + if (!MACH_IS_ATARI) + return 0; -static BLOCK *add_region( void *addr, unsigned long size ); -static BLOCK *find_region( void *addr ); -static int remove_region( BLOCK *block ); + pool_size = memparse(arg, NULL); + return 0; +} -/************************* End of Prototypes **************************/ +early_param("stram_pool", atari_stram_setup); - -/* ------------------------------------------------------------------------ */ -/* Public Interface */ -/* ------------------------------------------------------------------------ */ /* * This init function is called very early by atari/config.c @@ -123,25 +67,23 @@ static int remove_region( BLOCK *block ); void __init atari_stram_init(void) { int i; + void *stram_start; - /* initialize static blocks */ - for( i = 0; i < N_STATIC_BLOCKS; ++i ) - static_blocks[i].flags = BLOCK_FREE; - - /* determine whether kernel code resides in ST-RAM (then ST-RAM is the - * first memory block at virtual 0x0) */ + /* + * determine whether kernel code resides in ST-RAM + * (then ST-RAM is the first memory block at virtual 0x0) + */ stram_start = phys_to_virt(0); kernel_in_stram = (stram_start == 0); - for( i = 0; i < m68k_num_memory; ++i ) { + for (i = 0; i < m68k_num_memory; ++i) { if (m68k_memory[i].addr == 0) { - /* skip first 2kB or page (supervisor-only!) */ - stram_end = stram_start + m68k_memory[i].size; return; } } + /* Should never come here! (There is always ST-Ram!) */ - panic( "atari_stram_init: no ST-RAM found!" ); + panic("atari_stram_init: no ST-RAM found!"); } @@ -151,226 +93,68 @@ void __init atari_stram_init(void) */ void __init atari_stram_reserve_pages(void *start_mem) { - /* always reserve first page of ST-RAM, the first 2 kB are - * supervisor-only! */ + /* + * always reserve first page of ST-RAM, the first 2 KiB are + * supervisor-only! + */ if (!kernel_in_stram) reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT); -} + stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size); + stram_pool.end = stram_pool.start + pool_size - 1; + request_resource(&iomem_resource, &stram_pool); -void atari_stram_mem_init_hook (void) -{ - mem_init_done = 1; + pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n", + pool_size, &stram_pool); } -/* - * This is main public interface: somehow allocate a ST-RAM block - * - * - If we're before mem_init(), we have to make a static allocation. The - * region is taken in the kernel data area (if the kernel is in ST-RAM) or - * from the start of ST-RAM (if the kernel is in TT-RAM) and added to the - * rsvd_stram_* region. The ST-RAM is somewhere in the middle of kernel - * address space in the latter case. - * - * - If mem_init() already has been called, try with __get_dma_pages(). - * This has the disadvantage that it's very hard to get more than 1 page, - * and it is likely to fail :-( - * - */ -void *atari_stram_alloc(long size, const char *owner) +void *atari_stram_alloc(unsigned long size, const char *owner) { - void *addr = NULL; - BLOCK *block; - int flags; - - DPRINTK("atari_stram_alloc(size=%08lx,owner=%s)\n", size, owner); - - if (!mem_init_done) - return alloc_bootmem_low(size); - else { - /* After mem_init(): can only resort to __get_dma_pages() */ - addr = (void *)__get_dma_pages(GFP_KERNEL, get_order(size)); - flags = BLOCK_GFP; - DPRINTK( "atari_stram_alloc: after mem_init, " - "get_pages=%p\n", addr ); + struct resource *res; + int error; + + pr_debug("atari_stram_alloc: allocate %lu bytes\n", size); + + /* round up */ + size = PAGE_ALIGN(size); + + res = kzalloc(sizeof(struct resource), GFP_KERNEL); + if (!res) + return NULL; + + res->name = owner; + error = allocate_resource(&stram_pool, res, size, 0, UINT_MAX, + PAGE_SIZE, NULL, NULL); + if (error < 0) { + pr_err("atari_stram_alloc: allocate_resource() failed %d!\n", + error); + kfree(res); + return NULL; } - if (addr) { - if (!(block = add_region( addr, size ))) { - /* out of memory for BLOCK structure :-( */ - DPRINTK( "atari_stram_alloc: out of mem for BLOCK -- " - "freeing again\n" ); - free_pages((unsigned long)addr, get_order(size)); - return( NULL ); - } - block->owner = owner; - block->flags |= flags; - } - return( addr ); + pr_debug("atari_stram_alloc: returning %pR\n", res); + return (void *)res->start; } EXPORT_SYMBOL(atari_stram_alloc); -void atari_stram_free( void *addr ) +void atari_stram_free(void *addr) { - BLOCK *block; - - DPRINTK( "atari_stram_free(addr=%p)\n", addr ); + unsigned long start = (unsigned long)addr; + struct resource *res; + unsigned long size; - if (!(block = find_region( addr ))) { - printk( KERN_ERR "Attempt to free non-allocated ST-RAM block at %p " - "from %p\n", addr, __builtin_return_address(0) ); + res = lookup_resource(&stram_pool, start); + if (!res) { + pr_err("atari_stram_free: trying to free nonexistent region " + "at %p\n", addr); return; } - DPRINTK( "atari_stram_free: found block (%p): size=%08lx, owner=%s, " - "flags=%02x\n", block, block->size, block->owner, block->flags ); - - if (!(block->flags & BLOCK_GFP)) - goto fail; - DPRINTK("atari_stram_free: is kmalloced, order_size=%d\n", - get_order(block->size)); - free_pages((unsigned long)addr, get_order(block->size)); - remove_region( block ); - return; - - fail: - printk( KERN_ERR "atari_stram_free: cannot free block at %p " - "(called from %p)\n", addr, __builtin_return_address(0) ); + size = resource_size(res); + pr_debug("atari_stram_free: free %lu bytes at %p\n", size, addr); + release_resource(res); + kfree(res); } EXPORT_SYMBOL(atari_stram_free); - - -/* ------------------------------------------------------------------------ */ -/* Region Management */ -/* ------------------------------------------------------------------------ */ - - -/* insert a region into the alloced list (sorted) */ -static BLOCK *add_region( void *addr, unsigned long size ) -{ - BLOCK **p, *n = NULL; - int i; - - for( i = 0; i < N_STATIC_BLOCKS; ++i ) { - if (static_blocks[i].flags & BLOCK_FREE) { - n = &static_blocks[i]; - n->flags = 0; - break; - } - } - if (!n && mem_init_done) { - /* if statics block pool exhausted and we can call kmalloc() already - * (after mem_init()), try that */ - n = kmalloc( sizeof(BLOCK), GFP_KERNEL ); - if (n) - n->flags = BLOCK_KMALLOCED; - } - if (!n) { - printk( KERN_ERR "Out of memory for ST-RAM descriptor blocks\n" ); - return( NULL ); - } - n->start = addr; - n->size = size; - - for( p = &alloc_list; *p; p = &((*p)->next) ) - if ((*p)->start > addr) break; - n->next = *p; - *p = n; - - return( n ); -} - - -/* find a region (by start addr) in the alloced list */ -static BLOCK *find_region( void *addr ) -{ - BLOCK *p; - - for( p = alloc_list; p; p = p->next ) { - if (p->start == addr) - return( p ); - if (p->start > addr) - break; - } - return( NULL ); -} - - -/* remove a block from the alloced list */ -static int remove_region( BLOCK *block ) -{ - BLOCK **p; - - for( p = &alloc_list; *p; p = &((*p)->next) ) - if (*p == block) break; - if (!*p) - return( 0 ); - - *p = block->next; - if (block->flags & BLOCK_KMALLOCED) - kfree( block ); - else - block->flags |= BLOCK_FREE; - return( 1 ); -} - - - -/* ------------------------------------------------------------------------ */ -/* /proc statistics file stuff */ -/* ------------------------------------------------------------------------ */ - -#ifdef DO_PROC - -#define PRINT_PROC(fmt,args...) seq_printf( m, fmt, ##args ) - -static int stram_proc_show(struct seq_file *m, void *v) -{ - BLOCK *p; - - PRINT_PROC("Total ST-RAM: %8u kB\n", - (stram_end - stram_start) >> 10); - PRINT_PROC( "Allocated regions:\n" ); - for( p = alloc_list; p; p = p->next ) { - PRINT_PROC("0x%08lx-0x%08lx: %s (", - virt_to_phys(p->start), - virt_to_phys(p->start+p->size-1), - p->owner); - if (p->flags & BLOCK_GFP) - PRINT_PROC( "page-alloced)\n" ); - else - PRINT_PROC( "??)\n" ); - } - - return 0; -} - -static int stram_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, stram_proc_show, NULL); -} - -static const struct file_operations stram_proc_fops = { - .open = stram_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int __init proc_stram_init(void) -{ - proc_create("stram", 0, NULL, &stram_proc_fops); - return 0; -} -module_init(proc_stram_init); -#endif - - -/* - * Local variables: - * c-indent-level: 4 - * tab-width: 4 - * End: - */ diff --git a/arch/m68k/include/asm/atari_stram.h b/arch/m68k/include/asm/atari_stram.h index 7546d13..62e2759 100644 --- a/arch/m68k/include/asm/atari_stram.h +++ b/arch/m68k/include/asm/atari_stram.h @@ -6,12 +6,11 @@ */ /* public interface */ -void *atari_stram_alloc(long size, const char *owner); +void *atari_stram_alloc(unsigned long size, const char *owner); void atari_stram_free(void *); /* functions called internally by other parts of the kernel */ void atari_stram_init(void); void atari_stram_reserve_pages(void *start_mem); -void atari_stram_mem_init_hook (void); #endif /*_M68K_ATARI_STRAM_H */ diff --git a/arch/m68k/mm/init_mm.c b/arch/m68k/mm/init_mm.c index 9113c2f..bbe5254 100644 --- a/arch/m68k/mm/init_mm.c +++ b/arch/m68k/mm/init_mm.c @@ -83,11 +83,6 @@ void __init mem_init(void) int initpages = 0; int i; -#ifdef CONFIG_ATARI - if (MACH_IS_ATARI) - atari_stram_mem_init_hook(); -#endif - /* this will put all memory onto the freelists */ totalram_pages = num_physpages = 0; for_each_online_pgdat(pgdat) { -- cgit v0.10.2 From a0e997c20a2fbe25b0f97fb7521cdbda341c7f0a Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sat, 7 May 2011 20:58:02 +0200 Subject: sparc: iounmap() and *_free_coherent() - Use lookup_resource() Replace a custom implementation (which doesn't lock the resource tree) by a call to lookup_resource() Signed-off-by: Geert Uytterhoeven Acked-by: David S. Miller diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c index b5e83be..92700c1 100644 --- a/arch/sparc/kernel/ioport.c +++ b/arch/sparc/kernel/ioport.c @@ -65,9 +65,6 @@ static inline void dma_make_coherent(unsigned long pa, unsigned long len) } #endif -static struct resource *_sparc_find_resource(struct resource *r, - unsigned long); - static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz); static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys, unsigned long size, char *name); @@ -143,7 +140,11 @@ void iounmap(volatile void __iomem *virtual) unsigned long vaddr = (unsigned long) virtual & PAGE_MASK; struct resource *res; - if ((res = _sparc_find_resource(&sparc_iomap, vaddr)) == NULL) { + /* + * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case. + * This probably warrants some sort of hashing. + */ + if ((res = lookup_resource(&sparc_iomap, vaddr)) == NULL) { printk("free_io/iounmap: cannot free %lx\n", vaddr); return; } @@ -319,7 +320,7 @@ static void sbus_free_coherent(struct device *dev, size_t n, void *p, struct resource *res; struct page *pgv; - if ((res = _sparc_find_resource(&_sparc_dvma, + if ((res = lookup_resource(&_sparc_dvma, (unsigned long)p)) == NULL) { printk("sbus_free_consistent: cannot free %p\n", p); return; @@ -492,7 +493,7 @@ static void pci32_free_coherent(struct device *dev, size_t n, void *p, { struct resource *res; - if ((res = _sparc_find_resource(&_sparc_dvma, + if ((res = lookup_resource(&_sparc_dvma, (unsigned long)p)) == NULL) { printk("pci_free_consistent: cannot free %p\n", p); return; @@ -715,25 +716,6 @@ static const struct file_operations sparc_io_proc_fops = { }; #endif /* CONFIG_PROC_FS */ -/* - * This is a version of find_resource and it belongs to kernel/resource.c. - * Until we have agreement with Linus and Martin, it lingers here. - * - * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case. - * This probably warrants some sort of hashing. - */ -static struct resource *_sparc_find_resource(struct resource *root, - unsigned long start) -{ - struct resource *tmp; - - for (tmp = root->child; tmp != 0; tmp = tmp->sibling) { - if (tmp->start == start) - return tmp; - } - return NULL; -} - static void register_proc_sparc_ioport(void) { #ifdef CONFIG_PROC_FS -- cgit v0.10.2 From 398476195a561271654ecce0fa27330688d326df Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 8 Jun 2011 20:20:58 +0200 Subject: m68k/atari: Prefix GPIO_{IN,OUT} with CODEC_ These defines are way to generic, and cause conflicts: drivers/net/wireless/rtlwifi/rtl8192c/../rtl8192ce/reg.h:369:1: warning: "GPIO_IN" redefined drivers/net/wireless/rtlwifi/rtl8192c/../rtl8192ce/reg.h:370:1: warning: "GPIO_OUT" redefined drivers/net/wireless/rtlwifi/rtl8192se/reg.h:252:1: warning: "GPIO_IN" redefined drivers/net/wireless/rtlwifi/rtl8192se/reg.h:253:1: warning: "GPIO_OUT" redefined Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/include/asm/atarihw.h b/arch/m68k/include/asm/atarihw.h index f51f709..0392b28 100644 --- a/arch/m68k/include/asm/atarihw.h +++ b/arch/m68k/include/asm/atarihw.h @@ -399,8 +399,8 @@ struct CODEC #define CODEC_OVERFLOW_LEFT 2 u_char unused2, unused3, unused4, unused5; u_char gpio_directions; -#define GPIO_IN 0 -#define GPIO_OUT 1 +#define CODEC_GPIO_IN 0 +#define CODEC_GPIO_OUT 1 u_char unused6; u_char gpio_data; }; -- cgit v0.10.2 From b2cb92417d301f46801695243df5061a9bd31dd5 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 8 Jun 2011 20:31:32 +0200 Subject: m68k: Kill warning in setup_arch() when compiling for Sun3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit arch/m68k/kernel/setup_mm.c: In function ‘setup_arch’: arch/m68k/kernel/setup_mm.c:219: warning: unused variable ‘i’ Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c index 334d836..c3b4506 100644 --- a/arch/m68k/kernel/setup_mm.c +++ b/arch/m68k/kernel/setup_mm.c @@ -216,7 +216,9 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record) void __init setup_arch(char **cmdline_p) { +#ifndef CONFIG_SUN3 int i; +#endif /* The bootinfo is located right after the kernel bss */ m68k_parse_bootinfo((const struct bi_record *)_end); -- cgit v0.10.2 From ffe6c42aa3f731f8707e49c39b4b37310ed363e9 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 12 Jun 2011 11:01:21 +0200 Subject: m68k/math-emu: Remove commented out old code It's been unused for ages, and contains bugs (e.g. incorrect shifts in lsl64()). Reported-by: Jonathan Elchison Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/math-emu/multi_arith.h b/arch/m68k/math-emu/multi_arith.h index 4ad0ca9..4b5eb3d 100644 --- a/arch/m68k/math-emu/multi_arith.h +++ b/arch/m68k/math-emu/multi_arith.h @@ -19,246 +19,6 @@ #ifndef MULTI_ARITH_H #define MULTI_ARITH_H -#if 0 /* old code... */ - -/* Unsigned only, because we don't need signs to multiply and divide. */ -typedef unsigned int int128[4]; - -/* Word order */ -enum { - MSW128, - NMSW128, - NLSW128, - LSW128 -}; - -/* big-endian */ -#define LO_WORD(ll) (((unsigned int *) &ll)[1]) -#define HI_WORD(ll) (((unsigned int *) &ll)[0]) - -/* Convenience functions to stuff various integer values into int128s */ - -static inline void zero128(int128 a) -{ - a[LSW128] = a[NLSW128] = a[NMSW128] = a[MSW128] = 0; -} - -/* Human-readable word order in the arguments */ -static inline void set128(unsigned int i3, unsigned int i2, unsigned int i1, - unsigned int i0, int128 a) -{ - a[LSW128] = i0; - a[NLSW128] = i1; - a[NMSW128] = i2; - a[MSW128] = i3; -} - -/* Convenience functions (for testing as well) */ -static inline void int64_to_128(unsigned long long src, int128 dest) -{ - dest[LSW128] = (unsigned int) src; - dest[NLSW128] = src >> 32; - dest[NMSW128] = dest[MSW128] = 0; -} - -static inline void int128_to_64(const int128 src, unsigned long long *dest) -{ - *dest = src[LSW128] | (long long) src[NLSW128] << 32; -} - -static inline void put_i128(const int128 a) -{ - printk("%08x %08x %08x %08x\n", a[MSW128], a[NMSW128], - a[NLSW128], a[LSW128]); -} - -/* Internal shifters: - - Note that these are only good for 0 < count < 32. - */ - -static inline void _lsl128(unsigned int count, int128 a) -{ - a[MSW128] = (a[MSW128] << count) | (a[NMSW128] >> (32 - count)); - a[NMSW128] = (a[NMSW128] << count) | (a[NLSW128] >> (32 - count)); - a[NLSW128] = (a[NLSW128] << count) | (a[LSW128] >> (32 - count)); - a[LSW128] <<= count; -} - -static inline void _lsr128(unsigned int count, int128 a) -{ - a[LSW128] = (a[LSW128] >> count) | (a[NLSW128] << (32 - count)); - a[NLSW128] = (a[NLSW128] >> count) | (a[NMSW128] << (32 - count)); - a[NMSW128] = (a[NMSW128] >> count) | (a[MSW128] << (32 - count)); - a[MSW128] >>= count; -} - -/* Should be faster, one would hope */ - -static inline void lslone128(int128 a) -{ - asm volatile ("lsl.l #1,%0\n" - "roxl.l #1,%1\n" - "roxl.l #1,%2\n" - "roxl.l #1,%3\n" - : - "=d" (a[LSW128]), - "=d"(a[NLSW128]), - "=d"(a[NMSW128]), - "=d"(a[MSW128]) - : - "0"(a[LSW128]), - "1"(a[NLSW128]), - "2"(a[NMSW128]), - "3"(a[MSW128])); -} - -static inline void lsrone128(int128 a) -{ - asm volatile ("lsr.l #1,%0\n" - "roxr.l #1,%1\n" - "roxr.l #1,%2\n" - "roxr.l #1,%3\n" - : - "=d" (a[MSW128]), - "=d"(a[NMSW128]), - "=d"(a[NLSW128]), - "=d"(a[LSW128]) - : - "0"(a[MSW128]), - "1"(a[NMSW128]), - "2"(a[NLSW128]), - "3"(a[LSW128])); -} - -/* Generalized 128-bit shifters: - - These bit-shift to a multiple of 32, then move whole longwords. */ - -static inline void lsl128(unsigned int count, int128 a) -{ - int wordcount, i; - - if (count % 32) - _lsl128(count % 32, a); - - if (0 == (wordcount = count / 32)) - return; - - /* argh, gak, endian-sensitive */ - for (i = 0; i < 4 - wordcount; i++) { - a[i] = a[i + wordcount]; - } - for (i = 3; i >= 4 - wordcount; --i) { - a[i] = 0; - } -} - -static inline void lsr128(unsigned int count, int128 a) -{ - int wordcount, i; - - if (count % 32) - _lsr128(count % 32, a); - - if (0 == (wordcount = count / 32)) - return; - - for (i = 3; i >= wordcount; --i) { - a[i] = a[i - wordcount]; - } - for (i = 0; i < wordcount; i++) { - a[i] = 0; - } -} - -static inline int orl128(int a, int128 b) -{ - b[LSW128] |= a; -} - -static inline int btsthi128(const int128 a) -{ - return a[MSW128] & 0x80000000; -} - -/* test bits (numbered from 0 = LSB) up to and including "top" */ -static inline int bftestlo128(int top, const int128 a) -{ - int r = 0; - - if (top > 31) - r |= a[LSW128]; - if (top > 63) - r |= a[NLSW128]; - if (top > 95) - r |= a[NMSW128]; - - r |= a[3 - (top / 32)] & ((1 << (top % 32 + 1)) - 1); - - return (r != 0); -} - -/* Aargh. We need these because GCC is broken */ -/* FIXME: do them in assembly, for goodness' sake! */ -static inline void mask64(int pos, unsigned long long *mask) -{ - *mask = 0; - - if (pos < 32) { - LO_WORD(*mask) = (1 << pos) - 1; - return; - } - LO_WORD(*mask) = -1; - HI_WORD(*mask) = (1 << (pos - 32)) - 1; -} - -static inline void bset64(int pos, unsigned long long *dest) -{ - /* This conditional will be optimized away. Thanks, GCC! */ - if (pos < 32) - asm volatile ("bset %1,%0":"=m" - (LO_WORD(*dest)):"id"(pos)); - else - asm volatile ("bset %1,%0":"=m" - (HI_WORD(*dest)):"id"(pos - 32)); -} - -static inline int btst64(int pos, unsigned long long dest) -{ - if (pos < 32) - return (0 != (LO_WORD(dest) & (1 << pos))); - else - return (0 != (HI_WORD(dest) & (1 << (pos - 32)))); -} - -static inline void lsl64(int count, unsigned long long *dest) -{ - if (count < 32) { - HI_WORD(*dest) = (HI_WORD(*dest) << count) - | (LO_WORD(*dest) >> count); - LO_WORD(*dest) <<= count; - return; - } - count -= 32; - HI_WORD(*dest) = LO_WORD(*dest) << count; - LO_WORD(*dest) = 0; -} - -static inline void lsr64(int count, unsigned long long *dest) -{ - if (count < 32) { - LO_WORD(*dest) = (LO_WORD(*dest) >> count) - | (HI_WORD(*dest) << (32 - count)); - HI_WORD(*dest) >>= count; - return; - } - count -= 32; - LO_WORD(*dest) = HI_WORD(*dest) >> count; - HI_WORD(*dest) = 0; -} -#endif - static inline void fp_denormalize(struct fp_ext *reg, unsigned int cnt) { reg->exp += cnt; @@ -481,117 +241,6 @@ static inline void fp_dividemant(union fp_mant128 *dest, struct fp_ext *src, } } -#if 0 -static inline unsigned int fp_fls128(union fp_mant128 *src) -{ - unsigned long data; - unsigned int res, off; - - if ((data = src->m32[0])) - off = 0; - else if ((data = src->m32[1])) - off = 32; - else if ((data = src->m32[2])) - off = 64; - else if ((data = src->m32[3])) - off = 96; - else - return 128; - - asm ("bfffo %1{#0,#32},%0" : "=d" (res) : "dm" (data)); - return res + off; -} - -static inline void fp_shiftmant128(union fp_mant128 *src, int shift) -{ - unsigned long sticky; - - switch (shift) { - case 0: - return; - case 1: - asm volatile ("lsl.l #1,%0" - : "=d" (src->m32[3]) : "0" (src->m32[3])); - asm volatile ("roxl.l #1,%0" - : "=d" (src->m32[2]) : "0" (src->m32[2])); - asm volatile ("roxl.l #1,%0" - : "=d" (src->m32[1]) : "0" (src->m32[1])); - asm volatile ("roxl.l #1,%0" - : "=d" (src->m32[0]) : "0" (src->m32[0])); - return; - case 2 ... 31: - src->m32[0] = (src->m32[0] << shift) | (src->m32[1] >> (32 - shift)); - src->m32[1] = (src->m32[1] << shift) | (src->m32[2] >> (32 - shift)); - src->m32[2] = (src->m32[2] << shift) | (src->m32[3] >> (32 - shift)); - src->m32[3] = (src->m32[3] << shift); - return; - case 32 ... 63: - shift -= 32; - src->m32[0] = (src->m32[1] << shift) | (src->m32[2] >> (32 - shift)); - src->m32[1] = (src->m32[2] << shift) | (src->m32[3] >> (32 - shift)); - src->m32[2] = (src->m32[3] << shift); - src->m32[3] = 0; - return; - case 64 ... 95: - shift -= 64; - src->m32[0] = (src->m32[2] << shift) | (src->m32[3] >> (32 - shift)); - src->m32[1] = (src->m32[3] << shift); - src->m32[2] = src->m32[3] = 0; - return; - case 96 ... 127: - shift -= 96; - src->m32[0] = (src->m32[3] << shift); - src->m32[1] = src->m32[2] = src->m32[3] = 0; - return; - case -31 ... -1: - shift = -shift; - sticky = 0; - if (src->m32[3] << (32 - shift)) - sticky = 1; - src->m32[3] = (src->m32[3] >> shift) | (src->m32[2] << (32 - shift)) | sticky; - src->m32[2] = (src->m32[2] >> shift) | (src->m32[1] << (32 - shift)); - src->m32[1] = (src->m32[1] >> shift) | (src->m32[0] << (32 - shift)); - src->m32[0] = (src->m32[0] >> shift); - return; - case -63 ... -32: - shift = -shift - 32; - sticky = 0; - if ((src->m32[2] << (32 - shift)) || src->m32[3]) - sticky = 1; - src->m32[3] = (src->m32[2] >> shift) | (src->m32[1] << (32 - shift)) | sticky; - src->m32[2] = (src->m32[1] >> shift) | (src->m32[0] << (32 - shift)); - src->m32[1] = (src->m32[0] >> shift); - src->m32[0] = 0; - return; - case -95 ... -64: - shift = -shift - 64; - sticky = 0; - if ((src->m32[1] << (32 - shift)) || src->m32[2] || src->m32[3]) - sticky = 1; - src->m32[3] = (src->m32[1] >> shift) | (src->m32[0] << (32 - shift)) | sticky; - src->m32[2] = (src->m32[0] >> shift); - src->m32[1] = src->m32[0] = 0; - return; - case -127 ... -96: - shift = -shift - 96; - sticky = 0; - if ((src->m32[0] << (32 - shift)) || src->m32[1] || src->m32[2] || src->m32[3]) - sticky = 1; - src->m32[3] = (src->m32[0] >> shift) | sticky; - src->m32[2] = src->m32[1] = src->m32[0] = 0; - return; - } - - if (shift < 0 && (src->m32[0] || src->m32[1] || src->m32[2] || src->m32[3])) - src->m32[3] = 1; - else - src->m32[3] = 0; - src->m32[2] = 0; - src->m32[1] = 0; - src->m32[0] = 0; -} -#endif - static inline void fp_putmant128(struct fp_ext *dest, union fp_mant128 *src, int shift) { @@ -637,183 +286,4 @@ static inline void fp_putmant128(struct fp_ext *dest, union fp_mant128 *src, } } -#if 0 /* old code... */ -static inline int fls(unsigned int a) -{ - int r; - - asm volatile ("bfffo %1{#0,#32},%0" - : "=d" (r) : "md" (a)); - return r; -} - -/* fls = "find last set" (cf. ffs(3)) */ -static inline int fls128(const int128 a) -{ - if (a[MSW128]) - return fls(a[MSW128]); - if (a[NMSW128]) - return fls(a[NMSW128]) + 32; - /* XXX: it probably never gets beyond this point in actual - use, but that's indicative of a more general problem in the - algorithm (i.e. as per the actual 68881 implementation, we - really only need at most 67 bits of precision [plus - overflow]) so I'm not going to fix it. */ - if (a[NLSW128]) - return fls(a[NLSW128]) + 64; - if (a[LSW128]) - return fls(a[LSW128]) + 96; - else - return -1; -} - -static inline int zerop128(const int128 a) -{ - return !(a[LSW128] | a[NLSW128] | a[NMSW128] | a[MSW128]); -} - -static inline int nonzerop128(const int128 a) -{ - return (a[LSW128] | a[NLSW128] | a[NMSW128] | a[MSW128]); -} - -/* Addition and subtraction */ -/* Do these in "pure" assembly, because "extended" asm is unmanageable - here */ -static inline void add128(const int128 a, int128 b) -{ - /* rotating carry flags */ - unsigned int carry[2]; - - carry[0] = a[LSW128] > (0xffffffff - b[LSW128]); - b[LSW128] += a[LSW128]; - - carry[1] = a[NLSW128] > (0xffffffff - b[NLSW128] - carry[0]); - b[NLSW128] = a[NLSW128] + b[NLSW128] + carry[0]; - - carry[0] = a[NMSW128] > (0xffffffff - b[NMSW128] - carry[1]); - b[NMSW128] = a[NMSW128] + b[NMSW128] + carry[1]; - - b[MSW128] = a[MSW128] + b[MSW128] + carry[0]; -} - -/* Note: assembler semantics: "b -= a" */ -static inline void sub128(const int128 a, int128 b) -{ - /* rotating borrow flags */ - unsigned int borrow[2]; - - borrow[0] = b[LSW128] < a[LSW128]; - b[LSW128] -= a[LSW128]; - - borrow[1] = b[NLSW128] < a[NLSW128] + borrow[0]; - b[NLSW128] = b[NLSW128] - a[NLSW128] - borrow[0]; - - borrow[0] = b[NMSW128] < a[NMSW128] + borrow[1]; - b[NMSW128] = b[NMSW128] - a[NMSW128] - borrow[1]; - - b[MSW128] = b[MSW128] - a[MSW128] - borrow[0]; -} - -/* Poor man's 64-bit expanding multiply */ -static inline void mul64(unsigned long long a, unsigned long long b, int128 c) -{ - unsigned long long acc; - int128 acc128; - - zero128(acc128); - zero128(c); - - /* first the low words */ - if (LO_WORD(a) && LO_WORD(b)) { - acc = (long long) LO_WORD(a) * LO_WORD(b); - c[NLSW128] = HI_WORD(acc); - c[LSW128] = LO_WORD(acc); - } - /* Next the high words */ - if (HI_WORD(a) && HI_WORD(b)) { - acc = (long long) HI_WORD(a) * HI_WORD(b); - c[MSW128] = HI_WORD(acc); - c[NMSW128] = LO_WORD(acc); - } - /* The middle words */ - if (LO_WORD(a) && HI_WORD(b)) { - acc = (long long) LO_WORD(a) * HI_WORD(b); - acc128[NMSW128] = HI_WORD(acc); - acc128[NLSW128] = LO_WORD(acc); - add128(acc128, c); - } - /* The first and last words */ - if (HI_WORD(a) && LO_WORD(b)) { - acc = (long long) HI_WORD(a) * LO_WORD(b); - acc128[NMSW128] = HI_WORD(acc); - acc128[NLSW128] = LO_WORD(acc); - add128(acc128, c); - } -} - -/* Note: unsigned */ -static inline int cmp128(int128 a, int128 b) -{ - if (a[MSW128] < b[MSW128]) - return -1; - if (a[MSW128] > b[MSW128]) - return 1; - if (a[NMSW128] < b[NMSW128]) - return -1; - if (a[NMSW128] > b[NMSW128]) - return 1; - if (a[NLSW128] < b[NLSW128]) - return -1; - if (a[NLSW128] > b[NLSW128]) - return 1; - - return (signed) a[LSW128] - b[LSW128]; -} - -inline void div128(int128 a, int128 b, int128 c) -{ - int128 mask; - - /* Algorithm: - - Shift the divisor until it's at least as big as the - dividend, keeping track of the position to which we've - shifted it, i.e. the power of 2 which we've multiplied it - by. - - Then, for this power of 2 (the mask), and every one smaller - than it, subtract the mask from the dividend and add it to - the quotient until the dividend is smaller than the raised - divisor. At this point, divide the dividend and the mask - by 2 (i.e. shift one place to the right). Lather, rinse, - and repeat, until there are no more powers of 2 left. */ - - /* FIXME: needless to say, there's room for improvement here too. */ - - /* Shift up */ - /* XXX: since it just has to be "at least as big", we can - probably eliminate this horribly wasteful loop. I will - have to prove this first, though */ - set128(0, 0, 0, 1, mask); - while (cmp128(b, a) < 0 && !btsthi128(b)) { - lslone128(b); - lslone128(mask); - } - - /* Shift down */ - zero128(c); - do { - if (cmp128(a, b) >= 0) { - sub128(b, a); - add128(mask, c); - } - lsrone128(mask); - lsrone128(b); - } while (nonzerop128(mask)); - - /* The remainder is in a... */ -} -#endif - #endif /* MULTI_ARITH_H */ -- cgit v0.10.2 From d3690f8b713f9710e68214ca38fb8b07b587a2a7 Mon Sep 17 00:00:00 2001 From: Greg Dietsche Date: Thu, 16 Jun 2011 11:42:07 -0500 Subject: m68k/math-emu: Remove unnecessary code Remove unnecessary code that matches this coccinelle pattern if (...) return ret; return ret; Signed-off-by: Greg Dietsche Signed-off-by: Geert Uytterhoeven diff --git a/arch/m68k/math-emu/fp_log.c b/arch/m68k/math-emu/fp_log.c index 367ecee..3384a52 100644 --- a/arch/m68k/math-emu/fp_log.c +++ b/arch/m68k/math-emu/fp_log.c @@ -105,9 +105,6 @@ fp_fetoxm1(struct fp_ext *dest, struct fp_ext *src) fp_monadic_check(dest, src); - if (IS_ZERO(dest)) - return dest; - return dest; } -- cgit v0.10.2