Changeset 65fb232 in mainline


Ignore:
Timestamp:
2005-12-30T22:38:23Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ccb238
Parents:
80bff342
Message:

sparc64 work.
kconsole support.
Add non-blocking ofw_getchar().

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • arch/sparc64/include/console.h

    r80bff342 r65fb232  
    3030#define __sparc64_CONSOLE_H__
    3131
     32extern void kofwinput(void *arg);
    3233extern void ofw_sparc64_console_init(void);
    3334
  • arch/sparc64/src/console.c

    r80bff342 r65fb232  
    3333#include <arch/asm.h>
    3434#include <arch/register.h>
     35#include <arch/types.h>
     36#include <typedefs.h>
     37#include <proc/thread.h>
     38#include <synch/mutex.h>
    3539
    3640static void ofw_sparc64_putchar(chardev_t *d, const char ch);
     41static char ofw_sparc64_getchar(chardev_t *d);
     42static void ofw_sparc64_suspend(chardev_t *d);
     43static void ofw_sparc64_resume(chardev_t *d);
     44
     45mutex_t canwork;
    3746
    3847static chardev_t ofw_sparc64_console;
    3948static chardev_operations_t ofw_sparc64_console_ops = {
    40         .write = ofw_sparc64_putchar
     49        .write = ofw_sparc64_putchar,
     50        .read = ofw_sparc64_getchar,
     51        .resume = ofw_sparc64_resume,
     52        .suspend = ofw_sparc64_suspend
    4153};
    4254
     
    4456{
    4557        chardev_initialize("ofw_sparc64_console", &ofw_sparc64_console, &ofw_sparc64_console_ops);
     58        stdin = &ofw_sparc64_console;
    4659        stdout = &ofw_sparc64_console;
     60        mutex_initialize(&canwork);
    4761}
    4862
    49 /** Print one character.
     63/** Write one character.
    5064 *
    51  * @param ch Character to be printed.
     65 * @param d Character device (ignored).
     66 * @param ch Character to be written.
    5267 */
    5368void ofw_sparc64_putchar(chardev_t *d, const char ch)
     
    6984        pstate_write(pstate.value);
    7085}
     86
     87/** Read one character.
     88 *
     89 * The call is non-blocking.
     90 *
     91 * @param d Character device (ignored).
     92 * @return Character read or zero if no character was read.
     93 */
     94char ofw_sparc64_getchar(chardev_t *d)
     95{
     96        char ch;
     97        pstate_reg_t pstate;
     98
     99        /*
     100         * 32-bit OpenFirmware depends on PSTATE.AM bit set.
     101         */     
     102        pstate.value = pstate_read();
     103        pstate.am = true;
     104        pstate_write(pstate.value);
     105
     106        ch = ofw_getchar();
     107       
     108        pstate.am = false;
     109        pstate_write(pstate.value);
     110       
     111        return ch;
     112}
     113
     114void ofw_sparc64_suspend(chardev_t *d)
     115{
     116        mutex_lock(&canwork);
     117}
     118
     119void ofw_sparc64_resume(chardev_t *d)
     120{
     121        mutex_unlock(&canwork);
     122}
     123
     124/** Kernel thread for pushing characters read from OFW to input buffer.
     125 *
     126 * @param arg Ignored.
     127 */
     128void kofwinput(void *arg)
     129{
     130
     131        while (1) {
     132                char ch = 0;
     133               
     134                mutex_lock(&canwork);
     135                mutex_unlock(&canwork);
     136               
     137                ch = ofw_sparc64_getchar(NULL);
     138                if (ch) {
     139                        if (ch == '\r')
     140                                ch = '\n';
     141                        chardev_push_character(&ofw_sparc64_console, ch);
     142                }
     143                thread_usleep(25000);
     144        }
     145}
  • arch/sparc64/src/sparc64.c

    r80bff342 r65fb232  
    2828
    2929#include <arch.h>
    30 #include <print.h>
     30#include <debug.h>
    3131#include <arch/trap/trap.h>
    3232#include <arch/console.h>
    3333#include <arch/drivers/tick.h>
     34#include <proc/thread.h>
    3435
    3536void arch_pre_mm_init(void)
     
    5152void arch_post_smp_init(void)
    5253{
     54        thread_t *t;
     55       
     56        /*
     57         * Create thread that reads characters from OFW's input.
     58         */
     59        t = thread_create(kofwinput, NULL, TASK, 0);
     60        if (!t)
     61                panic("cannot create kofwinput\n");
     62        thread_ready(t);
    5363}
    5464
  • genarch/include/ofw/ofw.h

    r80bff342 r65fb232  
    5656extern __native ofw_call(const char *service, const int nargs, const int nret, ...);
    5757extern void ofw_putchar(const char ch);
     58extern char ofw_getchar(void);
    5859extern phandle ofw_find_device(const char *name);
    5960extern int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen);
  • genarch/src/ofw/ofw.c

    r80bff342 r65fb232  
    3636
    3737phandle ofw_chosen;
     38ihandle ofw_stdin;
    3839ihandle ofw_stdout;
    3940
     
    4445                ofw_done();
    4546       
     47        if (ofw_get_property(ofw_chosen, "stdin",  &ofw_stdin, sizeof(ofw_stdin)) <= 0)
     48                ofw_stdin = 0;
     49               
    4650        if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
    47                 ofw_stdout = 0;
     51                ofw_stdout = 0; 
    4852}
    4953
     
    8589}
    8690
     91/** Read character from OFW's input.
     92 *
     93 * This call is non-blocking.
     94 *
     95 * @return 0 if no character was read, character read otherwise.
     96 */
     97char ofw_getchar(void)
     98{
     99        char ch;
     100
     101        if (ofw_stdin == 0)
     102                return 0;
     103       
     104        if (ofw_call("read", 3, 1, ofw_stdin, &ch, 1) == 1)
     105                return ch;
     106        else
     107                return 0;
     108}
     109
    87110phandle ofw_find_device(const char *name)
    88111{
  • generic/include/console/chardev.h

    r80bff342 r65fb232  
    6464                               chardev_t *chardev,
    6565                               chardev_operations_t *op);
    66 void chardev_push_character(chardev_t *chardev, __u8 ch);
     66extern void chardev_push_character(chardev_t *chardev, __u8 ch);
    6767
    6868#endif /* __CHARDEV_H__ */
Note: See TracChangeset for help on using the changeset viewer.