source: mainline/kernel/arch/sparc64/src/drivers/kbd.c@ 6d7f9bfe

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6d7f9bfe was e731b0d, checked in by Martin Decky <martin@…>, 16 years ago

make ppc32 OFW usage on par with sparc64, make appropriate modifications elsewhere

  • introduce ofw_tree_walk_by_device_type() to gather all OFW devices of a given type
  • ppc32 uses canonized OFW tree, mac-io and display devices are detected in kernel (not by the boot loader) by means of device type
  • various busses (PCI, EBUS, etc.) stay sparc64 specific for now
  • boot memcpy() is defined in a common way
  • BALLOC_MAX_SIZE is platform-dependent
  • ppc32 and sparc64 boot loaders cleanup (removal of obsolete stuff, data is not passed by global variables if not necessary, etc.)
  • balloc and OFW tree canonizer have now a provision to support different mapping of the data during boot time and kernel run-time
  • OFW tree canonizer uses balloc_rebase() to store pointers suitable for access during kernel run-time (with potentially different memory mapping than during boot time)
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright (c) 2006 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/drivers/kbd.h>
36#include <genarch/ofw/ofw_tree.h>
37#include <genarch/ofw/fhc.h>
38#include <genarch/ofw/ebus.h>
39#include <console/console.h>
40#include <ddi/irq.h>
41#include <arch/mm/page.h>
42#include <arch/types.h>
43#include <align.h>
44#include <string.h>
45#include <print.h>
46#include <sysinfo/sysinfo.h>
47
48#ifdef CONFIG_SUN_KBD
49#include <genarch/kbrd/kbrd.h>
50#endif
51
52#ifdef CONFIG_Z8530
53#include <genarch/drivers/z8530/z8530.h>
54#endif
55
56#ifdef CONFIG_NS16550
57#include <genarch/drivers/ns16550/ns16550.h>
58#endif
59
60#ifdef CONFIG_SUN_KBD
61
62#ifdef CONFIG_Z8530
63
64static bool kbd_z8530_init(ofw_tree_node_t *node)
65{
66 const char *name = ofw_tree_node_name(node);
67
68 if (str_cmp(name, "zs") != 0)
69 return false;
70
71 /*
72 * Read 'interrupts' property.
73 */
74 ofw_tree_property_t *prop = ofw_tree_getprop(node, "interrupts");
75 if ((!prop) || (!prop->value)) {
76 printf("z8530: Unable to find interrupts property\n");
77 return false;
78 }
79
80 uint32_t interrupts = *((uint32_t *) prop->value);
81
82 /*
83 * Read 'reg' property.
84 */
85 prop = ofw_tree_getprop(node, "reg");
86 if ((!prop) || (!prop->value)) {
87 printf("z8530: Unable to find reg property\n");
88 return false;
89 }
90
91 size_t size = ((ofw_fhc_reg_t *) prop->value)->size;
92
93 uintptr_t pa;
94 if (!ofw_fhc_apply_ranges(node->parent,
95 ((ofw_fhc_reg_t *) prop->value), &pa)) {
96 printf("z8530: Failed to determine address\n");
97 return false;
98 }
99
100 inr_t inr;
101 cir_t cir;
102 void *cir_arg;
103 if (!ofw_fhc_map_interrupt(node->parent,
104 ((ofw_fhc_reg_t *) prop->value), interrupts, &inr, &cir,
105 &cir_arg)) {
106 printf("z8530: Failed to determine interrupt\n");
107 return false;
108 }
109
110 /*
111 * We need to pass aligned address to hw_map().
112 * However, the physical keyboard address can
113 * be pretty much unaligned, depending on the
114 * underlying controller.
115 */
116 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
117 size_t offset = pa - aligned_addr;
118
119 z8530_t *z8530 = (z8530_t *)
120 (hw_map(aligned_addr, offset + size) + offset);
121
122 z8530_instance_t *z8530_instance = z8530_init(z8530, inr, cir, cir_arg);
123 if (z8530_instance) {
124 kbrd_instance_t *kbrd_instance = kbrd_init();
125 if (kbrd_instance) {
126 indev_t *sink = stdin_wire();
127 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
128 z8530_wire(z8530_instance, kbrd);
129 }
130 }
131
132 /*
133 * This is the necessary evil until the userspace drivers are
134 * entirely self-sufficient.
135 */
136 sysinfo_set_item_val("kbd", NULL, true);
137 sysinfo_set_item_val("kbd.inr", NULL, inr);
138 sysinfo_set_item_val("kbd.address.kernel", NULL,
139 (uintptr_t) z8530);
140 sysinfo_set_item_val("kbd.address.physical", NULL, pa);
141 sysinfo_set_item_val("kbd.type.z8530", NULL, true);
142
143 return true;
144}
145
146#endif /* CONFIG_Z8530 */
147
148#ifdef CONFIG_NS16550
149
150static bool kbd_ns16550_init(ofw_tree_node_t *node)
151{
152 const char *name = ofw_tree_node_name(node);
153
154 if (str_cmp(name, "su") != 0)
155 return false;
156
157 /*
158 * Read 'interrupts' property.
159 */
160 ofw_tree_property_t *prop = ofw_tree_getprop(node, "interrupts");
161 if ((!prop) || (!prop->value)) {
162 printf("ns16550: Unable to find interrupts property\n");
163 return false;
164 }
165
166 uint32_t interrupts = *((uint32_t *) prop->value);
167
168 /*
169 * Read 'reg' property.
170 */
171 prop = ofw_tree_getprop(node, "reg");
172 if ((!prop) || (!prop->value)) {
173 printf("ns16550: Unable to find reg property\n");
174 return false;
175 }
176
177 size_t size = ((ofw_ebus_reg_t *) prop->value)->size;
178
179 uintptr_t pa;
180 if (!ofw_ebus_apply_ranges(node->parent,
181 ((ofw_ebus_reg_t *) prop->value), &pa)) {
182 printf("ns16550: Failed to determine address\n");
183 return false;
184 }
185
186 inr_t inr;
187 cir_t cir;
188 void *cir_arg;
189 if (!ofw_ebus_map_interrupt(node->parent,
190 ((ofw_ebus_reg_t *) prop->value), interrupts, &inr, &cir,
191 &cir_arg)) {
192 printf("ns16550: Failed to determine interrupt\n");
193 return false;
194 }
195
196 /*
197 * We need to pass aligned address to hw_map().
198 * However, the physical keyboard address can
199 * be pretty much unaligned, depending on the
200 * underlying controller.
201 */
202 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
203 size_t offset = pa - aligned_addr;
204
205 ns16550_t *ns16550 = (ns16550_t *)
206 (hw_map(aligned_addr, offset + size) + offset);
207
208 ns16550_instance_t *ns16550_instance = ns16550_init(ns16550, inr, cir, cir_arg);
209 if (ns16550_instance) {
210 kbrd_instance_t *kbrd_instance = kbrd_init();
211 if (kbrd_instance) {
212 indev_t *sink = stdin_wire();
213 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
214 ns16550_wire(ns16550_instance, kbrd);
215 }
216 }
217
218 /*
219 * This is the necessary evil until the userspace drivers are
220 * entirely self-sufficient.
221 */
222 sysinfo_set_item_val("kbd", NULL, true);
223 sysinfo_set_item_val("kbd.inr", NULL, inr);
224 sysinfo_set_item_val("kbd.address.kernel", NULL,
225 (uintptr_t) ns16550);
226 sysinfo_set_item_val("kbd.address.physical", NULL, pa);
227 sysinfo_set_item_val("kbd.type.ns16550", NULL, true);
228
229 return true;
230}
231
232#endif /* CONFIG_NS16550 */
233
234/** Initialize keyboard.
235 *
236 * Traverse OpenFirmware device tree in order to find necessary
237 * info about the keyboard device.
238 *
239 * @param node Keyboard device node.
240 *
241 */
242void kbd_init(ofw_tree_node_t *node)
243{
244#ifdef CONFIG_Z8530
245 kbd_z8530_init(node);
246#endif
247
248#ifdef CONFIG_NS16550
249 kbd_ns16550_init(node);
250#endif
251}
252
253#endif /* CONFIG_SUN_KBD */
254
255/** @}
256 */
Note: See TracBrowser for help on using the repository browser.