Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4320 → Rev 4267

/trunk/kernel/arch/ppc32/src/ppc32.c
35,7 → 35,7
#include <config.h>
#include <arch.h>
#include <arch/boot/boot.h>
#include <genarch/drivers/via-cuda/cuda.h>
#include <arch/drivers/cuda.h>
#include <arch/interrupt.h>
#include <genarch/fb/fb.h>
#include <genarch/fb/visuals.h>
44,12 → 44,10
#include <console/console.h>
#include <ddi/irq.h>
#include <arch/drivers/pic.h>
#include <align.h>
#include <macros.h>
#include <string.h>
 
#define IRQ_COUNT 64
#define IRQ_CUDA 10
 
bootinfo_t bootinfo;
 
119,27 → 117,10
if (bootinfo.macio.addr) {
/* Initialize PIC */
cir_t cir;
void *cir_arg;
pic_init(bootinfo.macio.addr, PAGE_SIZE, &cir, &cir_arg);
pic_init(bootinfo.macio.addr, PAGE_SIZE);
#ifdef CONFIG_VIA_CUDA
uintptr_t pa = bootinfo.macio.addr + 0x16000;
uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
size_t offset = pa - aligned_addr;
size_t size = 2 * PAGE_SIZE;
cuda_t *cuda = (cuda_t *)
(hw_map(aligned_addr, offset + size) + offset);
/* Initialize I/O controller */
cuda_instance_t *cuda_instance =
cuda_init(cuda, IRQ_CUDA, cir, cir_arg);
if (cuda_instance) {
indev_t *sink = stdin_wire();
cuda_wire(cuda_instance, sink);
}
#endif
cuda_init(bootinfo.macio.addr + 0x16000, 2 * PAGE_SIZE);
}
/* Merge all zones to 1 big zone */
205,11 → 186,5
return addr;
}
 
void arch_reboot(void)
{
// TODO
while (1);
}
 
/** @}
*/
/trunk/kernel/arch/ppc32/src/drivers/cuda.c
0,0 → 1,260
/*
* Copyright (c) 2006 Martin Decky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup ppc32
* @{
*/
/** @file
*/
 
#include <arch/drivers/cuda.h>
#include <arch/asm.h>
#include <console/console.h>
#include <console/chardev.h>
#include <arch/drivers/pic.h>
#include <sysinfo/sysinfo.h>
#include <interrupt.h>
#include <stdarg.h>
#include <ddi/device.h>
#include <string.h>
 
#define CUDA_IRQ 10
 
#define PACKET_ADB 0x00
#define PACKET_CUDA 0x01
 
#define CUDA_POWERDOWN 0x0a
#define CUDA_RESET 0x11
 
#define RS 0x200
#define B (0 * RS)
#define A (1 * RS)
#define SR (10 * RS)
#define ACR (11 * RS)
 
#define SR_OUT 0x10
#define TACK 0x10
#define TIP 0x20
 
#define SCANCODES 128
 
static volatile uint8_t *cuda = NULL;
static irq_t cuda_irq; /**< Cuda's IRQ. */
 
static wchar_t lchars[SCANCODES] = {
'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v',
U_SPECIAL,
'b', 'q', 'w', 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5',
'=', '9', '7', '-', '8', '0', ']', 'o', 'u', '[', 'i', 'p',
'\n', /* Enter */
'l', 'j', '\'', 'k', ';', '\\', ',', '/', 'n', 'm', '.',
'\t', /* Tab */
' ', '`',
'\b', /* Backspace */
U_SPECIAL,
U_ESCAPE, /* Escape */
U_SPECIAL, /* Ctrl */
U_SPECIAL, /* Alt */
U_SPECIAL, /* Shift */
U_SPECIAL, /* CapsLock */
U_SPECIAL, /* Right Alt */
U_LEFT_ARROW, /* Left */
U_RIGHT_ARROW, /* Right */
U_DOWN_ARROW, /* Down */
U_UP_ARROW, /* Up */
U_SPECIAL,
U_SPECIAL,
'.', /* Keypad . */
U_SPECIAL,
'*', /* Keypad * */
U_SPECIAL,
'+', /* Keypad + */
U_SPECIAL,
U_SPECIAL, /* NumLock */
U_SPECIAL,
U_SPECIAL,
U_SPECIAL,
'/', /* Keypad / */
'\n', /* Keypad Enter */
U_SPECIAL,
'-', /* Keypad - */
U_SPECIAL,
U_SPECIAL,
U_SPECIAL,
'0', /* Keypad 0 */
'1', /* Keypad 1 */
'2', /* Keypad 2 */
'3', /* Keypad 3 */
'4', /* Keypad 4 */
'5', /* Keypad 5 */
'6', /* Keypad 6 */
'7', /* Keypad 7 */
U_SPECIAL,
'8', /* Keypad 8 */
'9', /* Keypad 9 */
U_SPECIAL,
U_SPECIAL,
U_SPECIAL,
U_SPECIAL, /* F5 */
U_SPECIAL, /* F6 */
U_SPECIAL, /* F7 */
U_SPECIAL, /* F3 */
U_SPECIAL, /* F8 */
U_SPECIAL, /* F9 */
U_SPECIAL,
U_SPECIAL, /* F11 */
U_SPECIAL,
U_SPECIAL, /* F13 */
U_SPECIAL,
U_SPECIAL, /* ScrollLock */
U_SPECIAL,
U_SPECIAL, /* F10 */
U_SPECIAL,
U_SPECIAL, /* F12 */
U_SPECIAL,
U_SPECIAL, /* Pause */
U_SPECIAL, /* Insert */
U_HOME_ARROW, /* Home */
U_PAGE_UP, /* Page Up */
U_DELETE, /* Delete */
U_SPECIAL, /* F4 */
U_END_ARROW, /* End */
U_SPECIAL, /* F2 */
U_PAGE_DOWN, /* Page Down */
U_SPECIAL /* F1 */
};
 
static void receive_packet(uint8_t *kind, index_t count, uint8_t data[])
{
cuda[B] = cuda[B] & ~TIP;
*kind = cuda[SR];
index_t i;
for (i = 0; i < count; i++)
data[i] = cuda[SR];
cuda[B] = cuda[B] | TIP;
}
 
static indev_t kbrd;
static indev_operations_t ops = {
.poll = NULL
};
 
int cuda_get_scancode(void)
{
if (cuda) {
uint8_t kind;
uint8_t data[4];
receive_packet(&kind, 4, data);
if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c))
return data[2];
}
return -1;
}
 
static void cuda_irq_handler(irq_t *irq)
{
int scan_code = cuda_get_scancode();
if (scan_code != -1) {
uint8_t scancode = (uint8_t) scan_code;
if ((scancode & 0x80) != 0x80)
indev_push_character(&kbrd, lchars[scancode & 0x7f]);
}
}
 
static irq_ownership_t cuda_claim(irq_t *irq)
{
return IRQ_ACCEPT;
}
 
void cuda_init(uintptr_t base, size_t size)
{
cuda = (uint8_t *) hw_map(base, size);
indev_initialize("cuda_kbd", &kbrd, &ops);
stdin = &kbrd;
irq_initialize(&cuda_irq);
cuda_irq.devno = device_assign_devno();
cuda_irq.inr = CUDA_IRQ;
cuda_irq.claim = cuda_claim;
cuda_irq.handler = cuda_irq_handler;
irq_register(&cuda_irq);
pic_enable_interrupt(CUDA_IRQ);
sysinfo_set_item_val("kbd", NULL, true);
sysinfo_set_item_val("kbd.inr", NULL, CUDA_IRQ);
sysinfo_set_item_val("kbd.address.virtual", NULL, base);
}
 
static void send_packet(const uint8_t kind, count_t count, ...)
{
index_t i;
va_list va;
cuda[B] = cuda[B] | TIP;
cuda[ACR] = cuda[ACR] | SR_OUT;
cuda[SR] = kind;
cuda[B] = cuda[B] & ~TIP;
va_start(va, count);
for (i = 0; i < count; i++) {
cuda[ACR] = cuda[ACR] | SR_OUT;
cuda[SR] = va_arg(va, int);
cuda[B] = cuda[B] | TACK;
}
va_end(va);
cuda[B] = cuda[B] | TIP;
}
 
void cpu_halt(void) {
asm volatile (
"b 0\n"
);
}
 
void arch_reboot(void) {
if (cuda)
send_packet(PACKET_CUDA, 1, CUDA_RESET);
asm volatile (
"b 0\n"
);
}
 
/** @}
*/
/trunk/kernel/arch/ppc32/src/drivers/pic.c
26,7 → 26,7
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup ppc32
/** @addtogroup ppc32
* @{
*/
/** @file
40,14 → 40,12
 
static volatile uint32_t *pic = NULL;
 
void pic_init(uintptr_t base, size_t size, cir_t *cir, void **cir_arg)
void pic_init(uintptr_t base, size_t size)
{
pic = (uint32_t *) hw_map(base, size);
*cir = pic_ack_interrupt;
*cir_arg = NULL;
}
 
void pic_enable_interrupt(inr_t intnum)
void pic_enable_interrupt(int intnum)
{
if (pic) {
if (intnum < 32)
58,7 → 56,7
}
 
void pic_disable_interrupt(inr_t intnum)
void pic_disable_interrupt(int intnum)
{
if (pic) {
if (intnum < 32)
68,7 → 66,7
}
}
 
void pic_ack_interrupt(void *arg, inr_t intnum)
void pic_ack_interrupt(int intnum)
{
if (pic) {
if (intnum < 32)
/trunk/kernel/arch/ppc32/src/interrupt.c
60,6 → 60,7
int inum;
while ((inum = pic_get_pending()) != -1) {
bool ack = false;
irq_t *irq = irq_dispatch_and_lock(inum);
if (irq) {
/*
68,17 → 69,11
if (irq->preack) {
/* Acknowledge the interrupt before processing */
if (irq->cir)
irq->cir(irq->cir_arg, irq->inr);
pic_ack_interrupt(inum);
ack = true;
}
irq->handler(irq);
if (!irq->preack) {
if (irq->cir)
irq->cir(irq->cir_arg, irq->inr);
}
spinlock_unlock(&irq->lock);
} else {
/*
88,6 → 83,9
printf("cpu%u: spurious interrupt (inum=%d)\n", CPU->id, inum);
#endif
}
if (!ack)
pic_ack_interrupt(inum);
}
}
 
/trunk/kernel/arch/ppc32/src/dummy.s
30,7 → 30,6
 
.global asm_delay_loop
.global sys_tls_set
.global cpu_halt
 
sys_tls_set:
b sys_tls_set
37,6 → 36,3
 
asm_delay_loop:
blr
 
cpu_halt:
b cpu_halt