1
linux/arch/m68k/atari/stram.c
Michael Schmitz 217bbd8188 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 <schmitz@debian.org>
[Andreas Schwab <schwab@linux-m68k.org>: Use memparse()]
[Geert: Use the resource subsystem instead of a custom allocator]
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2011-07-30 21:21:39 +02:00

161 lines
3.6 KiB
C

/*
* Functions for ST-RAM allocations
*
* Copyright 1994-97 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/kdev_t.h>
#include <linux/major.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/pagemap.h>
#include <linux/bootmem.h>
#include <linux/mount.h>
#include <linux/blkdev.h>
#include <linux/module.h>
#include <asm/setup.h>
#include <asm/machdep.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/atarihw.h>
#include <asm/atari_stram.h>
#include <asm/io.h>
/*
* 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.
*/
/* set if kernel is in ST-RAM */
static int kernel_in_stram;
static struct resource stram_pool = {
.name = "ST-RAM Pool"
};
static unsigned long pool_size = 1024*1024;
static int __init atari_stram_setup(char *arg)
{
if (!MACH_IS_ATARI)
return 0;
pool_size = memparse(arg, NULL);
return 0;
}
early_param("stram_pool", atari_stram_setup);
/*
* This init function is called very early by atari/config.c
* It initializes some internal variables needed for stram_alloc()
*/
void __init atari_stram_init(void)
{
int i;
void *stram_start;
/*
* 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) {
if (m68k_memory[i].addr == 0) {
return;
}
}
/* Should never come here! (There is always ST-Ram!) */
panic("atari_stram_init: no ST-RAM found!");
}
/*
* This function is called from setup_arch() to reserve the pages needed for
* ST-RAM management.
*/
void __init atari_stram_reserve_pages(void *start_mem)
{
/*
* 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);
pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
pool_size, &stram_pool);
}
void *atari_stram_alloc(unsigned long size, const char *owner)
{
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;
}
pr_debug("atari_stram_alloc: returning %pR\n", res);
return (void *)res->start;
}
EXPORT_SYMBOL(atari_stram_alloc);
void atari_stram_free(void *addr)
{
unsigned long start = (unsigned long)addr;
struct resource *res;
unsigned long size;
res = lookup_resource(&stram_pool, start);
if (!res) {
pr_err("atari_stram_free: trying to free nonexistent region "
"at %p\n", addr);
return;
}
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);