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