Changeset a416d070 in mainline for uspace/drv/intctl/icp-ic/icp-ic.c
- Timestamp:
- 2017-10-16T15:50:37Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 95c675b, b446b02
- Parents:
- 1974f56a
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/intctl/icp-ic/icp-ic.c
r1974f56a ra416d070 33 33 /** 34 34 * @file icp-ic.c 35 * @brief IntegratorCP interrupt controller driver .35 * @brief IntegratorCP interrupt controller driver 36 36 */ 37 37 … … 39 39 #include <bitops.h> 40 40 #include <ddi.h> 41 #include <ddf/log.h> 41 42 #include <errno.h> 42 #include <io/log.h>43 43 #include <ipc/irc.h> 44 44 #include <loc.h> 45 #include <sysinfo.h>46 #include <stdio.h>47 45 #include <stdint.h> 48 #include <str.h>49 46 47 #include "icp-ic.h" 50 48 #include "icp-ic_hw.h" 51 49 52 #define NAME "icp-ic"53 54 50 enum { 55 icp_pic_base = 0x14000000,56 51 icpic_max_irq = 32 57 52 }; 58 53 59 static icpic_regs_t *icpic_regs; 60 61 static int icpic_enable_irq(sysarg_t irq) 54 static int icpic_enable_irq(icpic_t *icpic, sysarg_t irq) 62 55 { 63 56 if (irq > icpic_max_irq) 64 57 return EINVAL; 65 58 66 log_msg(LOG_DEFAULT,LVL_NOTE, "Enable IRQ %zu", irq);59 ddf_msg(LVL_NOTE, "Enable IRQ %zu", irq); 67 60 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)); 69 62 return EOK; 70 63 } 71 64 72 /** Handle one connection to i8259.65 /** Client connection handler. 73 66 * 74 67 * @param iid Hash of the request that opened the connection. … … 80 73 ipc_callid_t callid; 81 74 ipc_call_t call; 75 icpic_t *icpic; 82 76 83 77 /* … … 85 79 */ 86 80 async_answer_0(iid, EOK); 81 82 icpic = (icpic_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg)); 87 83 88 84 while (true) { … … 98 94 case IRC_ENABLE_INTERRUPT: 99 95 async_answer_0(callid, 100 icpic_enable_irq( IPC_GET_ARG1(call)));96 icpic_enable_irq(icpic, IPC_GET_ARG1(call))); 101 97 break; 102 98 case IRC_DISABLE_INTERRUPT: … … 115 111 } 116 112 117 static int icpic_init(void) 113 /** Add icp-ic device. */ 114 int icpic_add(icpic_t *icpic, icpic_res_t *res) 118 115 { 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; 124 117 void *regs; 125 118 int rc; 126 119 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), ®s); 121 if (rc != EOK) { 122 ddf_msg(LVL_ERROR, "Error enabling PIO"); 131 123 goto error; 132 124 } 133 125 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'."); 137 131 rc = ENOMEM; 138 132 goto error; 139 133 } 140 134 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); 143 136 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); 146 140 goto error; 147 141 } 148 142 149 rc = pio_enable((void *)icp_pic_base, sizeof(icpic_regs_t), ®s); 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) 152 145 goto error; 153 }154 146 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);187 147 return EOK; 188 148 error: 189 free(platform);190 free(pstr);149 if (fun_a != NULL) 150 ddf_fun_destroy(fun_a); 191 151 return rc; 192 152 } 193 153 194 int main(int argc, char **argv) 154 /** Remove icp-ic device */ 155 int icpic_remove(icpic_t *icpic) 195 156 { 196 int rc; 157 return ENOTSUP; 158 } 197 159 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 */ 161 int icpic_gone(icpic_t *icpic) 162 { 163 return ENOTSUP; 215 164 } 216 165
Note:
See TracChangeset
for help on using the changeset viewer.