source: mainline/kernel/arch/mips32/src/drivers/msim.c@ e78136a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e78136a was 0c33687a, checked in by Jakub Jermar <jakub@…>, 17 years ago

Unbreak mips32 candidate.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[a7fdfe1]1/*
[df4ed85]2 * Copyright (c) 2005 Ondrej Palkovsky
[a7fdfe1]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
[516ff92]29/** @addtogroup mips32
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[973be64e]35#include <interrupt.h>
[2677758]36#include <console/chardev.h>
[973be64e]37#include <arch/drivers/msim.h>
[a7fdfe1]38#include <arch/cp0.h>
[af9a7c5]39#include <console/console.h>
[7688b5d]40#include <sysinfo/sysinfo.h>
[113c677]41#include <ddi/ddi.h>
[7688b5d]42
[973be64e]43static chardev_t console;
[7688b5d]44static irq_t msim_irq;
[607c5f9]45
[b7c4044]46static void msim_write(chardev_t *dev, const char ch, bool silent);
[973be64e]47static void msim_enable(chardev_t *dev);
48static void msim_disable(chardev_t *dev);
[93b84b3]49static char msim_do_read(chardev_t *dev);
[ac0cb2a]50
51static chardev_operations_t msim_ops = {
[973be64e]52 .resume = msim_enable,
53 .suspend = msim_disable,
[93b84b3]54 .write = msim_write,
55 .read = msim_do_read,
[607c5f9]56};
[2677758]57
[973be64e]58/** Putchar that works with MSIM & gxemul */
[516ff92]59void msim_write(chardev_t *dev, const char ch, bool silent)
[a7fdfe1]60{
[516ff92]61 if (!silent)
62 *((char *) MSIM_VIDEORAM) = ch;
[a7fdfe1]63}
64
[973be64e]65/* Called from getc(). */
66void msim_enable(chardev_t *dev)
[a7fdfe1]67{
[973be64e]68 cp0_unmask_int(MSIM_KBD_IRQ);
[2677758]69}
70
71/* Called from getc(). */
[973be64e]72void msim_disable(chardev_t *dev)
[2677758]73{
[973be64e]74 cp0_mask_int(MSIM_KBD_IRQ);
[a7fdfe1]75}
[607c5f9]76
[93b84b3]77/** Read character using polling, assume interrupts disabled */
78static char msim_do_read(chardev_t *dev)
79{
80 char ch;
[516ff92]81
[93b84b3]82 while (1) {
83 ch = *((volatile char *) MSIM_KBD_ADDRESS);
84 if (ch) {
85 if (ch == '\r')
86 return '\n';
87 if (ch == 0x7f)
88 return '\b';
89 return ch;
90 }
91 }
92}
93
[973be64e]94/** Process keyboard interrupt. */
[6cd9aa6]95static void msim_irq_handler(irq_t *irq)
[607c5f9]96{
[0c33687a]97 char ch = 0;
[7688b5d]98
[0c33687a]99 ch = *((char *) MSIM_KBD_ADDRESS);
100 if (ch =='\r')
101 ch = '\n';
102 if (ch == 0x7f)
103 ch = '\b';
104 chardev_push_character(&console, ch);
[607c5f9]105}
[ac0cb2a]106
[c9b550b]107static irq_ownership_t msim_claim(irq_t *irq)
[ac0cb2a]108{
[7688b5d]109 return IRQ_ACCEPT;
[ac0cb2a]110}
[41d33ac]111
112void msim_kbd_grab(void)
113{
[3dea17f]114 ipl_t ipl = interrupts_disable();
115 spinlock_lock(&msim_irq.lock);
[7688b5d]116 msim_irq.notif_cfg.notify = false;
[3dea17f]117 spinlock_unlock(&msim_irq.lock);
118 interrupts_restore(ipl);
[41d33ac]119}
[7688b5d]120
[41d33ac]121void msim_kbd_release(void)
122{
[3dea17f]123 ipl_t ipl = interrupts_disable();
124 spinlock_lock(&msim_irq.lock);
[7688b5d]125 if (msim_irq.notif_cfg.answerbox)
126 msim_irq.notif_cfg.notify = true;
[3dea17f]127 spinlock_unlock(&msim_irq.lock);
128 interrupts_restore(ipl);
[7688b5d]129}
130
131
132/* Return console object representing msim console */
133void msim_console(devno_t devno)
134{
135 chardev_initialize("msim_console", &console, &msim_ops);
136 stdin = &console;
137 stdout = &console;
138
139 irq_initialize(&msim_irq);
140 msim_irq.devno = devno;
141 msim_irq.inr = MSIM_KBD_IRQ;
142 msim_irq.claim = msim_claim;
143 msim_irq.handler = msim_irq_handler;
144 irq_register(&msim_irq);
145
146 cp0_unmask_int(MSIM_KBD_IRQ);
147
148 sysinfo_set_item_val("kbd", NULL, true);
149 sysinfo_set_item_val("kbd.devno", NULL, devno);
150 sysinfo_set_item_val("kbd.inr", NULL, MSIM_KBD_IRQ);
151 sysinfo_set_item_val("kbd.address.virtual", NULL, MSIM_KBD_ADDRESS);
[113c677]152
153 sysinfo_set_item_val("fb", NULL, true);
154 sysinfo_set_item_val("fb.kind", NULL, 3);
155 sysinfo_set_item_val("fb.address.physical", NULL, KA2PA(MSIM_VIDEORAM));
[41d33ac]156}
[b45c443]157
[06e1e95]158/** @}
[b45c443]159 */
Note: See TracBrowser for help on using the repository browser.