2 ** linux/amiga/chipram.c
4 ** Modified 03-May-94 by Geert Uytterhoeven <geert@linux-m68k.org>
5 ** - 64-bit aligned allocations for full AGA compatibility
7 ** Rewritten 15/9/2000 by Geert to use resource management
10 #include <linux/types.h>
11 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/slab.h>
16 #include <linux/string.h>
17 #include <linux/module.h>
19 #include <asm/atomic.h>
21 #include <asm/amigahw.h>
23 unsigned long amiga_chip_size;
24 EXPORT_SYMBOL(amiga_chip_size);
26 static struct resource chipram_res = {
27 .name = "Chip RAM", .start = CHIP_PHYSADDR
29 static atomic_t chipavail;
32 void __init amiga_chip_init(void)
34 if (!AMIGAHW_PRESENT(CHIP_RAM))
37 chipram_res.end = CHIP_PHYSADDR + amiga_chip_size - 1;
38 request_resource(&iomem_resource, &chipram_res);
40 atomic_set(&chipavail, amiga_chip_size);
44 void *amiga_chip_alloc(unsigned long size, const char *name)
49 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
54 p = amiga_chip_alloc_res(size, res);
62 EXPORT_SYMBOL(amiga_chip_alloc);
67 * amiga_chip_alloc_res is meant only for drivers that need to
68 * allocate Chip RAM before kmalloc() is functional. As a consequence,
69 * those drivers must not free that Chip RAM afterwards.
72 void *amiga_chip_alloc_res(unsigned long size, struct resource *res)
77 size = PAGE_ALIGN(size);
79 pr_debug("amiga_chip_alloc_res: allocate %lu bytes\n", size);
80 error = allocate_resource(&chipram_res, res, size, 0, UINT_MAX,
81 PAGE_SIZE, NULL, NULL);
83 pr_err("amiga_chip_alloc_res: allocate_resource() failed %d!\n",
88 atomic_sub(size, &chipavail);
89 pr_debug("amiga_chip_alloc_res: returning %pR\n", res);
90 return (void *)ZTWO_VADDR(res->start);
93 void amiga_chip_free(void *ptr)
95 unsigned long start = ZTWO_PADDR(ptr);
99 res = lookup_resource(&chipram_res, start);
101 pr_err("amiga_chip_free: trying to free nonexistent region at "
106 size = resource_size(res);
107 pr_debug("amiga_chip_free: free %lu bytes at %p\n", size, ptr);
108 atomic_add(size, &chipavail);
109 release_resource(res);
112 EXPORT_SYMBOL(amiga_chip_free);
115 unsigned long amiga_chip_avail(void)
117 unsigned long n = atomic_read(&chipavail);
119 pr_debug("amiga_chip_avail : %lu bytes\n", n);
122 EXPORT_SYMBOL(amiga_chip_avail);