Changeset 7de5f12 in mainline


Ignore:
Timestamp:
2017-11-15T20:23:50Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ac1243d, 7f4937e
Parents:
e7a8bd2
Message:

MSIM console driver can use hw_res instead of sysinfo for configuration.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/mips32/src/mach/msim/msim.c

    re7a8bd2 r7de5f12  
    105105                }
    106106        }
    107        
    108         /*
    109          * This is the necessary evil until the userspace driver is entirely
    110          * self-sufficient.
    111          */
    112         sysinfo_set_item_val("kbd", NULL, true);
    113         sysinfo_set_item_val("kbd.inr", NULL, MSIM_KBD_IRQ);
    114         sysinfo_set_item_val("kbd.address.physical", NULL,
    115             PA2KA(MSIM_KBD_ADDRESS));
    116107#endif
    117108}
  • uspace/drv/char/msim-con/main.c

    re7a8bd2 r7de5f12  
    3535#include <ddf/driver.h>
    3636#include <ddf/log.h>
     37#include <device/hw_res_parsed.h>
    3738#include <errno.h>
    3839#include <stdio.h>
     
    6162};
    6263
     64static int msim_con_get_res(ddf_dev_t *dev, msim_con_res_t *res)
     65{
     66        async_sess_t *parent_sess;
     67        hw_res_list_parsed_t hw_res;
     68        int rc;
     69
     70        parent_sess = ddf_dev_parent_sess_get(dev);
     71        if (parent_sess == NULL)
     72                return ENOMEM;
     73
     74        hw_res_list_parsed_init(&hw_res);
     75        rc = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
     76        if (rc != EOK)
     77                return rc;
     78
     79        if (hw_res.mem_ranges.count != 1) {
     80                rc = EINVAL;
     81                goto error;
     82        }
     83
     84        res->base = RNGABS(hw_res.mem_ranges.ranges[0]);
     85
     86        if (hw_res.irqs.count != 1) {
     87                rc = EINVAL;
     88                goto error;
     89        }
     90
     91        res->irq = hw_res.irqs.irqs[0];
     92
     93        return EOK;
     94error:
     95        hw_res_list_parsed_clean(&hw_res);
     96        return rc;
     97}
     98
    6399static int msim_con_dev_add(ddf_dev_t *dev)
    64100{
    65101        msim_con_t *msim_con;
     102        msim_con_res_t res;
     103        int rc;
    66104
    67105        ddf_msg(LVL_DEBUG, "msim_con_dev_add(%p)", dev);
     106
    68107        msim_con = ddf_dev_data_alloc(dev, sizeof(msim_con_t));
    69108        if (msim_con == NULL) {
     
    74113        msim_con->dev = dev;
    75114
    76         return msim_con_add(msim_con);
     115        rc = msim_con_get_res(dev, &res);
     116        if (rc != EOK) {
     117                ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n");
     118                return EIO;
     119        }
     120
     121        return msim_con_add(msim_con, &res);
    77122}
    78123
  • uspace/drv/char/msim-con/msim-con.c

    re7a8bd2 r7de5f12  
    3838#include <errno.h>
    3939#include <ipc/char.h>
    40 #include <sysinfo.h>
    4140
    4241#include "msim-con.h"
     
    8483
    8584/** Add msim console device. */
    86 int msim_con_add(msim_con_t *con)
     85int msim_con_add(msim_con_t *con, msim_con_res_t *res)
    8786{
    8887        ddf_fun_t *fun = NULL;
    8988        bool subscribed = false;
    9089        int rc;
     90
     91        con->res = *res;
    9192
    9293        fun = ddf_fun_create(con->dev, fun_exposed, "a");
     
    99100        ddf_fun_set_conn_handler(fun, msim_con_connection);
    100101
    101         sysarg_t paddr;
    102         if (sysinfo_get_value("kbd.address.physical", &paddr) != EOK) {
    103                 rc = ENOENT;
    104                 goto error;
    105         }
    106 
    107         sysarg_t inr;
    108         if (sysinfo_get_value("kbd.inr", &inr) != EOK) {
    109                 rc = ENOENT;
    110                 goto error;
    111         }
    112 
    113         msim_ranges[0].base = paddr;
    114         msim_cmds[0].addr = (void *) paddr;
    115         async_irq_subscribe(inr, msim_irq_handler, con, &msim_kbd);
     102        msim_ranges[0].base = res->base;
     103        msim_cmds[0].addr = (void *) res->base;
     104        async_irq_subscribe(res->irq, msim_irq_handler, con, &msim_kbd);
    116105        subscribed = true;
    117106
     
    125114error:
    126115        if (subscribed)
    127                 async_irq_unsubscribe(inr);
     116                async_irq_unsubscribe(res->irq);
    128117        if (fun != NULL)
    129118                ddf_fun_destroy(fun);
  • uspace/drv/char/msim-con/msim-con.h

    re7a8bd2 r7de5f12  
    4141#include <stdint.h>
    4242
     43/** MSIM console resources */
     44typedef struct {
     45        uintptr_t base;
     46        int irq;
     47} msim_con_res_t;
     48
    4349/** MSIM console */
    4450typedef struct {
    4551        async_sess_t *client_sess;
    4652        ddf_dev_t *dev;
     53        msim_con_res_t res;
    4754} msim_con_t;
    4855
    49 extern int msim_con_add(msim_con_t *);
     56extern int msim_con_add(msim_con_t *, msim_con_res_t *);
    5057extern int msim_con_remove(msim_con_t *);
    5158extern int msim_con_gone(msim_con_t *);
  • uspace/drv/platform/msim/msim.c

    re7a8bd2 r7de5f12  
    3838
    3939#include <assert.h>
    40 #include <stdio.h>
    41 #include <errno.h>
    42 #include <stdbool.h>
    43 #include <stdlib.h>
    44 #include <ctype.h>
    45 #include <macros.h>
    46 
    47 #include <ddi.h>
    4840#include <ddf/driver.h>
    4941#include <ddf/log.h>
     42#include <errno.h>
    5043#include <ipc/dev_iface.h>
    5144#include <ops/hw_res.h>
    5245#include <ops/pio_window.h>
     46#include <stdbool.h>
     47#include <stdio.h>
    5348
    5449#define NAME "msim"
    5550
    56 #define MSIM_DISK_BASE  UINT32_C(0x10000200)
    57 #define MSIM_DISK_SIZE  UINT32_C(0x00000010)
     51#define MSIM_DDISK_BASE UINT32_C(0x10000200)
     52#define MSIM_DDISK_SIZE UINT32_C(0x00000010)
     53#define MSIM_DDISK_IRQ 6
     54
     55#define MSIM_KBD_ADDRESS UINT32_C(0x10000000)
     56#define MSIM_KBD_SIZE 1
     57#define MSIM_KBD_IRQ 2
    5858
    5959typedef struct msim_fun {
     
    8989                .type = INTERRUPT,
    9090                .res.interrupt = {
    91                         .irq = 6
     91                        .irq = MSIM_DDISK_IRQ
    9292                }
    9393        }
     
    101101        .pio_window = {
    102102                .mem = {
    103                         .base = MSIM_DISK_BASE,
    104                         .size = MSIM_DISK_SIZE
     103                        .base = MSIM_DDISK_BASE,
     104                        .size = MSIM_DDISK_SIZE
     105                }
     106        }
     107};
     108
     109static hw_resource_t console_regs[] = {
     110        {
     111                .type = MEM_RANGE,
     112                .res.mem_range = {
     113                        .address = 0,
     114                        .size = 1,
     115                        .relative = true,
     116                        .endianness = LITTLE_ENDIAN
     117                }
     118        },
     119        {
     120                .type = INTERRUPT,
     121                .res.interrupt = {
     122                        .irq = MSIM_KBD_IRQ
     123                }
     124        }
     125};
     126
     127static msim_fun_t console_data = {
     128        .hw_resources = {
     129                sizeof(console_regs) / sizeof(console_regs[0]),
     130                console_regs
     131        },
     132        .pio_window = {
     133                .mem = {
     134                        .base = MSIM_KBD_ADDRESS,
     135                        .size = MSIM_KBD_SIZE
    105136                }
    106137        }
     
    194225        if (!msim_add_fun(dev, "disk0", "msim/ddisk", &disk_data))
    195226                return false;
    196         if (!msim_add_fun(dev, "console", "msim/console", &disk_data))
     227        if (!msim_add_fun(dev, "console", "msim/console", &console_data))
    197228                return false;
    198229        return true;
Note: See TracChangeset for help on using the changeset viewer.