xref: /haiku/src/add-ons/kernel/bus_managers/isa/isa.cpp (revision 1a76488fc88584bf66b9751d7fb9b6527ac20d87)
1 /*
2  * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Copyright 2002/03, Thomas Kurschel. All rights reserved.
4  *
5  * Distributed under the terms of the MIT License.
6  */
7 
8 /*
9 	ISA bus manager
10 
11 	Implementation.
12 */
13 
14 
15 #include <ISA.h>
16 #include <bus/ISA.h>
17 #include <KernelExport.h>
18 #include <device_manager.h>
19 #include <arch/cpu.h>
20 
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "isa_arch.h"
25 
26 //#define TRACE_ISA
27 #ifdef TRACE_ISA
28 #	define TRACE(x) dprintf x
29 #else
30 #	define TRACE(x) ;
31 #endif
32 
33 // ToDo: this is architecture dependent and should be made differently!
34 //	(for example, the Pegasos (PPC based) also has an ISA bus)
35 
36 
37 #define ISA_MODULE_NAME "bus_managers/isa/root/driver_v1"
38 
39 device_manager_info *pnp;
40 
41 
42 static long
43 make_isa_dma_table(const void *buffer, long buffer_size, ulong num_bits,
44 	isa_dma_entry *table, long num_entries)
45 {
46 	// ToDo: implement this?!
47 	return ENOSYS;
48 }
49 
50 
51 static long
52 start_scattered_isa_dma(long channel, const isa_dma_entry *table,
53 	uchar mode, uchar emode)
54 {
55 	// ToDo: implement this?!
56 	return ENOSYS;
57 }
58 
59 
60 static status_t
61 lock_isa_dma_channel(long channel)
62 {
63 	// ToDo: implement this?!
64 	return B_NOT_ALLOWED;
65 }
66 
67 
68 static status_t
69 unlock_isa_dma_channel(long channel)
70 {
71 	// ToDo: implement this?!
72 	return B_ERROR;
73 }
74 
75 
76 //	#pragma mark - driver module API
77 
78 
79 static status_t
80 isa_init_driver(device_node *node, void **cookie)
81 {
82 	*cookie = node;
83 	return B_OK;
84 }
85 
86 
87 static void
88 isa_uninit_driver(void *cookie)
89 {
90 }
91 
92 
93 static float
94 isa_supports_device(device_node *parent)
95 {
96 	const char *bus;
97 
98 	// make sure parent is really pnp root
99 	if (pnp->get_attr_string(parent, B_DEVICE_BUS, &bus, false))
100 		return B_ERROR;
101 
102 	if (strcmp(bus, "root"))
103 		return 0.0;
104 
105 	return 1.0;
106 }
107 
108 
109 static status_t
110 isa_register_device(device_node *parent)
111 {
112 	static const device_attr attrs[] = {
113 		// tell where to look for child devices
114 		{B_DEVICE_BUS, B_STRING_TYPE, {.string = "isa" }},
115 		{B_DEVICE_FLAGS, B_UINT32_TYPE,
116 			{.ui32 = B_FIND_CHILD_ON_DEMAND | B_FIND_MULTIPLE_CHILDREN}},
117 		{}
118 	};
119 
120 	return pnp->register_node(parent, ISA_MODULE_NAME, attrs, NULL, NULL);
121 }
122 
123 
124 static status_t
125 std_ops(int32 op, ...)
126 {
127 	switch (op) {
128 		case B_MODULE_INIT:
129 			return arch_isa_init();
130 		case B_MODULE_UNINIT:
131 			return B_OK;
132 
133 		default:
134 			return B_ERROR;
135 	}
136 }
137 
138 
139 module_dependency module_dependencies[] = {
140 	{ B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&pnp },
141 	{}
142 };
143 
144 static isa_module_info isa_module = {
145 	{
146 		{
147 			B_ISA_MODULE_NAME,
148 			B_KEEP_LOADED,
149 			std_ops
150 		},
151 		NULL	// rescan
152 	},
153 	&arch_isa_read_io_8,
154 	&arch_isa_write_io_8,
155 	&arch_isa_read_io_16,
156 	&arch_isa_write_io_16,
157 	&arch_isa_read_io_32,
158 	&arch_isa_write_io_32,
159 	&arch_isa_ram_address,
160 	&make_isa_dma_table,
161 	&arch_start_isa_dma,
162 	&start_scattered_isa_dma,
163 	&lock_isa_dma_channel,
164 	&unlock_isa_dma_channel
165 };
166 
167 static isa2_module_info isa2_module = {
168 	{
169 		{
170 			ISA_MODULE_NAME,
171 			0,
172 			std_ops
173 		},
174 
175 		isa_supports_device,
176 		isa_register_device,
177 		isa_init_driver,
178 		isa_uninit_driver,
179 		NULL,	// removed device
180 		NULL,	// register child devices
181 		NULL,	// rescan bus
182 	},
183 
184 	arch_isa_read_io_8, arch_isa_write_io_8,
185 	arch_isa_read_io_16, arch_isa_write_io_16,
186 	arch_isa_read_io_32, arch_isa_write_io_32,
187 
188 	arch_isa_ram_address,
189 
190 	arch_start_isa_dma,
191 };
192 
193 module_info *modules[] = {
194 	(module_info *)&isa_module,
195 	(module_info *)&isa2_module,
196 	NULL
197 };
198