Changeset c188c62 in mainline


Ignore:
Timestamp:
2017-10-05T18:00:52Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
81b9d3e
Parents:
e27e36e
Message:

CUDA driver should use hw_res to obtain HW configuration.

Location:
uspace/drv
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/adb/cuda_adb/cuda_adb.c

    re27e36e rc188c62  
    148148}
    149149
    150 int cuda_add(cuda_t *cuda)
     150int cuda_add(cuda_t *cuda, cuda_res_t *res)
    151151{
    152152        adb_dev_t *kbd = NULL;
     
    154154        int rc;
    155155
     156        cuda->phys_base = res->base;
     157
    156158        rc = cuda_dev_create(cuda, "kbd", &kbd);
    157159        if (rc != EOK)
     
    166168
    167169        cuda->addr_dev[9] = mouse;
    168 
    169170
    170171        rc = cuda_init(cuda);
     
    225226        int rc;
    226227
    227         if (sysinfo_get_value("cuda.address.physical", &(cuda->cuda_physical)) != EOK)
    228                 return EIO;
    229 
    230228        void *vaddr;
    231         rc = pio_enable((void *) cuda->cuda_physical, sizeof(cuda_regs_t),
     229        rc = pio_enable((void *) cuda->phys_base, sizeof(cuda_regs_t),
    232230            &vaddr);
    233231        if (rc != EOK)
     
    244242        pio_write_8(&cuda->regs->ier, IER_CLR | ALL_INT);
    245243
    246         cuda_irq_code.ranges[0].base = (uintptr_t) cuda->cuda_physical;
     244        cuda_irq_code.ranges[0].base = (uintptr_t) cuda->phys_base;
    247245        cuda_irq_code.cmds[0].addr = (void *) &((cuda_regs_t *)
    248             cuda->cuda_physical)->ifr;
     246            cuda->phys_base)->ifr;
    249247        async_irq_subscribe(10, cuda_irq_handler, cuda, &cuda_irq_code);
    250248
  • uspace/drv/bus/adb/cuda_adb/cuda_adb.h

    re27e36e rc188c62  
    5757};
    5858
     59typedef struct {
     60        uintptr_t base;
     61        int irq;
     62} cuda_res_t;
     63
    5964/** ADB bus device */
    6065typedef struct {
     
    6873typedef struct cude {
    6974        struct cuda_regs *regs;
    70         uintptr_t cuda_physical;
     75        uintptr_t phys_base;
    7176        ddf_dev_t *dev;
    7277
     
    8287} cuda_t;
    8388
    84 extern int cuda_add(cuda_t *);
     89extern int cuda_add(cuda_t *, cuda_res_t *);
    8590extern int cuda_remove(cuda_t *);
    8691extern int cuda_gone(cuda_t *);
  • uspace/drv/bus/adb/cuda_adb/main.c

    re27e36e rc188c62  
    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 cuda_get_res(ddf_dev_t *dev, cuda_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_create(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.io_ranges.count != 1) {
     80                rc = EINVAL;
     81                goto error;
     82        }
     83
     84        res->base = RNGABS(hw_res.io_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 cuda_dev_add(ddf_dev_t *dev)
    64100{
    65101        cuda_t *cuda;
     102        cuda_res_t cuda_res;
     103        int rc;
    66104
    67         printf("cuda_dev_add\n");
    68105        ddf_msg(LVL_DEBUG, "cuda_dev_add(%p)", dev);
    69106        cuda = ddf_dev_data_alloc(dev, sizeof(cuda_t));
     
    75112        cuda->dev = dev;
    76113        list_initialize(&cuda->devs);
    77         printf("call cuda_add\n");
    78         int rc = cuda_add(cuda);
    79         printf("cuda_add->%d\n", rc);
    80         return rc;
     114
     115        rc = cuda_get_res(dev, &cuda_res);
     116        if (rc != EOK) {
     117                ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n");
     118                return EIO;
     119        }
     120
     121        return cuda_add(cuda, &cuda_res);
    81122}
    82123
  • uspace/drv/platform/mac/mac.c

    re27e36e rc188c62  
    11/*
    22 * Copyright (c) 2011 Martin Decky
     3 * Copyright (c) 2017 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    4041#include <errno.h>
    4142#include <ops/hw_res.h>
     43#include <ops/pio_window.h>
    4244#include <stdio.h>
    4345#include <sysinfo.h>
     
    4749typedef struct {
    4850        hw_resource_list_t hw_resources;
     51        pio_window_t pio_window;
    4952} mac_fun_t;
    5053
    51 static hw_resource_t adb_regs[] = {
     54static hw_resource_t adb_res[] = {
    5255        {
    5356                .type = IO_RANGE,
     
    5558                        .address = 0,
    5659                        .size = 0x2000,
    57                         .relative = false,
     60                        .relative = true,
    5861                        .endianness = BIG_ENDIAN
     62                }
     63        },
     64        {
     65                .type = INTERRUPT,
     66                .res.interrupt = {
     67                        .irq = 0 /* patched at run time */
    5968                }
    6069        },
     
    6372static mac_fun_t adb_data = {
    6473        .hw_resources = {
    65                 1,
    66                 adb_regs
     74                sizeof(adb_res) / sizeof(adb_res[0]),
     75                adb_res
     76        },
     77        .pio_window = {
     78                .io = {
     79                        .base = 0, /* patched at run time */
     80                        .size = 0x2000
     81                }
    6782        }
    6883};
     
    99114
    100115/** Obtain function soft-state from DDF function node */
    101 static mac_fun_t *mac_fun(ddf_fun_t *fnode)
    102 {
    103         return ddf_fun_data_get(fnode);
     116static mac_fun_t *mac_fun(ddf_fun_t *ddf_fun)
     117{
     118        return ddf_fun_data_get(ddf_fun);
     119}
     120
     121static pio_window_t *mac_get_pio_window(ddf_fun_t *ddf_fun)
     122{
     123        mac_fun_t *fun = mac_fun(ddf_fun);
     124        return &fun->pio_window;
    104125}
    105126
     
    159180        int rc;
    160181        uintptr_t cuda_physical;
     182        sysarg_t cuda_inr;
    161183#if 0
    162184        /* Register functions */
     
    171193        if (rc != EOK)
    172194                return EIO;
    173 
    174         adb_regs[0].res.io_range.address = cuda_physical;
     195        rc = sysinfo_get_value("cuda.inr", &cuda_inr);
     196        if (rc != EOK)
     197                return EIO;
     198
     199        adb_data.pio_window.io.base = cuda_physical;
     200        adb_res[1].res.interrupt.irq = cuda_inr;
    175201
    176202        if (!mac_add_fun(dev, "adb", "cuda_adb", &adb_data)) {
     
    208234}
    209235
     236static pio_window_ops_t fun_pio_window_ops = {
     237        .get_pio_window = &mac_get_pio_window
     238};
     239
    210240static hw_res_ops_t fun_hw_res_ops = {
    211241        .get_resource_list = &mac_get_resources,
     
    218248        ddf_log_init(NAME);
    219249        mac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
     250        mac_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
    220251        return ddf_driver_main(&mac_driver);
    221252}
Note: See TracChangeset for help on using the changeset viewer.