Changeset 19d2ce01 in mainline for uspace/drv/platform


Ignore:
Timestamp:
2017-11-16T09:51:14Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
92232331
Parents:
ce96ec2
git-author:
Jiri Svoboda <jiri@…> (2017-11-15 21:50:05)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-16 09:51:14)
Message:

Sun4v console driver can use hw_res for configuration.

Location:
uspace/drv/platform
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/platform/msim/msim.c

    rce96ec2 r19d2ce01  
    6565static void msim_init(void);
    6666
    67 /** The root device driver's standard operations. */
     67/** Standard driver operations. */
    6868static driver_ops_t msim_ops = {
    6969        .dev_add = &msim_dev_add
    7070};
    7171
    72 /** The root device driver structure. */
     72/** Driver structure. */
    7373static driver_t msim_driver = {
    7474        .name = NAME,
     
    194194       
    195195        msim_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(msim_fun_t));
     196        if (fun == NULL)
     197                goto failure;
     198       
    196199        *fun = *fun_proto;
    197200       
     
    230233}
    231234
    232 /** Get the root device.
    233  *
    234  * @param dev           The device which is root of the whole device tree (both
    235  *                      of HW and pseudo devices).
    236  * @return              Zero on success, negative error number otherwise.
     235/** Add MSIM platform device.
     236 *
     237 * @param dev DDF device
     238 * @return Zero on success or non-zero error code.
    237239 */
    238240static int msim_dev_add(ddf_dev_t *dev)
  • uspace/drv/platform/sun4v/sun4v.c

    rce96ec2 r19d2ce01  
    3636 */
    3737
     38#include <as.h>
    3839#include <assert.h>
    39 #include <stdio.h>
    40 #include <errno.h>
    41 #include <stdlib.h>
    42 
    4340#include <ddf/driver.h>
    4441#include <ddf/log.h>
     42#include <errno.h>
     43#include <ops/hw_res.h>
     44#include <ops/pio_window.h>
     45#include <stdio.h>
     46#include <stdlib.h>
     47#include <sysinfo.h>
    4548
    4649#define NAME "sun4v"
     50
     51typedef struct sun4v_fun {
     52        hw_resource_list_t hw_resources;
     53        pio_window_t pio_window;
     54} sun4v_fun_t;
    4755
    4856static int sun4v_dev_add(ddf_dev_t *dev);
     
    5765};
    5866
    59 static int sun4v_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id)
     67static hw_resource_t console_res[] = {
     68        {
     69                .type = MEM_RANGE,
     70                .res.mem_range = {
     71                        .address = 0,
     72                        .size = PAGE_SIZE,
     73                        .relative = true,
     74                        .endianness = LITTLE_ENDIAN
     75                }
     76        },
     77};
     78
     79static sun4v_fun_t console_data = {
     80        .hw_resources = {
     81                sizeof(console_res) / sizeof(console_res[0]),
     82                console_res
     83        },
     84        .pio_window = {
     85                .mem = {
     86                        .base = 0,
     87                        .size = PAGE_SIZE
     88                }
     89        }
     90};
     91
     92/** Obtain function soft-state from DDF function node */
     93static sun4v_fun_t *sun4v_fun(ddf_fun_t *fnode)
     94{
     95        return ddf_fun_data_get(fnode);
     96}
     97
     98static hw_resource_list_t *sun4v_get_resources(ddf_fun_t *fnode)
     99{
     100        sun4v_fun_t *fun = sun4v_fun(fnode);
     101
     102        assert(fun != NULL);
     103        return &fun->hw_resources;
     104}
     105
     106static int sun4v_enable_interrupt(ddf_fun_t *fun, int irq)
     107{
     108        return true;
     109}
     110
     111static pio_window_t *sun4v_get_pio_window(ddf_fun_t *fnode)
     112{
     113        sun4v_fun_t *fun = sun4v_fun(fnode);
     114
     115        assert(fun != NULL);
     116        return &fun->pio_window;
     117}
     118
     119static hw_res_ops_t fun_hw_res_ops = {
     120        .get_resource_list = &sun4v_get_resources,
     121        .enable_interrupt = &sun4v_enable_interrupt,
     122};
     123
     124static pio_window_ops_t fun_pio_window_ops = {
     125        .get_pio_window = &sun4v_get_pio_window
     126};
     127
     128static ddf_dev_ops_t sun4v_fun_ops;
     129
     130static int sun4v_add_fun(ddf_dev_t *dev, const char *name,
     131    const char *str_match_id, sun4v_fun_t *fun_proto)
    60132{
    61133        ddf_msg(LVL_NOTE, "Adding function '%s'.", name);
     
    72144        }
    73145
     146        sun4v_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(sun4v_fun_t));
     147        if (fun == NULL) {
     148                rc = ENOMEM;
     149                goto error;
     150        }
     151
     152        *fun = *fun_proto;
     153
    74154        /* Add match ID */
    75155        rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
     
    79159        }
    80160
     161        /* Set provided operations to the device. */
     162        ddf_fun_set_ops(fnode, &sun4v_fun_ops);
     163
    81164        /* Register function. */
    82         if (ddf_fun_bind(fnode) != EOK) {
     165        rc = ddf_fun_bind(fnode);
     166        if (rc != EOK) {
    83167                ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
    84168                goto error;
     
    98182        int rc;
    99183
    100         rc = sun4v_add_fun(dev, "console", "sun4v/console");
     184        rc = sun4v_add_fun(dev, "console", "sun4v/console", &console_data);
    101185        if (rc != EOK)
    102186                return rc;
     
    108192static int sun4v_dev_add(ddf_dev_t *dev)
    109193{
    110         ddf_msg(LVL_NOTE, "sun4v_dev_add, device handle = %d",
     194        ddf_msg(LVL_DEBUG, "sun4v_dev_add, device handle = %d",
    111195            (int)ddf_dev_get_handle(dev));
    112196
     
    119203}
    120204
     205static int sun4v_init(void)
     206{
     207        int rc;
     208        sysarg_t paddr;
     209
     210        sun4v_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
     211        sun4v_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
     212
     213        rc = ddf_log_init(NAME);
     214        if (rc != EOK) {
     215                printf(NAME ": Failed initializing logging service\n");
     216                return rc;
     217        }
     218
     219        rc = sysinfo_get_value("niagara.inbuf.address", &paddr);
     220        if (rc != EOK) {
     221                ddf_msg(LVL_ERROR, "niagara.inbuf.address not set (%d)", rc);
     222                return rc;
     223        }
     224
     225        console_data.pio_window.mem.base = paddr;
     226        return EOK;
     227}
     228
    121229int main(int argc, char *argv[])
    122230{
     
    125233        printf(NAME ": Sun4v platform driver\n");
    126234
    127         rc = ddf_log_init(NAME);
    128         if (rc != EOK) {
    129                 printf(NAME ": Failed initializing logging service");
     235        rc = sun4v_init();
     236        if (rc != EOK)
    130237                return 1;
    131         }
    132238
    133239        return ddf_driver_main(&sun4v_driver);
Note: See TracChangeset for help on using the changeset viewer.