aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/amiga/chipram.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/m68k/amiga/chipram.c')
-rw-r--r--arch/m68k/amiga/chipram.c118
1 files changed, 61 insertions, 57 deletions
diff --git a/arch/m68k/amiga/chipram.c b/arch/m68k/amiga/chipram.c
index dd0447db1c90..e757ffffbc8a 100644
--- a/arch/m68k/amiga/chipram.c
+++ b/arch/m68k/amiga/chipram.c
@@ -23,101 +23,105 @@ unsigned long amiga_chip_size;
23EXPORT_SYMBOL(amiga_chip_size); 23EXPORT_SYMBOL(amiga_chip_size);
24 24
25static struct resource chipram_res = { 25static struct resource chipram_res = {
26 .name = "Chip RAM", .start = CHIP_PHYSADDR 26 .name = "Chip RAM", .start = CHIP_PHYSADDR
27}; 27};
28static unsigned long chipavail; 28static unsigned long chipavail;
29 29
30 30
31void __init amiga_chip_init(void) 31void __init amiga_chip_init(void)
32{ 32{
33 if (!AMIGAHW_PRESENT(CHIP_RAM)) 33 if (!AMIGAHW_PRESENT(CHIP_RAM))
34 return; 34 return;
35 35
36 chipram_res.end = amiga_chip_size-1; 36 chipram_res.end = amiga_chip_size-1;
37 request_resource(&iomem_resource, &chipram_res); 37 request_resource(&iomem_resource, &chipram_res);
38 38
39 chipavail = amiga_chip_size; 39 chipavail = amiga_chip_size;
40} 40}
41 41
42 42
43void *amiga_chip_alloc(unsigned long size, const char *name) 43void *amiga_chip_alloc(unsigned long size, const char *name)
44{ 44{
45 struct resource *res; 45 struct resource *res;
46 46
47 /* round up */ 47 /* round up */
48 size = PAGE_ALIGN(size); 48 size = PAGE_ALIGN(size);
49 49
50#ifdef DEBUG 50#ifdef DEBUG
51 printk("amiga_chip_alloc: allocate %ld bytes\n", size); 51 printk("amiga_chip_alloc: allocate %ld bytes\n", size);
52#endif 52#endif
53 res = kzalloc(sizeof(struct resource), GFP_KERNEL); 53 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
54 if (!res) 54 if (!res)
55 return NULL; 55 return NULL;
56 res->name = name; 56 res->name = name;
57 57
58 if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) { 58 if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE,
59 kfree(res); 59 NULL, NULL) < 0) {
60 return NULL; 60 kfree(res);
61 } 61 return NULL;
62 chipavail -= size; 62 }
63 chipavail -= size;
63#ifdef DEBUG 64#ifdef DEBUG
64 printk("amiga_chip_alloc: returning %lx\n", res->start); 65 printk("amiga_chip_alloc: returning %lx\n", res->start);
65#endif 66#endif
66 return (void *)ZTWO_VADDR(res->start); 67 return (void *)ZTWO_VADDR(res->start);
67} 68}
68EXPORT_SYMBOL(amiga_chip_alloc); 69EXPORT_SYMBOL(amiga_chip_alloc);
69 70
70 71
71 /* 72 /*
72 * Warning: 73 * Warning:
73 * amiga_chip_alloc_res is meant only for drivers that need to allocate 74 * amiga_chip_alloc_res is meant only for drivers that need to
74 * Chip RAM before kmalloc() is functional. As a consequence, those 75 * allocate Chip RAM before kmalloc() is functional. As a consequence,
75 * drivers must not free that Chip RAM afterwards. 76 * those drivers must not free that Chip RAM afterwards.
76 */ 77 */
77 78
78void * __init amiga_chip_alloc_res(unsigned long size, struct resource *res) 79void * __init amiga_chip_alloc_res(unsigned long size, struct resource *res)
79{ 80{
80 unsigned long start; 81 unsigned long start;
81 82
82 /* round up */ 83 /* round up */
83 size = PAGE_ALIGN(size); 84 size = PAGE_ALIGN(size);
84 /* dmesg into chipmem prefers memory at the safe end */ 85 /* dmesg into chipmem prefers memory at the safe end */
85 start = CHIP_PHYSADDR + chipavail - size; 86 start = CHIP_PHYSADDR + chipavail - size;
86 87
87#ifdef DEBUG 88#ifdef DEBUG
88 printk("amiga_chip_alloc_res: allocate %ld bytes\n", size); 89 printk("amiga_chip_alloc_res: allocate %ld bytes\n", size);
89#endif 90#endif
90 if (allocate_resource(&chipram_res, res, size, start, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) { 91 if (allocate_resource(&chipram_res, res, size, start, UINT_MAX,
91 printk("amiga_chip_alloc_res: first alloc failed!\n"); 92 PAGE_SIZE, NULL, NULL) < 0) {
92 if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX, PAGE_SIZE, NULL, NULL) < 0) 93 printk("amiga_chip_alloc_res: first alloc failed!\n");
93 return NULL; 94 if (allocate_resource(&chipram_res, res, size, 0, UINT_MAX,
94 } 95 PAGE_SIZE, NULL, NULL) < 0)
95 chipavail -= size; 96 return NULL;
97 }
98 chipavail -= size;
96#ifdef DEBUG 99#ifdef DEBUG
97 printk("amiga_chip_alloc_res: returning %lx\n", res->start); 100 printk("amiga_chip_alloc_res: returning %lx\n", res->start);
98#endif 101#endif
99 return (void *)ZTWO_VADDR(res->start); 102 return (void *)ZTWO_VADDR(res->start);
100} 103}
101 104
102void amiga_chip_free(void *ptr) 105void amiga_chip_free(void *ptr)
103{ 106{
104 unsigned long start = ZTWO_PADDR(ptr); 107 unsigned long start = ZTWO_PADDR(ptr);
105 struct resource **p, *res; 108 struct resource **p, *res;
106 unsigned long size; 109 unsigned long size;
107 110
108 for (p = &chipram_res.child; (res = *p); p = &res->sibling) { 111 for (p = &chipram_res.child; (res = *p); p = &res->sibling) {
109 if (res->start != start) 112 if (res->start != start)
110 continue; 113 continue;
111 *p = res->sibling; 114 *p = res->sibling;
112 size = res->end-start; 115 size = res->end-start;
113#ifdef DEBUG 116#ifdef DEBUG
114 printk("amiga_chip_free: free %ld bytes at %p\n", size, ptr); 117 printk("amiga_chip_free: free %ld bytes at %p\n", size, ptr);
115#endif 118#endif
116 chipavail += size; 119 chipavail += size;
117 kfree(res); 120 kfree(res);
118 return; 121 return;
119 } 122 }
120 printk("amiga_chip_free: trying to free nonexistent region at %p\n", ptr); 123 printk("amiga_chip_free: trying to free nonexistent region at %p\n",
124 ptr);
121} 125}
122EXPORT_SYMBOL(amiga_chip_free); 126EXPORT_SYMBOL(amiga_chip_free);
123 127