Subversion Repositories HelenOS

Rev

Rev 3582 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3549 rimsky 1
/*
2
 * Copyright (c) 2008 Pavel Rimsky
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 kbdsparc64 sparc64
30
 * @brief   Serengeti-specific parts of uspace keyboard handler.
31
 * @ingroup  kbd
32
 * @{
33
 */
34
/** @file
35
 */
36
 
37
#include <arch/sgcn.h>
38
#include <as.h>
39
#include <ddi.h>
40
#include <ipc/ipc.h>
41
#include <kbd.h>
42
#include <genarch/nofb.h>
43
#include <genarch/kbd.h>
44
#include <sysinfo.h>
45
#include <stdio.h>
46
#include <futex.h>
47
 
48
/**
49
 * SGCN buffer header. It is placed at the very beginning of the SGCN
50
 * buffer.
51
 */
52
typedef struct {
53
    /** hard-wired to "CON" */
54
    char magic[4];
55
 
56
    /** we don't need this */
57
    char unused[8];
58
 
59
    /** offset within the SGCN buffer of the input buffer start */
60
    uint32_t in_begin;
61
 
62
    /** offset within the SGCN buffer of the input buffer end */
63
    uint32_t in_end;
64
 
65
    /** offset within the SGCN buffer of the input buffer read pointer */
66
    uint32_t in_rdptr;
67
 
68
    /** offset within the SGCN buffer of the input buffer write pointer */
69
    uint32_t in_wrptr;
70
 
71
    /** offset within the SGCN buffer of the output buffer start */
72
    uint32_t out_begin;
73
 
74
    /** offset within the SGCN buffer of the output buffer end */
75
    uint32_t out_end;
76
 
77
    /** offset within the SGCN buffer of the output buffer read pointer */
78
    uint32_t out_rdptr;
79
 
80
    /** offset within the SGCN buffer of the output buffer write pointer */
81
    uint32_t out_wrptr;
82
} __attribute__ ((packed)) sgcn_buffer_header_t;
83
 
84
/*
85
 * Returns a pointer to the object of a given type which is placed at the given
86
 * offset from the console buffer beginning.
87
 */
88
#define SGCN_BUFFER(type, offset) \
89
        ((type *) (sram_virt_addr + sram_buffer_offset + (offset)))
90
 
91
/** Returns a pointer to the console buffer header. */
92
#define SGCN_BUFFER_HEADER  (SGCN_BUFFER(sgcn_buffer_header_t, 0))
93
 
94
extern keybuffer_t keybuffer;
95
 
96
/**
97
 * Virtual address mapped to SRAM.
98
 */
99
static uintptr_t sram_virt_addr;
100
 
101
/**
102
 * SGCN buffer offset within SGCN.
103
 */
104
static uintptr_t sram_buffer_offset;
105
 
106
/**
107
 * Initializes the SGCN driver.
108
 * Maps the physical memory (SRAM) and registers the interrupt.
109
 */
110
void sgcn_init(void)
111
{
112
    sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
113
    int result = physmem_map(
114
        (void *) sysinfo_value("sram.address.physical"),
115
        (void *) sram_virt_addr,
116
        sysinfo_value("sram.area.size") / PAGE_SIZE,
117
        AS_AREA_READ | AS_AREA_WRITE
118
        );
119
    if (result != 0) {
120
        printf("SGCN: uspace driver could not map physical memory.");
121
    }
122
 
123
    sram_buffer_offset = sysinfo_value("sram.buffer.offset");
124
    ipc_register_irq(sysinfo_value("kbd.inr"), sysinfo_value("kbd.devno"),
125
        0, (void *) 0);
126
}
127
 
128
 
129
 
130
/**
131
 * Handler of the "key pressed" event. Reads codes of all the pressed keys from
132
 * the buffer.
133
 */
134
void sgcn_key_pressed(void)
135
{
136
    char c;
137
 
138
    uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
139
    uint32_t end = SGCN_BUFFER_HEADER->in_end;
140
    uint32_t size = end - begin;
141
 
142
    volatile char *buf_ptr = (volatile char *)
143
        SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
144
    volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr);
145
    volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr);
146
 
147
    while (*in_rdptr_ptr != *in_wrptr_ptr) {
148
        c = *buf_ptr;
149
        *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin;
150
        buf_ptr = (volatile char *)
151
            SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
152
        printf("Pressed character %c.\n", c);
153
        if (c == '\r') {
154
                        c = '\n';
155
                }
156
        //keybuffer_push(&keybuffer, c);
157
        kbd_process_no_fb(&keybuffer, c);
158
    }
159
}
160
 
161
/** @}
162
 */