Changeset 86018c1 in mainline


Ignore:
Timestamp:
2010-01-24T19:48:56Z (14 years ago)
Author:
Pavel Rimsky <pavel@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8e33e1d
Parents:
eeb643d
Message:

Implemented uspace keyboard driver. Cleanup needed.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • defaults/sparc64/sun4v/Makefile.config

    reeb643d r86018c1  
    77CONFIG_RD_EXTERNAL = n
    88
    9 CONFIG_LOG = y
     9# CONFIG_LOG = y
    1010
    1111CONFIG_SMP = n
  • kernel/arch/sparc64/src/drivers/niagara.c

    reeb643d r86018c1  
    5454#define POLL_INTERVAL  10000
    5555
    56 /**
    57  * The driver is polling based, but in order to notify the userspace
    58  * of a key being pressed, we need to supply the interface with some
    59  * interrupt number. The interrupt number can be arbitrary as it it
    60  * will never be used for identifying HW interrupts, but only in
    61  * notifying the userspace.
    62  */
    63 #define FICTIONAL_INR           1
    64 
    65 
    6656static niagara_instance_t *instance = NULL;
    6757
     
    9585        output_buffer;
    9686
    97 #if 0
    98 /** Niagara character device */
    99 chardev_t niagara_io;
    100 
    101 /** defined in drivers/kbd.c */
    102 extern kbd_type_t kbd_type;
    103 
    104 /**
    105  * The character read will be stored here until the (notified) uspace
    106  * driver picks it up.
    107  */
    108 static char read_char;
    109 
    110 
    111 #endif
     87/**
     88 * Analogous to the output_buffer, see the previous definition.
     89 */
     90#define INPUT_BUFFER_SIZE       ((PAGE_SIZE) - 2 * 8)
     91static volatile struct {
     92        uint64_t write_ptr;
     93        uint64_t read_ptr;
     94        char data[INPUT_BUFFER_SIZE];
     95}
     96        __attribute__ ((packed))
     97        __attribute__ ((aligned(PAGE_SIZE)))
     98        input_buffer;
     99
    112100
    113101/** Writes a single character to the standard output. */
     
    126114}
    127115
    128 #if 0
    129 /**
    130  * Grabs the input for kernel.
    131  */
    132 void niagara_grab(void)
    133 {
    134         ipl_t ipl = interrupts_disable();
    135         spinlock_lock(&niagara_irq.lock);
    136         niagara_irq.notif_cfg.notify = false;
    137         spinlock_unlock(&niagara_irq.lock);
    138         interrupts_restore(ipl);
    139 }
    140 
    141 /**
    142  * Releases the input so that userspace can use it.
    143  */
    144 void niagara_release(void)
    145 {
    146         ipl_t ipl = interrupts_disable();
    147         spinlock_lock(&niagara_irq.lock);
    148         if (niagara_irq.notif_cfg.answerbox)
    149                 niagara_irq.notif_cfg.notify = true;
    150         spinlock_unlock(&niagara_irq.lock);
    151         interrupts_restore(ipl);
    152 }
    153 
    154 /**
    155  * Default suspend/resume operation for the input device.
    156  */
    157 static void niagara_noop(chardev_t *d)
    158 {
    159 }
    160 
    161 /**
    162  * Called when actively reading the character.
    163  */
    164 static char niagara_read(chardev_t *d)
    165 {
    166         uint64_t c;
    167 
    168         if (__hypercall_fast_ret1(0, 0, 0, 0, 0, CONS_GETCHAR, &c) == EOK) {
    169                 return (char) c;
    170         }
    171 
    172         return '\0';
    173 }
    174 
    175 /**
    176  * Returns the character last read. This function is called from the
    177  * pseudocode - the character returned by this function is passed to
    178  * the userspace keyboard driver.
    179  */
    180 char niagara_getc(void) {
    181         return read_char;
    182 }
    183 
    184 #endif
    185 
    186116/**
    187117 * Function regularly called by the keyboard polling thread. Asks the
    188118 * hypervisor whether there is any unread character. If so, it picks it up
    189119 * and sends it to the upper layers of HelenOS.
     120 *
     121 * Apart from that, it also checks whether the userspace output driver has
     122 * pushed any characters to the output buffer. If so, it prints them.
    190123 */
    191124static void niagara_poll(niagara_instance_t *instance)
     
    200133
    201134        if (__hypercall_fast_ret1(0, 0, 0, 0, 0, CONS_GETCHAR, &c) == EOK) {
    202                 indev_push_character(instance->srlnin, c);
     135                if (!silent) {
     136                        indev_push_character(instance->srlnin, c);
     137                } else {
     138                        input_buffer.data[input_buffer.write_ptr] = (char) c;
     139                        input_buffer.write_ptr =
     140                                ((input_buffer.write_ptr) + 1) % INPUT_BUFFER_SIZE;
     141                }
    203142        }
    204143
     
    210149static void kniagarapoll(void *instance) {
    211150        while (true) {
    212                 //MH
    213                 //if (!silent)
    214                         niagara_poll(instance);
    215                
     151                niagara_poll(instance);
    216152                thread_usleep(POLL_INTERVAL);
    217153        }
     
    245181        /*
    246182         * Set sysinfos and pareas so that the userspace counterpart of the
    247          * niagara fb driver can communicate with kernel using a shared buffer.
     183         * niagara fb and kbd driver can communicate with kernel using shared
     184         * buffers.
    248185         */
    249186        output_buffer.read_ptr = 0;
    250187        output_buffer.write_ptr = 0;
     188        input_buffer.write_ptr = 0;
     189        input_buffer.read_ptr = 0;
    251190
    252191        sysinfo_set_item_val("niagara.outbuf.address", NULL,
     
    257196                OUTPUT_BUFFER_SIZE);
    258197
     198        sysinfo_set_item_val("niagara.inbuf.address", NULL,
     199                KA2PA(&input_buffer));
     200        sysinfo_set_item_val("niagara.inbuf.size", NULL,
     201                PAGE_SIZE);
     202        sysinfo_set_item_val("niagara.inbuf.datasize", NULL,
     203                INPUT_BUFFER_SIZE);
     204
    259205        static parea_t outbuf_parea;
    260206        outbuf_parea.pbase = (uintptr_t) (KA2PA(&output_buffer));
     
    262208        ddi_parea_register(&outbuf_parea);
    263209
    264         #if 0
    265         kbd_type = KBD_SUN4V;
    266 
    267         devno_t devno = device_assign_devno();
    268         irq_initialize(&niagara_irq);
    269         niagara_irq.devno = devno;
    270         niagara_irq.inr = FICTIONAL_INR;
    271         niagara_irq.claim = niagara_claim;
    272         niagara_irq.handler = niagara_irq_handler;
    273         irq_register(&niagara_irq);
    274        
    275         sysinfo_set_item_val("kbd", NULL, true);
    276         sysinfo_set_item_val("kbd.type", NULL, KBD_SUN4V);
    277         sysinfo_set_item_val("kbd.devno", NULL, devno);
    278         sysinfo_set_item_val("kbd.inr", NULL, FICTIONAL_INR);
    279         #endif
    280 
    281         /*
    282          * Set sysinfos and pareas so that the userspace counterpart of the
    283          * niagara fb driver can communicate with kernel using a shared buffer.
    284          */
    285         //output_buffer.read_ptr = 0;
    286         //output_buffer.write_ptr = 0;
    287 
    288         #if 0
    289         sysinfo_set_item_val("niagara.outbuf.address", NULL,
    290                 KA2PA(&output_buffer));
    291         sysinfo_set_item_val("niagara.outbuf.size", NULL,
    292                 PAGE_SIZE);
    293         sysinfo_set_item_val("niagara.outbuf.datasize", NULL,
    294                 OUTPUT_BUFFER_SIZE);
    295         static parea_t outbuf_parea;
    296         outbuf_parea.pbase = (uintptr_t) (KA2PA(&output_buffer));
    297         outbuf_parea.vbase = (uintptr_t) (&output_buffer);
    298         outbuf_parea.frames = 1;
    299         outbuf_parea.cacheable = false;
    300         ddi_parea_register(&outbuf_parea);
    301 
    302         #endif
     210        static parea_t inbuf_parea;
     211        inbuf_parea.pbase = (uintptr_t) (KA2PA(&input_buffer));
     212        inbuf_parea.frames = 1;
     213        ddi_parea_register(&inbuf_parea);
    303214
    304215        outdev_t *niagara_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
  • uspace/lib/libc/arch/sparc64/src/thread_entry.s

    reeb643d r86018c1  
    3838        # Create the first stack frame.
    3939        #
    40         save %sp, -176, %sp
    41         flushw
    42         add %g0, -0x7ff, %fp
     40
     41        # MH
     42        #save %sp, -176, %sp
     43        #flushw
     44        #add %g0, -0x7ff, %fp
    4345
    4446        sethi %hi(_gp), %l7
  • uspace/lib/libc/generic/thread.c

    reeb643d r86018c1  
    4141#include <string.h>
    4242#include <async.h>
     43#include <stdio.h>
    4344
    4445#ifndef THREAD_INITIAL_STACK_PAGES_NO
     
    6263        __tcb_set(f->tcb);
    6364
     65        // MH
     66        printf("uarg: %lx\n", uarg);
    6467        uarg->uspace_thread_function(uarg->uspace_thread_arg);
    6568        /* XXX: we cannot free the userspace stack while running on it */
  • uspace/srv/hid/kbd/port/niagara.c

    reeb643d r86018c1  
    4747#define POLL_INTERVAL           10000
    4848
     49/**
     50 * Virtual address mapped to the buffer shared with the kernel counterpart.
     51 */
     52static uintptr_t input_buffer_addr;
     53
     54/*
     55 * Kernel counterpart of the driver pushes characters (it has read) here.
     56 * Keep in sync with the definition from
     57 * kernel/arch/sparc64/src/drivers/niagara.c.
     58 */
     59#define INPUT_BUFFER_SIZE       ((PAGE_SIZE) - 2 * 8)
     60typedef volatile struct {
     61        uint64_t write_ptr;
     62        uint64_t read_ptr;
     63        char data[INPUT_BUFFER_SIZE];
     64}
     65        __attribute__ ((packed))
     66        __attribute__ ((aligned(PAGE_SIZE)))
     67        *input_buffer_t;
     68
     69input_buffer_t input_buffer;
     70
    4971static volatile bool polling_disabled = false;
    50 //static void *niagara_thread_impl(void *arg);
     72static void *niagara_thread_impl(void *arg);
    5173
    5274/**
     
    5678int kbd_port_init(void)
    5779{
    58         printf("****************** Niagara keyboard driver **********************\n");
    59         /*
     80        input_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE);
     81        int result = physmem_map(
     82                (void *) sysinfo_value("niagara.inbuf.address"),
     83                (void *) input_buffer_addr,
     84                1, AS_AREA_READ | AS_AREA_WRITE);
     85
     86        if (result != 0) {
     87                printf("Niagara: uspace driver couldn't map physical memory: %d\n",
     88                        result);
     89        }
     90
     91        input_buffer = (input_buffer_t) input_buffer_addr;
     92
    6093        thread_id_t tid;
    6194        int rc;
     
    6598                return rc;
    6699        }
    67         */
    68100        return 0;
    69101}
     
    90122static void niagara_key_pressed(void)
    91123{
    92         printf("%s\n", "polling");
    93 /*
    94124        char c;
    95125       
    96         uint32_t begin = SGCN_BUFFER_HEADER->in_begin;
    97         uint32_t end = SGCN_BUFFER_HEADER->in_end;
    98         uint32_t size = end - begin;
    99        
    100         volatile char *buf_ptr = (volatile char *)
    101                 SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
    102         volatile uint32_t *in_wrptr_ptr = &(SGCN_BUFFER_HEADER->in_wrptr);
    103         volatile uint32_t *in_rdptr_ptr = &(SGCN_BUFFER_HEADER->in_rdptr);
    104        
    105         while (*in_rdptr_ptr != *in_wrptr_ptr) {
    106                 c = *buf_ptr;
    107                 *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin;
    108                 buf_ptr = (volatile char *)
    109                         SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
     126        while (input_buffer->read_ptr != input_buffer->write_ptr) {
     127                c = input_buffer->data[input_buffer->read_ptr];
     128                input_buffer->read_ptr =
     129                        ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
    110130                kbd_push_scancode(c);
    111131        }
    112 */
    113132}
    114133
     
    116135 * Thread to poll SGCN for keypresses.
    117136 */
    118 /*
    119137static void *niagara_thread_impl(void *arg)
    120138{
     
    128146        return 0;
    129147}
    130 */
    131148/** @}
    132149 */
Note: See TracChangeset for help on using the changeset viewer.