Changeset f9d0a86 in mainline for uspace/drv/intctl/obio/obio.c


Ignore:
Timestamp:
2017-11-14T12:24:42Z (6 years ago)
Author:
Aearsis <Hlavaty.Ondrej@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6cad776
Parents:
887c9de (diff), d2d142a (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.
git-author:
Aearsis <Hlavaty.Ondrej@…> (2017-11-14 01:04:19)
git-committer:
Aearsis <Hlavaty.Ondrej@…> (2017-11-14 12:24:42)
Message:

Merge tag '0.7.1'

The merge wasn't clean, because of changes in build system. The most
significant change was partial revert of usbhc callback refactoring,
which now does not take usb transfer batch, but few named fields again.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/intctl/obio/obio.c

    r887c9de rf9d0a86  
    4242 */
    4343
     44#include <align.h>
     45#include <as.h>
     46#include <async.h>
     47#include <ddf/driver.h>
     48#include <ddf/log.h>
     49#include <ddi.h>
     50#include <errno.h>
     51#include <inttypes.h>
    4452#include <ipc/irc.h>
    45 #include <loc.h>
    46 #include <as.h>
    47 #include <ddi.h>
    48 #include <align.h>
    49 #include <inttypes.h>
    5053#include <stdbool.h>
    51 #include <errno.h>
    52 #include <async.h>
    53 #include <align.h>
    54 #include <async.h>
    5554#include <stdio.h>
     55
     56#include "obio.h"
    5657
    5758#define NAME "obio"
     
    6768#define INO_MASK        0x1f
    6869
    69 static uintptr_t base_phys;
    70 static volatile uint64_t *base_virt = (volatile uint64_t *) AS_AREA_ANY;
    71 
    7270/** Handle one connection to obio.
    7371 *
     
    8078        ipc_callid_t callid;
    8179        ipc_call_t call;
     80        obio_t *obio;
    8281
    8382        /*
     
    8685        async_answer_0(iid, EOK);
    8786
     87        obio = (obio_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
     88
    8889        while (1) {
    8990                int inr;
    90        
     91
    9192                callid = async_get_call(&call);
    9293                switch (IPC_GET_IMETHOD(call)) {
    9394                case IRC_ENABLE_INTERRUPT:
    9495                        inr = IPC_GET_ARG1(call);
    95                         base_virt[OBIO_IMR(inr & INO_MASK)] |= (1UL << 31);
     96                        pio_set_64(&obio->regs[OBIO_IMR(inr & INO_MASK)],
     97                            1UL << 31, 0);
    9698                        async_answer_0(callid, EOK);
    9799                        break;
     
    102104                case IRC_CLEAR_INTERRUPT:
    103105                        inr = IPC_GET_ARG1(call);
    104                         base_virt[OBIO_CIR(inr & INO_MASK)] = 0;
     106                        pio_write_64(&obio->regs[OBIO_CIR(inr & INO_MASK)], 0);
    105107                        async_answer_0(callid, EOK);
    106108                        break;
     
    112114}
    113115
    114 /** Initialize the OBIO driver.
    115  *
    116  * In the future, the OBIO driver should be integrated with the sun4u platform driver.
    117  */
    118 static bool obio_init(void)
     116/** Add OBIO device. */
     117int obio_add(obio_t *obio, obio_res_t *res)
    119118{
    120         category_id_t irc_cat;
    121         service_id_t svc_id;
     119        ddf_fun_t *fun_a = NULL;
     120        int flags;
     121        int retval;
    122122        int rc;
    123        
    124         base_phys = (uintptr_t) 0x1fe00000000ULL;
    125        
    126         int flags = AS_AREA_READ | AS_AREA_WRITE;
    127         int retval = physmem_map(base_phys,
     123
     124        flags = AS_AREA_READ | AS_AREA_WRITE;
     125        obio->regs = (ioport64_t *)AS_AREA_ANY;
     126        retval = physmem_map(res->base,
    128127            ALIGN_UP(OBIO_SIZE, PAGE_SIZE) >> PAGE_WIDTH, flags,
    129             (void *) &base_virt);
    130        
     128            (void *) &obio->regs);
     129
    131130        if (retval < 0) {
    132                 printf("%s: Error mapping OBIO registers\n", NAME);
    133                 return false;
     131                ddf_msg(LVL_ERROR, "Error mapping OBIO registers");
     132                rc = EIO;
     133                goto error;
    134134        }
    135        
    136         printf("%s: OBIO registers with base at 0x%" PRIun "\n", NAME, base_phys);
    137        
    138         async_set_fallback_port_handler(obio_connection, NULL);
    139        
    140         rc = loc_server_register(NAME);
     135
     136        ddf_msg(LVL_NOTE, "OBIO registers with base at 0x%" PRIun, res->base);
     137
     138        fun_a = ddf_fun_create(obio->dev, fun_exposed, "a");
     139        if (fun_a == NULL) {
     140                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
     141                rc = ENOMEM;
     142                goto error;
     143        }
     144
     145        ddf_fun_set_conn_handler(fun_a, obio_connection);
     146
     147        rc = ddf_fun_bind(fun_a);
    141148        if (rc != EOK) {
    142                 printf("%s: Failed registering server. (%d)\n", NAME, rc);
    143                 return false;
     149                ddf_msg(LVL_ERROR, "Failed binding function 'a'. (%d)", rc);
     150                goto error;
    144151        }
    145        
    146         rc = loc_service_register("irc/" NAME, &svc_id);
    147         if (rc != EOK) {
    148                 printf("%s: Failed registering service. (%d)\n", NAME, rc);
    149                 return false;
    150         }
    151        
    152         rc = loc_category_get_id("irc", &irc_cat, IPC_FLAG_BLOCKING);
    153         if (rc != EOK) {
    154                 printf("%s: Failed resolving category 'iplink' (%d).\n", NAME,
    155                     rc);
    156                 return false;
    157         }
    158        
    159         rc = loc_service_add_to_cat(svc_id, irc_cat);
    160         if (rc != EOK) {
    161                 printf("%s: Failed adding service to category (%d).\n", NAME,
    162                     rc);
    163                 return false;
    164         }
    165        
    166         return true;
     152
     153        rc = ddf_fun_add_to_category(fun_a, "irc");
     154        if (rc != EOK)
     155                goto error;
     156
     157        return EOK;
     158error:
     159        if (fun_a != NULL)
     160                ddf_fun_destroy(fun_a);
     161        return rc;
    167162}
    168163
    169 int main(int argc, char **argv)
     164/** Remove OBIO device */
     165int obio_remove(obio_t *obio)
    170166{
    171         printf("%s: HelenOS OBIO driver\n", NAME);
    172        
    173         if (!obio_init())
    174                 return -1;
    175        
    176         printf("%s: Accepting connections\n", NAME);
    177         task_retval(0);
    178         async_manager();
    179        
    180         /* Never reached */
    181         return 0;
     167        return ENOTSUP;
    182168}
     169
     170/** OBIO device gone */
     171int obio_gone(obio_t *obio)
     172{
     173        return ENOTSUP;
     174}
     175
    183176
    184177/**
Note: See TracChangeset for help on using the changeset viewer.