Subversion Repositories HelenOS

Rev

Rev 4042 | Rev 4103 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4042 Rev 4070
1
/*
1
/*
2
 * Copyright (c) 2006 Jakub Jermar
2
 * Copyright (c) 2006 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup sparc64
29
/** @addtogroup sparc64
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/drivers/kbd.h>
35
#include <arch/drivers/kbd.h>
36
#include <genarch/ofw/ofw_tree.h>
36
#include <genarch/ofw/ofw_tree.h>
37
 
37
 
38
#ifdef CONFIG_SUN_KBD
38
#ifdef CONFIG_SUN_KBD
39
#include <genarch/kbrd/kbrd.h>
39
#include <genarch/kbrd/kbrd.h>
40
#endif
40
#endif
41
#ifdef CONFIG_Z8530
41
#ifdef CONFIG_Z8530
42
#include <genarch/drivers/z8530/z8530.h>
42
#include <genarch/drivers/z8530/z8530.h>
43
#endif
43
#endif
44
#ifdef CONFIG_NS16550
44
#ifdef CONFIG_NS16550
45
#include <genarch/drivers/ns16550/ns16550.h>
45
#include <genarch/drivers/ns16550/ns16550.h>
46
#endif
46
#endif
47
 
47
 
48
#include <console/console.h>
48
#include <console/console.h>
49
#include <ddi/device.h>
49
#include <ddi/device.h>
50
#include <ddi/irq.h>
50
#include <ddi/irq.h>
51
#include <arch/mm/page.h>
51
#include <arch/mm/page.h>
52
#include <arch/types.h>
52
#include <arch/types.h>
53
#include <align.h>
53
#include <align.h>
54
#include <string.h>
54
#include <string.h>
55
#include <print.h>
55
#include <print.h>
56
#include <sysinfo/sysinfo.h>
56
#include <sysinfo/sysinfo.h>
57
 
57
 
58
kbd_type_t kbd_type = KBD_UNKNOWN;
58
kbd_type_t kbd_type = KBD_UNKNOWN;
59
 
59
 
-
 
60
#if defined (CONFIG_Z8530) || defined (CONFIG_NS16550)
-
 
61
 
60
/** Initialize keyboard.
62
/** Initialize keyboard.
61
 *
63
 *
62
 * Traverse OpenFirmware device tree in order to find necessary
64
 * Traverse OpenFirmware device tree in order to find necessary
63
 * info about the keyboard device.
65
 * info about the keyboard device.
64
 *
66
 *
65
 * @param node Keyboard device node.
67
 * @param node Keyboard device node.
66
 */
68
 */
67
void kbd_init(ofw_tree_node_t *node)
69
void kbd_init(ofw_tree_node_t *node)
68
{
70
{
69
    size_t offset;
71
    size_t offset;
70
    uintptr_t aligned_addr;
72
    uintptr_t aligned_addr;
71
    ofw_tree_property_t *prop;
73
    ofw_tree_property_t *prop;
72
    const char *name;
74
    const char *name;
73
    cir_t cir;
75
    cir_t cir;
74
    void *cir_arg;
76
    void *cir_arg;
75
 
77
 
76
#ifdef CONFIG_NS16550
78
#ifdef CONFIG_NS16550
77
    ns16550_t *ns16550;
79
    ns16550_t *ns16550;
78
#endif
80
#endif
79
#ifdef CONFIG_Z8530
81
#ifdef CONFIG_Z8530
80
    z8530_t *z8530;
82
    z8530_t *z8530;
81
#endif
83
#endif
82
   
84
   
83
    name = ofw_tree_node_name(node);
85
    name = ofw_tree_node_name(node);
84
   
86
   
85
    /*
87
    /*
86
     * Determine keyboard serial controller type.
88
     * Determine keyboard serial controller type.
87
     */
89
     */
88
    if (strcmp(name, "zs") == 0)
90
    if (strcmp(name, "zs") == 0)
89
        kbd_type = KBD_Z8530;
91
        kbd_type = KBD_Z8530;
90
    else if (strcmp(name, "su") == 0)
92
    else if (strcmp(name, "su") == 0)
91
        kbd_type = KBD_NS16550;
93
        kbd_type = KBD_NS16550;
92
   
94
   
93
    if (kbd_type == KBD_UNKNOWN) {
95
    if (kbd_type == KBD_UNKNOWN) {
94
        printf("Unknown keyboard device.\n");
96
        printf("Unknown keyboard device.\n");
95
        return;
97
        return;
96
    }
98
    }
97
   
99
   
98
    /*
100
    /*
99
     * Read 'interrupts' property.
101
     * Read 'interrupts' property.
100
     */
102
     */
101
    uint32_t interrupts;
103
    uint32_t interrupts;
102
    prop = ofw_tree_getprop(node, "interrupts");
104
    prop = ofw_tree_getprop(node, "interrupts");
103
    if ((!prop) || (!prop->value))
105
    if ((!prop) || (!prop->value))
104
        panic("Cannot find 'interrupt' property.");
106
        panic("Cannot find 'interrupt' property.");
105
    interrupts = *((uint32_t *) prop->value);
107
    interrupts = *((uint32_t *) prop->value);
106
   
108
   
107
    /*
109
    /*
108
     * Read 'reg' property.
110
     * Read 'reg' property.
109
     */
111
     */
110
    prop = ofw_tree_getprop(node, "reg");
112
    prop = ofw_tree_getprop(node, "reg");
111
    if ((!prop) || (!prop->value))
113
    if ((!prop) || (!prop->value))
112
        panic("Cannot find 'reg' property.");
114
        panic("Cannot find 'reg' property.");
113
   
115
   
114
    uintptr_t pa;
116
    uintptr_t pa;
115
    size_t size;
117
    size_t size;
116
    devno_t devno;
118
    devno_t devno;
117
    inr_t inr;
119
    inr_t inr;
118
   
120
   
119
    switch (kbd_type) {
121
    switch (kbd_type) {
120
    case KBD_Z8530:
122
    case KBD_Z8530:
121
        size = ((ofw_fhc_reg_t *) prop->value)->size;
123
        size = ((ofw_fhc_reg_t *) prop->value)->size;
122
        if (!ofw_fhc_apply_ranges(node->parent,
124
        if (!ofw_fhc_apply_ranges(node->parent,
123
            ((ofw_fhc_reg_t *) prop->value), &pa)) {
125
            ((ofw_fhc_reg_t *) prop->value), &pa)) {
124
            printf("Failed to determine keyboard address.\n");
126
            printf("Failed to determine keyboard address.\n");
125
            return;
127
            return;
126
        }
128
        }
127
        if (!ofw_fhc_map_interrupt(node->parent,
129
        if (!ofw_fhc_map_interrupt(node->parent,
128
            ((ofw_fhc_reg_t *) prop->value), interrupts, &inr, &cir,
130
            ((ofw_fhc_reg_t *) prop->value), interrupts, &inr, &cir,
129
            &cir_arg)) {
131
            &cir_arg)) {
130
            printf("Failed to determine keyboard interrupt.\n");
132
            printf("Failed to determine keyboard interrupt.\n");
131
            return;
133
            return;
132
        }
134
        }
133
        break;
135
        break;
134
       
136
       
135
    case KBD_NS16550:
137
    case KBD_NS16550:
136
        size = ((ofw_ebus_reg_t *) prop->value)->size;
138
        size = ((ofw_ebus_reg_t *) prop->value)->size;
137
        if (!ofw_ebus_apply_ranges(node->parent,
139
        if (!ofw_ebus_apply_ranges(node->parent,
138
            ((ofw_ebus_reg_t *) prop->value), &pa)) {
140
            ((ofw_ebus_reg_t *) prop->value), &pa)) {
139
            printf("Failed to determine keyboard address.\n");
141
            printf("Failed to determine keyboard address.\n");
140
            return;
142
            return;
141
        }
143
        }
142
        if (!ofw_ebus_map_interrupt(node->parent,
144
        if (!ofw_ebus_map_interrupt(node->parent,
143
            ((ofw_ebus_reg_t *) prop->value), interrupts, &inr, &cir,
145
            ((ofw_ebus_reg_t *) prop->value), interrupts, &inr, &cir,
144
            &cir_arg)) {
146
            &cir_arg)) {
145
            printf("Failed to determine keyboard interrupt.\n");
147
            printf("Failed to determine keyboard interrupt.\n");
146
            return;
148
            return;
147
        };
149
        };
148
        break;
150
        break;
149
    default:
151
    default:
150
        panic("Unexpected keyboard type.");
152
        panic("Unexpected keyboard type.");
151
    }
153
    }
152
   
154
   
153
    /*
155
    /*
154
     * We need to pass aligned address to hw_map().
156
     * We need to pass aligned address to hw_map().
155
     * However, the physical keyboard address can
157
     * However, the physical keyboard address can
156
     * be pretty much unaligned, depending on the
158
     * be pretty much unaligned, depending on the
157
     * underlying controller.
159
     * underlying controller.
158
     */
160
     */
159
    aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
161
    aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
160
    offset = pa - aligned_addr;
162
    offset = pa - aligned_addr;
161
   
163
   
162
    switch (kbd_type) {
164
    switch (kbd_type) {
163
#ifdef CONFIG_Z8530
165
#ifdef CONFIG_Z8530
164
    case KBD_Z8530:
166
    case KBD_Z8530:
165
        devno = device_assign_devno();
167
        devno = device_assign_devno();
166
        z8530 = (z8530_t *) hw_map(aligned_addr, offset + size) +
168
        z8530 = (z8530_t *) hw_map(aligned_addr, offset + size) +
167
            offset;
169
            offset;
168
        kbrd_init(stdin);
170
        kbrd_init(stdin);
169
        (void) z8530_init(z8530, devno, inr, cir, cir_arg, &kbrdin);
171
        (void) z8530_init(z8530, devno, inr, cir, cir_arg, &kbrdin);
170
       
172
       
171
        /*
173
        /*
172
         * This is the necessary evil until the userspace drivers are
174
         * This is the necessary evil until the userspace drivers are
173
         * entirely self-sufficient.
175
         * entirely self-sufficient.
174
         */
176
         */
175
        sysinfo_set_item_val("kbd", NULL, true);
177
        sysinfo_set_item_val("kbd", NULL, true);
176
        sysinfo_set_item_val("kbd.type", NULL, KBD_Z8530);
178
        sysinfo_set_item_val("kbd.type", NULL, KBD_Z8530);
177
        sysinfo_set_item_val("kbd.devno", NULL, devno);
179
        sysinfo_set_item_val("kbd.devno", NULL, devno);
178
        sysinfo_set_item_val("kbd.inr", NULL, inr);
180
        sysinfo_set_item_val("kbd.inr", NULL, inr);
179
        sysinfo_set_item_val("kbd.address.kernel", NULL,
181
        sysinfo_set_item_val("kbd.address.kernel", NULL,
180
            (uintptr_t) z8530);
182
            (uintptr_t) z8530);
181
        sysinfo_set_item_val("kbd.address.physical", NULL, pa);
183
        sysinfo_set_item_val("kbd.address.physical", NULL, pa);
182
        break;
184
        break;
183
#endif
185
#endif
184
#ifdef CONFIG_NS16550
186
#ifdef CONFIG_NS16550
185
    case KBD_NS16550:
187
    case KBD_NS16550:
186
        devno = device_assign_devno();
188
        devno = device_assign_devno();
187
        ns16550 = (ns16550_t *) hw_map(aligned_addr, offset + size) +
189
        ns16550 = (ns16550_t *) hw_map(aligned_addr, offset + size) +
188
            offset;
190
            offset;
189
        kbrd_init(stdin);
191
        kbrd_init(stdin);
190
        (void) ns16550_init(ns16550, devno, inr, cir, cir_arg, &kbrdin);
192
        (void) ns16550_init(ns16550, devno, inr, cir, cir_arg, &kbrdin);
191
       
193
       
192
        /*
194
        /*
193
         * This is the necessary evil until the userspace driver is
195
         * This is the necessary evil until the userspace driver is
194
         * entirely self-sufficient.
196
         * entirely self-sufficient.
195
         */
197
         */
196
        sysinfo_set_item_val("kbd", NULL, true);
198
        sysinfo_set_item_val("kbd", NULL, true);
197
        sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550);
199
        sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550);
198
        sysinfo_set_item_val("kbd.devno", NULL, devno);
200
        sysinfo_set_item_val("kbd.devno", NULL, devno);
199
        sysinfo_set_item_val("kbd.inr", NULL, inr);
201
        sysinfo_set_item_val("kbd.inr", NULL, inr);
200
        sysinfo_set_item_val("kbd.address.kernel", NULL,
202
        sysinfo_set_item_val("kbd.address.kernel", NULL,
201
            (uintptr_t) ns16550);
203
            (uintptr_t) ns16550);
202
        sysinfo_set_item_val("kbd.address.physical", NULL, pa);
204
        sysinfo_set_item_val("kbd.address.physical", NULL, pa);
203
        break;
205
        break;
204
#endif
206
#endif
205
    default:
207
    default:
206
        printf("Kernel is not compiled with the necessary keyboard "
208
        printf("Kernel is not compiled with the necessary keyboard "
207
            "driver this machine requires.\n");
209
            "driver this machine requires.\n");
208
    }
210
    }
209
}
211
}
210
 
212
 
-
 
213
    #endif
211
/** @}
214
/** @}
212
 */
215
 */
213
 
216