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


Ignore:
Timestamp:
2017-10-16T15:50:37Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
95c675b, b446b02
Parents:
1974f56a
Message:

Let ICP-IC be enumerated by the DDF.

File:
1 moved

Legend:

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

    r1974f56a ra416d070  
    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>
    4343#include <ipc/irc.h>
    4444#include <loc.h>
    45 #include <sysinfo.h>
    46 #include <stdio.h>
    4745#include <stdint.h>
    48 #include <str.h>
    4946
     47#include "icp-ic.h"
    5048#include "icp-ic_hw.h"
    5149
    52 #define NAME  "icp-ic"
    53 
    5450enum {
    55         icp_pic_base = 0x14000000,
    5651        icpic_max_irq = 32
    5752};
    5853
    59 static icpic_regs_t *icpic_regs;
    60 
    61 static int icpic_enable_irq(sysarg_t irq)
     54static int icpic_enable_irq(icpic_t *icpic, sysarg_t irq)
    6255{
    6356        if (irq > icpic_max_irq)
    6457                return EINVAL;
    6558
    66         log_msg(LOG_DEFAULT, LVL_NOTE, "Enable IRQ %zu", irq);
     59        ddf_msg(LVL_NOTE, "Enable IRQ %zu", irq);
    6760
    68         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));
    6962        return EOK;
    7063}
    7164
    72 /** Handle one connection to i8259.
     65/** Client connection handler.
    7366 *
    7467 * @param iid   Hash of the request that opened the connection.
     
    8073        ipc_callid_t callid;
    8174        ipc_call_t call;
     75        icpic_t *icpic;
    8276
    8377        /*
     
    8579         */
    8680        async_answer_0(iid, EOK);
     81
     82        icpic = (icpic_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
    8783
    8884        while (true) {
     
    9894                case IRC_ENABLE_INTERRUPT:
    9995                        async_answer_0(callid,
    100                             icpic_enable_irq(IPC_GET_ARG1(call)));
     96                            icpic_enable_irq(icpic, IPC_GET_ARG1(call)));
    10197                        break;
    10298                case IRC_DISABLE_INTERRUPT:
     
    115111}
    116112
    117 static int icpic_init(void)
     113/** Add icp-ic device. */
     114int icpic_add(icpic_t *icpic, icpic_res_t *res)
    118115{
    119         char *platform = NULL;
    120         char *pstr = NULL;
    121         size_t platform_size;
    122         category_id_t irc_cat;
    123         service_id_t svc_id;
     116        ddf_fun_t *fun_a = NULL;
    124117        void *regs;
    125118        int rc;
    126119
    127         platform = sysinfo_get_data("platform", &platform_size);
    128         if (platform == NULL) {
    129                 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting platform type.");
    130                 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");
    131123                goto error;
    132124        }
    133125
    134         pstr = str_ndup(platform, platform_size);
    135         if (pstr == NULL) {
    136                 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'.");
    137131                rc = ENOMEM;
    138132                goto error;
    139133        }
    140134
    141         if (str_cmp(pstr, "integratorcp") != 0) {
    142                 log_msg(LOG_DEFAULT, LVL_ERROR, "Platform '%s' is not 'integratorcp'.",
     135        ddf_fun_set_conn_handler(fun_a, icpic_connection);
    143136
    144                     pstr);
    145                 rc = ENOENT;
     137        rc = ddf_fun_bind(fun_a);
     138        if (rc != EOK) {
     139                ddf_msg(LVL_ERROR, "Failed binding function 'a'. (%d)", rc);
    146140                goto error;
    147141        }
    148142
    149         rc = pio_enable((void *)icp_pic_base, sizeof(icpic_regs_t), &regs);
    150         if (rc != EOK) {
    151                 log_msg(LOG_DEFAULT, LVL_ERROR, "Error enabling PIO");
     143        rc = ddf_fun_add_to_category(fun_a, "irc");
     144        if (rc != EOK)
    152145                goto error;
    153         }
    154146
    155         icpic_regs = (icpic_regs_t *)regs;
    156 
    157         async_set_fallback_port_handler(icpic_connection, NULL);
    158 
    159         rc = loc_server_register(NAME);
    160         if (rc != EOK) {
    161                 printf("%s: Failed registering server. (%d)\n", NAME, rc);
    162                 return rc;
    163         }
    164 
    165         rc = loc_service_register("irc/" NAME, &svc_id);
    166         if (rc != EOK) {
    167                 printf("%s: Failed registering service. (%d)\n", NAME, rc);
    168                 return rc;
    169         }
    170 
    171         rc = loc_category_get_id("irc", &irc_cat, IPC_FLAG_BLOCKING);
    172         if (rc != EOK) {
    173                 printf("%s: Failed resolving category 'iplink' (%d).\n", NAME,
    174                     rc);
    175                 goto error;
    176         }
    177 
    178         rc = loc_service_add_to_cat(svc_id, irc_cat);
    179         if (rc != EOK) {
    180                 printf("%s: Failed adding service to category (%d).\n", NAME,
    181                     rc);
    182                 goto error;
    183         }
    184 
    185         free(platform);
    186         free(pstr);
    187147        return EOK;
    188148error:
    189         free(platform);
    190         free(pstr);
     149        if (fun_a != NULL)
     150                ddf_fun_destroy(fun_a);
    191151        return rc;
    192152}
    193153
    194 int main(int argc, char **argv)
     154/** Remove icp-ic device */
     155int icpic_remove(icpic_t *icpic)
    195156{
    196         int rc;
     157        return ENOTSUP;
     158}
    197159
    198         printf("%s: HelenOS IntegratorCP interrupt controller driver\n", NAME);
    199 
    200         rc = log_init(NAME);
    201         if (rc != EOK) {
    202                 printf(NAME ": Error connecting logging service.");
    203                 return 1;
    204         }
    205 
    206         if (icpic_init() != EOK)
    207                 return -1;
    208 
    209         log_msg(LOG_DEFAULT, LVL_NOTE, "%s: Accepting connections\n", NAME);
    210         task_retval(0);
    211         async_manager();
    212 
    213         /* Not reached */
    214         return 0;
     160/** icp-ic device gone */
     161int icpic_gone(icpic_t *icpic)
     162{
     163        return ENOTSUP;
    215164}
    216165
Note: See TracChangeset for help on using the changeset viewer.