blob: 4cc42b64820cdb09e0ae5a6212feb9b5e8ed8528 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * $Id: zorro.c,v 1.1.2.1 1998/06/07 23:21:02 geert Exp $
3 *
4 * Zorro Bus Services
5 *
6 * Copyright (C) 1995-2003 Geert Uytterhoeven
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/zorro.h>
18#include <linux/bitops.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080019#include <linux/string.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/setup.h>
22#include <asm/amigahw.h>
23
24#include "zorro.h"
25
26
27 /*
28 * Zorro Expansion Devices
29 */
30
31u_int zorro_num_autocon = 0;
32struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
33
34
35 /*
36 * Single Zorro bus
37 */
38
39struct zorro_bus zorro_bus = {\
40 .resources = {
41 /* Zorro II regions (on Zorro II/III) */
42 { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff },
43 { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff },
44 /* Zorro III regions (on Zorro III only) */
45 { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff },
46 { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff }
47 },
48 .name = "Zorro bus"
49};
50
51
52 /*
53 * Find Zorro Devices
54 */
55
56struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
57{
58 struct zorro_dev *z;
59
60 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
61 return NULL;
62
63 for (z = from ? from+1 : &zorro_autocon[0];
64 z < zorro_autocon+zorro_num_autocon;
65 z++)
66 if (id == ZORRO_WILDCARD || id == z->id)
67 return z;
68 return NULL;
69}
70
71
72 /*
73 * Bitmask indicating portions of available Zorro II RAM that are unused
74 * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
75 * (128 chunks, physical 0x00200000-0x009fffff).
76 *
77 * If you want to use (= allocate) portions of this RAM, you should clear
78 * the corresponding bits.
79 *
80 * Possible uses:
81 * - z2ram device
82 * - SCSI DMA bounce buffers
83 *
84 * FIXME: use the normal resource management
85 */
86
87DECLARE_BITMAP(zorro_unused_z2ram, 128);
88
89
90static void __init mark_region(unsigned long start, unsigned long end,
91 int flag)
92{
93 if (flag)
94 start += Z2RAM_CHUNKMASK;
95 else
96 end += Z2RAM_CHUNKMASK;
97 start &= ~Z2RAM_CHUNKMASK;
98 end &= ~Z2RAM_CHUNKMASK;
99
100 if (end <= Z2RAM_START || start >= Z2RAM_END)
101 return;
102 start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
103 end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
104 while (start < end) {
105 u32 chunk = start>>Z2RAM_CHUNKSHIFT;
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(struct zorro_dev *z)
116{
117 int i;
118
119 for (i = 0; i < zorro_bus.num_resources; i++)
120 if (zorro_resource_start(z) >= zorro_bus.resources[i].start &&
121 zorro_resource_end(z) <= zorro_bus.resources[i].end)
122 return &zorro_bus.resources[i];
123 return &iomem_resource;
124}
125
126
127 /*
128 * Initialization
129 */
130
131static int __init zorro_init(void)
132{
133 struct zorro_dev *z;
134 unsigned int i;
135
136 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
137 return 0;
138
139 pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
140 zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
141
142 /* Initialize the Zorro bus */
143 INIT_LIST_HEAD(&zorro_bus.devices);
144 strcpy(zorro_bus.dev.bus_id, "zorro");
145 device_register(&zorro_bus.dev);
146
147 /* Request the resources */
148 zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
149 for (i = 0; i < zorro_bus.num_resources; i++)
150 request_resource(&iomem_resource, &zorro_bus.resources[i]);
151
152 /* Register all devices */
153 for (i = 0; i < zorro_num_autocon; i++) {
154 z = &zorro_autocon[i];
155 z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
156 if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
157 /* GVP quirk */
158 unsigned long magic = zorro_resource_start(z)+0x8000;
159 z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
160 }
161 sprintf(z->name, "Zorro device %08x", z->id);
162 zorro_name_device(z);
163 z->resource.name = z->name;
164 if (request_resource(zorro_find_parent_resource(z), &z->resource))
165 printk(KERN_ERR "Zorro: Address space collision on device %s "
166 "[%lx:%lx]\n",
Geert Uytterhoeven31817572007-05-01 22:33:04 +0200167 z->name, (unsigned long)zorro_resource_start(z),
168 (unsigned long)zorro_resource_end(z));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 sprintf(z->dev.bus_id, "%02x", i);
170 z->dev.parent = &zorro_bus.dev;
171 z->dev.bus = &zorro_bus_type;
172 device_register(&z->dev);
173 zorro_create_sysfs_dev_files(z);
174 }
175
176 /* Mark all available Zorro II memory */
177 zorro_for_each_dev(z) {
178 if (z->rom.er_Type & ERTF_MEMLIST)
179 mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1);
180 }
181
182 /* Unmark all used Zorro II memory */
183 for (i = 0; i < m68k_num_memory; i++)
184 if (m68k_memory[i].addr < 16*1024*1024)
185 mark_region(m68k_memory[i].addr,
186 m68k_memory[i].addr+m68k_memory[i].size, 0);
187
188 return 0;
189}
190
191subsys_initcall(zorro_init);
192
193EXPORT_SYMBOL(zorro_find_device);
194EXPORT_SYMBOL(zorro_unused_z2ram);
195
196MODULE_LICENSE("GPL");