]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/m68k/amiga/chipram.c
Merge branch 'pm-cpufreq'
[mirror_ubuntu-zesty-kernel.git] / arch / m68k / amiga / chipram.c
CommitLineData
1da177e4
LT
1/*
2** linux/amiga/chipram.c
3**
4** Modified 03-May-94 by Geert Uytterhoeven <geert@linux-m68k.org>
5** - 64-bit aligned allocations for full AGA compatibility
6**
7** Rewritten 15/9/2000 by Geert to use resource management
8*/
9
1da177e4
LT
10#include <linux/types.h>
11#include <linux/kernel.h>
27ac792c 12#include <linux/mm.h>
1da177e4
LT
13#include <linux/init.h>
14#include <linux/ioport.h>
15#include <linux/slab.h>
16#include <linux/string.h>
8b169fa2
AB
17#include <linux/module.h>
18
cab49bc9 19#include <asm/atomic.h>
1da177e4
LT
20#include <asm/page.h>
21#include <asm/amigahw.h>
22
23unsigned long amiga_chip_size;
8b169fa2 24EXPORT_SYMBOL(amiga_chip_size);
1da177e4
LT
25
26static struct resource chipram_res = {
5be32463 27 .name = "Chip RAM", .start = CHIP_PHYSADDR
1da177e4 28};
cab49bc9 29static atomic_t chipavail;
1da177e4
LT
30
31
32void __init amiga_chip_init(void)
33{
5be32463
GU
34 if (!AMIGAHW_PRESENT(CHIP_RAM))
35 return;
1da177e4 36
1dad6c7b 37 chipram_res.end = CHIP_PHYSADDR + amiga_chip_size - 1;
5be32463 38 request_resource(&iomem_resource, &chipram_res);
1da177e4 39
cab49bc9 40 atomic_set(&chipavail, amiga_chip_size);
1da177e4
LT
41}
42
43
44void *amiga_chip_alloc(unsigned long size, const char *name)
45{
5be32463 46 struct resource *res;
3a17bfa4 47 void *p;
1da177e4 48
5be32463
GU
49 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
50 if (!res)
51 return NULL;
5be32463 52
3a17bfa4
GU
53 res->name = name;
54 p = amiga_chip_alloc_res(size, res);
55 if (!p) {
5be32463
GU
56 kfree(res);
57 return NULL;
58 }
3a17bfa4
GU
59
60 return p;
1da177e4 61}
8b169fa2 62EXPORT_SYMBOL(amiga_chip_alloc);
1da177e4
LT
63
64
5be32463
GU
65 /*
66 * Warning:
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.
70 */
1da177e4 71
3a17bfa4 72void *amiga_chip_alloc_res(unsigned long size, struct resource *res)
1da177e4 73{
3a17bfa4 74 int error;
1da177e4 75
5be32463
GU
76 /* round up */
77 size = PAGE_ALIGN(size);
1da177e4 78
b4f6f453 79 pr_debug("amiga_chip_alloc_res: allocate %lu bytes\n", size);
3a17bfa4
GU
80 error = allocate_resource(&chipram_res, res, size, 0, UINT_MAX,
81 PAGE_SIZE, NULL, NULL);
82 if (error < 0) {
83 pr_err("amiga_chip_alloc_res: allocate_resource() failed %d!\n",
84 error);
85 return NULL;
5be32463 86 }
3a17bfa4 87
cab49bc9 88 atomic_sub(size, &chipavail);
b4f6f453 89 pr_debug("amiga_chip_alloc_res: returning %pR\n", res);
6112ea08 90 return ZTWO_VADDR(res->start);
1da177e4
LT
91}
92
93void amiga_chip_free(void *ptr)
94{
5be32463 95 unsigned long start = ZTWO_PADDR(ptr);
b7785e95 96 struct resource *res;
5be32463
GU
97 unsigned long size;
98
b7785e95
GU
99 res = lookup_resource(&chipram_res, start);
100 if (!res) {
101 pr_err("amiga_chip_free: trying to free nonexistent region at "
102 "%p\n", ptr);
5be32463
GU
103 return;
104 }
b7785e95
GU
105
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);
110 kfree(res);
1da177e4 111}
8b169fa2 112EXPORT_SYMBOL(amiga_chip_free);
1da177e4
LT
113
114
115unsigned long amiga_chip_avail(void)
116{
cab49bc9
GU
117 unsigned long n = atomic_read(&chipavail);
118
119 pr_debug("amiga_chip_avail : %lu bytes\n", n);
120 return n;
1da177e4 121}
8b169fa2
AB
122EXPORT_SYMBOL(amiga_chip_avail);
123