]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Zorro Bus Services |
3 | * | |
4 | * Copyright (C) 1995-2003 Geert Uytterhoeven | |
5 | * | |
6 | * This file is subject to the terms and conditions of the GNU General Public | |
7 | * License. See the file COPYING in the main directory of this archive | |
8 | * for more details. | |
9 | */ | |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/types.h> | |
13 | #include <linux/kernel.h> | |
14 | #include <linux/init.h> | |
15 | #include <linux/zorro.h> | |
16 | #include <linux/bitops.h> | |
4e57b681 | 17 | #include <linux/string.h> |
0d305464 | 18 | #include <linux/platform_device.h> |
3082bdfc | 19 | #include <linux/dma-mapping.h> |
0d305464 | 20 | #include <linux/slab.h> |
4e57b681 | 21 | |
bd9ba8f4 | 22 | #include <asm/byteorder.h> |
1da177e4 LT |
23 | #include <asm/setup.h> |
24 | #include <asm/amigahw.h> | |
25 | ||
26 | #include "zorro.h" | |
27 | ||
28 | ||
29 | /* | |
30 | * Zorro Expansion Devices | |
31 | */ | |
32 | ||
0d305464 | 33 | unsigned int zorro_num_autocon; |
c293738e GU |
34 | struct zorro_dev_init zorro_autocon_init[ZORRO_NUM_AUTO] __initdata; |
35 | struct zorro_dev *zorro_autocon; | |
1da177e4 LT |
36 | |
37 | ||
38 | /* | |
0d305464 | 39 | * Zorro bus |
1da177e4 LT |
40 | */ |
41 | ||
0d305464 | 42 | struct zorro_bus { |
0d305464 | 43 | struct device dev; |
c293738e | 44 | struct zorro_dev devices[0]; |
1da177e4 LT |
45 | }; |
46 | ||
47 | ||
48 | /* | |
49 | * Find Zorro Devices | |
50 | */ | |
51 | ||
52 | struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) | |
53 | { | |
0d305464 | 54 | struct zorro_dev *z; |
1da177e4 | 55 | |
0d305464 GU |
56 | if (!zorro_num_autocon) |
57 | return NULL; | |
1da177e4 | 58 | |
0d305464 GU |
59 | for (z = from ? from+1 : &zorro_autocon[0]; |
60 | z < zorro_autocon+zorro_num_autocon; | |
61 | z++) | |
62 | if (id == ZORRO_WILDCARD || id == z->id) | |
63 | return z; | |
64 | return NULL; | |
1da177e4 | 65 | } |
0d305464 | 66 | EXPORT_SYMBOL(zorro_find_device); |
1da177e4 LT |
67 | |
68 | ||
69 | /* | |
70 | * Bitmask indicating portions of available Zorro II RAM that are unused | |
71 | * by the system. Every bit represents a 64K chunk, for a maximum of 8MB | |
72 | * (128 chunks, physical 0x00200000-0x009fffff). | |
73 | * | |
74 | * If you want to use (= allocate) portions of this RAM, you should clear | |
75 | * the corresponding bits. | |
76 | * | |
77 | * Possible uses: | |
78 | * - z2ram device | |
79 | * - SCSI DMA bounce buffers | |
80 | * | |
81 | * FIXME: use the normal resource management | |
82 | */ | |
83 | ||
84 | DECLARE_BITMAP(zorro_unused_z2ram, 128); | |
0d305464 | 85 | EXPORT_SYMBOL(zorro_unused_z2ram); |
1da177e4 LT |
86 | |
87 | ||
88 | static void __init mark_region(unsigned long start, unsigned long end, | |
89 | int flag) | |
90 | { | |
1da177e4 | 91 | if (flag) |
0d305464 | 92 | start += Z2RAM_CHUNKMASK; |
1da177e4 | 93 | else |
0d305464 GU |
94 | end += Z2RAM_CHUNKMASK; |
95 | start &= ~Z2RAM_CHUNKMASK; | |
96 | end &= ~Z2RAM_CHUNKMASK; | |
97 | ||
98 | if (end <= Z2RAM_START || start >= Z2RAM_END) | |
99 | return; | |
100 | start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START; | |
101 | end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START; | |
102 | while (start < end) { | |
103 | u32 chunk = start>>Z2RAM_CHUNKSHIFT; | |
104 | if (flag) | |
105 | set_bit(chunk, zorro_unused_z2ram); | |
106 | else | |
107 | clear_bit(chunk, zorro_unused_z2ram); | |
108 | start += Z2RAM_CHUNKSIZE; | |
109 | } | |
1da177e4 LT |
110 | } |
111 | ||
112 | ||
0d305464 GU |
113 | static struct resource __init *zorro_find_parent_resource( |
114 | struct platform_device *bridge, struct zorro_dev *z) | |
1da177e4 | 115 | { |
0d305464 | 116 | int i; |
1da177e4 | 117 | |
0d305464 GU |
118 | for (i = 0; i < bridge->num_resources; i++) { |
119 | struct resource *r = &bridge->resource[i]; | |
120 | if (zorro_resource_start(z) >= r->start && | |
121 | zorro_resource_end(z) <= r->end) | |
122 | return r; | |
123 | } | |
124 | return &iomem_resource; | |
1da177e4 LT |
125 | } |
126 | ||
127 | ||
1da177e4 | 128 | |
0d305464 | 129 | static int __init amiga_zorro_probe(struct platform_device *pdev) |
1da177e4 | 130 | { |
0d305464 | 131 | struct zorro_bus *bus; |
c293738e | 132 | struct zorro_dev_init *zi; |
0d305464 GU |
133 | struct zorro_dev *z; |
134 | struct resource *r; | |
135 | unsigned int i; | |
136 | int error; | |
137 | ||
138 | /* Initialize the Zorro bus */ | |
c293738e GU |
139 | bus = kzalloc(sizeof(*bus) + |
140 | zorro_num_autocon * sizeof(bus->devices[0]), | |
141 | GFP_KERNEL); | |
0d305464 GU |
142 | if (!bus) |
143 | return -ENOMEM; | |
144 | ||
c293738e | 145 | zorro_autocon = bus->devices; |
0d305464 | 146 | bus->dev.parent = &pdev->dev; |
83b7bce3 | 147 | dev_set_name(&bus->dev, zorro_bus_type.name); |
0d305464 | 148 | error = device_register(&bus->dev); |
11a8b2c5 | 149 | if (error) { |
0d305464 | 150 | pr_err("Zorro: Error registering zorro_bus\n"); |
10b68799 | 151 | put_device(&bus->dev); |
0d305464 GU |
152 | kfree(bus); |
153 | return error; | |
11a8b2c5 | 154 | } |
0d305464 GU |
155 | platform_set_drvdata(pdev, bus); |
156 | ||
0d305464 GU |
157 | pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n", |
158 | zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); | |
159 | ||
a7f4d00a | 160 | /* First identify all devices ... */ |
0d305464 | 161 | for (i = 0; i < zorro_num_autocon; i++) { |
c293738e | 162 | zi = &zorro_autocon_init[i]; |
0d305464 | 163 | z = &zorro_autocon[i]; |
c293738e GU |
164 | |
165 | z->rom = zi->rom; | |
bd9ba8f4 GU |
166 | z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) | |
167 | (z->rom.er_Product << 8); | |
0d305464 GU |
168 | if (z->id == ZORRO_PROD_GVP_EPC_BASE) { |
169 | /* GVP quirk */ | |
c293738e | 170 | unsigned long magic = zi->boardaddr + 0x8000; |
0d305464 GU |
171 | z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK; |
172 | } | |
c293738e GU |
173 | z->slotaddr = zi->slotaddr; |
174 | z->slotsize = zi->slotsize; | |
0d305464 GU |
175 | sprintf(z->name, "Zorro device %08x", z->id); |
176 | zorro_name_device(z); | |
c293738e GU |
177 | z->resource.start = zi->boardaddr; |
178 | z->resource.end = zi->boardaddr + zi->boardsize - 1; | |
0d305464 GU |
179 | z->resource.name = z->name; |
180 | r = zorro_find_parent_resource(pdev, z); | |
181 | error = request_resource(r, &z->resource); | |
182 | if (error) | |
183 | dev_err(&bus->dev, | |
184 | "Address space collision on device %s %pR\n", | |
185 | z->name, &z->resource); | |
0d305464 GU |
186 | z->dev.parent = &bus->dev; |
187 | z->dev.bus = &zorro_bus_type; | |
83b7bce3 | 188 | z->dev.id = i; |
3082bdfc MS |
189 | switch (z->rom.er_Type & ERT_TYPEMASK) { |
190 | case ERT_ZORROIII: | |
191 | z->dev.coherent_dma_mask = DMA_BIT_MASK(32); | |
192 | break; | |
193 | ||
194 | case ERT_ZORROII: | |
195 | default: | |
196 | z->dev.coherent_dma_mask = DMA_BIT_MASK(24); | |
197 | break; | |
198 | } | |
199 | z->dev.dma_mask = &z->dev.coherent_dma_mask; | |
a7f4d00a GU |
200 | } |
201 | ||
202 | /* ... then register them */ | |
203 | for (i = 0; i < zorro_num_autocon; i++) { | |
204 | z = &zorro_autocon[i]; | |
0d305464 GU |
205 | error = device_register(&z->dev); |
206 | if (error) { | |
207 | dev_err(&bus->dev, "Error registering device %s\n", | |
208 | z->name); | |
10b68799 | 209 | put_device(&z->dev); |
0d305464 GU |
210 | continue; |
211 | } | |
0d305464 GU |
212 | } |
213 | ||
214 | /* Mark all available Zorro II memory */ | |
215 | zorro_for_each_dev(z) { | |
216 | if (z->rom.er_Type & ERTF_MEMLIST) | |
217 | mark_region(zorro_resource_start(z), | |
218 | zorro_resource_end(z)+1, 1); | |
219 | } | |
220 | ||
221 | /* Unmark all used Zorro II memory */ | |
222 | for (i = 0; i < m68k_num_memory; i++) | |
223 | if (m68k_memory[i].addr < 16*1024*1024) | |
224 | mark_region(m68k_memory[i].addr, | |
225 | m68k_memory[i].addr+m68k_memory[i].size, | |
226 | 0); | |
227 | ||
228 | return 0; | |
1da177e4 LT |
229 | } |
230 | ||
0d305464 GU |
231 | static struct platform_driver amiga_zorro_driver = { |
232 | .driver = { | |
233 | .name = "amiga-zorro", | |
0d305464 GU |
234 | }, |
235 | }; | |
1da177e4 | 236 | |
0d305464 GU |
237 | static int __init amiga_zorro_init(void) |
238 | { | |
239 | return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe); | |
240 | } | |
241 | ||
242 | module_init(amiga_zorro_init); | |
1da177e4 LT |
243 | |
244 | MODULE_LICENSE("GPL"); |