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