Changeset 432a269 in mainline for uspace/srv/hid/fb/port/niagara.c


Ignore:
Timestamp:
2011-09-16T21:13:57Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3a11f17
Parents:
c0e53ff (diff), fd07e526 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/fb/port/niagara.c

    rc0e53ff r432a269  
    2929 */
    3030
    31 /** @defgroup niagarafb
    32  * @brief       userland driver of the Niagara console output
    33  * @{
    34  */
    3531/** @file
    3632 */
    3733
    38 #include <async.h>
     34#include <sys/types.h>
     35#include <errno.h>
    3936#include <sysinfo.h>
     37#include <ddi.h>
    4038#include <as.h>
    41 #include <errno.h>
    42 #include <stdio.h>
    43 #include <ddi.h>
    44 
    45 #include "serial_console.h"
     39#include <align.h>
     40#include "../ctl/serial.h"
    4641#include "niagara.h"
    4742
    48 #define WIDTH 80
    49 #define HEIGHT 24
     43#define OUTPUT_FIFO_SIZE  ((PAGE_SIZE) - 2 * sizeof(uint64_t))
    5044
    51 /**
    52  * Virtual address mapped to the buffer shared with the kernel counterpart.
    53  */
    54 static uintptr_t output_buffer_addr;
    55 
    56 /*
    57  * Kernel counterpart of the driver reads characters to be printed from here.
    58  * Keep in sync with the definition from
    59  * kernel/arch/sparc64/src/drivers/niagara.c.
    60  */
    61 #define OUTPUT_BUFFER_SIZE      ((PAGE_SIZE) - 2 * 8)
    6245typedef volatile struct {
    6346        uint64_t read_ptr;
    6447        uint64_t write_ptr;
    65         char data[OUTPUT_BUFFER_SIZE];
    66 }
    67         __attribute__ ((packed))
    68         __attribute__ ((aligned(PAGE_SIZE)))
    69         *output_buffer_t;
     48        char data[OUTPUT_FIFO_SIZE];
     49} __attribute__((packed)) output_fifo_t;
    7050
    71 output_buffer_t output_buffer;
     51typedef struct {
     52        output_fifo_t *fifo;
     53} niagara_t;
    7254
    73 /**
    74  * Pushes the character to the Niagara serial.
    75  * @param c     character to be pushed
    76  */
    77 static void niagara_putc(char c)
     55static niagara_t niagara;
     56
     57static void niagara_putc(const char c)
    7858{
    79         while (output_buffer->write_ptr ==
    80                (output_buffer->read_ptr + OUTPUT_BUFFER_SIZE - 1)
    81                % OUTPUT_BUFFER_SIZE)
    82                 ;
    83         output_buffer->data[output_buffer->write_ptr] = (uint64_t) c;
    84         output_buffer->write_ptr =
    85                 ((output_buffer->write_ptr) + 1) % OUTPUT_BUFFER_SIZE;
     59        while (niagara.fifo->write_ptr ==
     60            (niagara.fifo->read_ptr + OUTPUT_FIFO_SIZE - 1)
     61            % OUTPUT_FIFO_SIZE);
     62       
     63        niagara.fifo->data[niagara.fifo->write_ptr] = c;
     64        niagara.fifo->write_ptr =
     65            ((niagara.fifo->write_ptr) + 1) % OUTPUT_FIFO_SIZE;
    8666}
    8767
    88 /**
    89  * Initializes the Niagara serial driver.
    90  */
     68static void niagara_putchar(wchar_t ch)
     69{
     70        if ((ch >= 0) && (ch < 128))
     71                niagara_putc(ch);
     72        else
     73                niagara_putc('?');
     74}
     75
     76static void niagara_control_puts(const char *str)
     77{
     78        while (*str)
     79                niagara_putc(*(str++));
     80}
     81
    9182int niagara_init(void)
    9283{
     84        sysarg_t present;
     85        int rc = sysinfo_get_value("fb", &present);
     86        if (rc != EOK)
     87                present = false;
     88       
     89        if (!present)
     90                return ENOENT;
     91       
     92        sysarg_t kind;
     93        rc = sysinfo_get_value("fb.kind", &kind);
     94        if (rc != EOK)
     95                kind = (sysarg_t) -1;
     96       
     97        if (kind != 5)
     98                return EINVAL;
     99       
    93100        sysarg_t paddr;
    94         if (sysinfo_get_value("niagara.outbuf.address", &paddr) != EOK)
    95                 return -1;
     101        rc = sysinfo_get_value("niagara.outbuf.address", &paddr);
     102        if (rc != EOK)
     103                return rc;
    96104       
    97         output_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE);
    98         int result = physmem_map((void *) paddr,
    99             (void *) output_buffer_addr, 1,
     105        niagara.fifo =
     106            (output_fifo_t *) as_get_mappable_page(sizeof(output_fifo_t));
     107        if (niagara.fifo == NULL)
     108                return ENOMEM;
     109       
     110        rc = physmem_map((void *) paddr, (void *) niagara.fifo, 1,
    100111            AS_AREA_READ | AS_AREA_WRITE);
    101 
    102         if (result != 0) {
    103                 printf("Niagara: uspace driver couldn't map physical memory: %d\n",
    104                         result);
    105         }
    106 
    107         output_buffer = (output_buffer_t) output_buffer_addr;
    108 
    109         serial_console_init(niagara_putc, WIDTH, HEIGHT);
    110         async_set_client_connection(serial_client_connection);
    111         return 0;
     112        if (rc != EOK)
     113                return rc;
     114       
     115        return serial_init(niagara_putchar, niagara_control_puts);
    112116}
    113117
    114 /**
    115  * @}
     118/** @}
    116119 */
    117  
Note: See TracChangeset for help on using the changeset viewer.