Changeset 95c675b in mainline for uspace/drv/intctl/icp-ic/icp-ic.c


Ignore:
Timestamp:
2017-10-17T13:11:35Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60af4cdb
Parents:
dbf32b1 (diff), a416d070 (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

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/intctl/icp-ic/icp-ic.c

    rdbf32b1 r95c675b  
    3333/**
    3434 * @file icp-ic.c
    35  * @brief IntegratorCP interrupt controller driver.
     35 * @brief IntegratorCP interrupt controller driver
    3636 */
    3737
     
    3939#include <bitops.h>
    4040#include <ddi.h>
     41#include <ddf/log.h>
    4142#include <errno.h>
    42 #include <io/log.h>
    43 #include <ipc/services.h>
    4443#include <ipc/irc.h>
    45 #include <ns.h>
    46 #include <sysinfo.h>
    47 #include <stdio.h>
     44#include <loc.h>
    4845#include <stdint.h>
    49 #include <str.h>
    5046
     47#include "icp-ic.h"
    5148#include "icp-ic_hw.h"
    5249
    53 #define NAME  "icp-ic"
    54 
    5550enum {
    56         icp_pic_base = 0x14000000,
    5751        icpic_max_irq = 32
    5852};
    5953
    60 static icpic_regs_t *icpic_regs;
    61 
    62 static int icpic_enable_irq(sysarg_t irq)
     54static int icpic_enable_irq(icpic_t *icpic, sysarg_t irq)
    6355{
    6456        if (irq > icpic_max_irq)
    6557                return EINVAL;
    6658
    67         log_msg(LOG_DEFAULT, LVL_NOTE, "Enable IRQ %d", irq);
     59        ddf_msg(LVL_NOTE, "Enable IRQ %zu", irq);
    6860
    69         pio_write_32(&icpic_regs->irq_enableset, BIT_V(uint32_t, irq));
     61        pio_write_32(&icpic->regs->irq_enableset, BIT_V(uint32_t, irq));
    7062        return EOK;
    7163}
    7264
    73 /** Handle one connection to i8259.
     65/** Client connection handler.
    7466 *
    7567 * @param iid   Hash of the request that opened the connection.
     
    8173        ipc_callid_t callid;
    8274        ipc_call_t call;
     75        icpic_t *icpic;
    8376
    8477        /*
     
    8679         */
    8780        async_answer_0(iid, EOK);
     81
     82        icpic = (icpic_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
    8883
    8984        while (true) {
     
    9994                case IRC_ENABLE_INTERRUPT:
    10095                        async_answer_0(callid,
    101                             icpic_enable_irq(IPC_GET_ARG1(call)));
     96                            icpic_enable_irq(icpic, IPC_GET_ARG1(call)));
     97                        break;
     98                case IRC_DISABLE_INTERRUPT:
     99                        /* XXX TODO */
     100                        async_answer_0(callid, EOK);
    102101                        break;
    103102                case IRC_CLEAR_INTERRUPT:
     
    112111}
    113112
    114 static int icpic_init(void)
     113/** Add icp-ic device. */
     114int icpic_add(icpic_t *icpic, icpic_res_t *res)
    115115{
    116         char *platform = NULL;
    117         char *pstr = NULL;
    118         size_t platform_size;
     116        ddf_fun_t *fun_a = NULL;
    119117        void *regs;
    120118        int rc;
    121119
    122         platform = sysinfo_get_data("platform", &platform_size);
    123         if (platform == NULL) {
    124                 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting platform type.");
    125                 rc = ENOENT;
     120        rc = pio_enable((void *)res->base, sizeof(icpic_regs_t), &regs);
     121        if (rc != EOK) {
     122                ddf_msg(LVL_ERROR, "Error enabling PIO");
    126123                goto error;
    127124        }
    128125
    129         pstr = str_ndup(platform, platform_size);
    130         if (pstr == NULL) {
    131                 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
     126        icpic->regs = (icpic_regs_t *)regs;
     127
     128        fun_a = ddf_fun_create(icpic->dev, fun_exposed, "a");
     129        if (fun_a == NULL) {
     130                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    132131                rc = ENOMEM;
    133132                goto error;
    134133        }
    135134
    136         if (str_cmp(pstr, "integratorcp") != 0) {
    137                 log_msg(LOG_DEFAULT, LVL_ERROR, "Platform '%s' is not 'integratorcp'.",
     135        ddf_fun_set_conn_handler(fun_a, icpic_connection);
    138136
    139                     pstr);
    140                 rc = ENOENT;
     137        rc = ddf_fun_bind(fun_a);
     138        if (rc != EOK) {
     139                ddf_msg(LVL_ERROR, "Failed binding function 'a'. (%d)", rc);
    141140                goto error;
    142141        }
    143142
    144         rc = pio_enable((void *)icp_pic_base, sizeof(icpic_regs_t), &regs);
    145         if (rc != EOK) {
    146                 log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling PIO");
     143        rc = ddf_fun_add_to_category(fun_a, "irc");
     144        if (rc != EOK)
    147145                goto error;
    148         }
    149146
    150         icpic_regs = (icpic_regs_t *)regs;
    151 
    152         async_set_fallback_port_handler(icpic_connection, NULL);
    153         service_register(SERVICE_IRC);
    154 
    155         free(platform);
    156         free(pstr);
    157147        return EOK;
    158148error:
    159         free(platform);
    160         free(pstr);
     149        if (fun_a != NULL)
     150                ddf_fun_destroy(fun_a);
    161151        return rc;
    162152}
    163153
    164 int main(int argc, char **argv)
     154/** Remove icp-ic device */
     155int icpic_remove(icpic_t *icpic)
    165156{
    166         int rc;
     157        return ENOTSUP;
     158}
    167159
    168         printf("%s: HelenOS IntegratorCP interrupt controller driver\n", NAME);
    169 
    170         rc = log_init(NAME);
    171         if (rc != EOK) {
    172                 printf(NAME ": Error connecting logging service.");
    173                 return 1;
    174         }
    175 
    176         if (icpic_init() != EOK)
    177                 return -1;
    178 
    179         log_msg(LOG_DEFAULT, LVL_NOTE, "%s: Accepting connections\n", NAME);
    180         task_retval(0);
    181         async_manager();
    182 
    183         /* Not reached */
    184         return 0;
     160/** icp-ic device gone */
     161int icpic_gone(icpic_t *icpic)
     162{
     163        return ENOTSUP;
    185164}
    186165
Note: See TracChangeset for help on using the changeset viewer.