Changeset 19d2ce01 in mainline
- Timestamp:
- 2017-11-16T09:51:14Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 92232331
- Parents:
- ce96ec2
- git-author:
- Jiri Svoboda <jiri@…> (2017-11-15 21:50:05)
- git-committer:
- Jiri Svoboda <jiri@…> (2017-11-16 09:51:14)
- Location:
- uspace/drv
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/sun4v-con/main.c
rce96ec2 r19d2ce01 32 32 #include <ddf/driver.h> 33 33 #include <ddf/log.h> 34 #include <device/hw_res_parsed.h> 34 35 #include <errno.h> 35 36 #include <stdio.h> … … 58 59 }; 59 60 61 static int sun4v_con_get_res(ddf_dev_t *dev, sun4v_con_res_t *res) 62 { 63 async_sess_t *parent_sess; 64 hw_res_list_parsed_t hw_res; 65 int rc; 66 67 parent_sess = ddf_dev_parent_sess_get(dev); 68 if (parent_sess == NULL) 69 return ENOMEM; 70 71 hw_res_list_parsed_init(&hw_res); 72 rc = hw_res_get_list_parsed(parent_sess, &hw_res, 0); 73 if (rc != EOK) 74 return rc; 75 76 if (hw_res.mem_ranges.count != 1) { 77 rc = EINVAL; 78 goto error; 79 } 80 81 res->base = RNGABS(hw_res.mem_ranges.ranges[0]); 82 return EOK; 83 error: 84 hw_res_list_parsed_clean(&hw_res); 85 return rc; 86 } 87 88 60 89 static int sun4v_con_dev_add(ddf_dev_t *dev) 61 90 { 62 91 sun4v_con_t *sun4v_con; 92 sun4v_con_res_t res; 93 int rc; 63 94 64 95 ddf_msg(LVL_DEBUG, "sun4v_con_dev_add(%p)", dev); … … 71 102 sun4v_con->dev = dev; 72 103 73 return sun4v_con_add(sun4v_con); 104 rc = sun4v_con_get_res(dev, &res); 105 if (rc != EOK) { 106 ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n"); 107 return EIO; 108 } 109 110 return sun4v_con_add(sun4v_con, &res); 74 111 } 75 112 -
uspace/drv/char/sun4v-con/sun4v-con.c
rce96ec2 r19d2ce01 38 38 #include <ipc/char.h> 39 39 #include <stdbool.h> 40 #include <sysinfo.h>41 40 #include <thread.h> 42 41 … … 72 71 73 72 /** Add sun4v console device. */ 74 int sun4v_con_add(sun4v_con_t *con )73 int sun4v_con_add(sun4v_con_t *con, sun4v_con_res_t *res) 75 74 { 76 75 ddf_fun_t *fun = NULL; 77 76 int rc; 78 77 78 con->res = *res; 79 79 input_buffer = (input_buffer_t) AS_AREA_ANY; 80 80 … … 88 88 ddf_fun_set_conn_handler(fun, sun4v_con_connection); 89 89 90 sysarg_t paddr; 91 rc = sysinfo_get_value("niagara.inbuf.address", &paddr); 92 if (rc != EOK) { 93 ddf_msg(LVL_ERROR, "niagara.inbuf.address not set (%d)", rc); 94 goto error; 95 } 96 97 rc = physmem_map(paddr, 1, AS_AREA_READ | AS_AREA_WRITE, 90 rc = physmem_map(res->base, 1, AS_AREA_READ | AS_AREA_WRITE, 98 91 (void *) &input_buffer); 99 92 if (rc != EOK) { -
uspace/drv/char/sun4v-con/sun4v-con.h
rce96ec2 r19d2ce01 41 41 #include <stdint.h> 42 42 43 /** Sun4v console resources */ 44 typedef struct { 45 uintptr_t base; 46 } sun4v_con_res_t; 47 43 48 /** Sun4v console */ 44 49 typedef struct { 45 50 async_sess_t *client_sess; 46 51 ddf_dev_t *dev; 52 sun4v_con_res_t res; 47 53 } sun4v_con_t; 48 54 49 extern int sun4v_con_init(sun4v_con_t *); 50 extern void sun4v_con_write(uint8_t data); 51 52 53 extern int sun4v_con_add(sun4v_con_t *); 55 extern int sun4v_con_add(sun4v_con_t *, sun4v_con_res_t *); 54 56 extern int sun4v_con_remove(sun4v_con_t *); 55 57 extern int sun4v_con_gone(sun4v_con_t *); -
uspace/drv/platform/msim/msim.c
rce96ec2 r19d2ce01 65 65 static void msim_init(void); 66 66 67 /** The root device driver's standardoperations. */67 /** Standard driver operations. */ 68 68 static driver_ops_t msim_ops = { 69 69 .dev_add = &msim_dev_add 70 70 }; 71 71 72 /** The root device driver structure. */72 /** Driver structure. */ 73 73 static driver_t msim_driver = { 74 74 .name = NAME, … … 194 194 195 195 msim_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(msim_fun_t)); 196 if (fun == NULL) 197 goto failure; 198 196 199 *fun = *fun_proto; 197 200 … … 230 233 } 231 234 232 /** Get the root device. 233 * 234 * @param dev The device which is root of the whole device tree (both 235 * of HW and pseudo devices). 236 * @return Zero on success, negative error number otherwise. 235 /** Add MSIM platform device. 236 * 237 * @param dev DDF device 238 * @return Zero on success or non-zero error code. 237 239 */ 238 240 static int msim_dev_add(ddf_dev_t *dev) -
uspace/drv/platform/sun4v/sun4v.c
rce96ec2 r19d2ce01 36 36 */ 37 37 38 #include <as.h> 38 39 #include <assert.h> 39 #include <stdio.h>40 #include <errno.h>41 #include <stdlib.h>42 43 40 #include <ddf/driver.h> 44 41 #include <ddf/log.h> 42 #include <errno.h> 43 #include <ops/hw_res.h> 44 #include <ops/pio_window.h> 45 #include <stdio.h> 46 #include <stdlib.h> 47 #include <sysinfo.h> 45 48 46 49 #define NAME "sun4v" 50 51 typedef struct sun4v_fun { 52 hw_resource_list_t hw_resources; 53 pio_window_t pio_window; 54 } sun4v_fun_t; 47 55 48 56 static int sun4v_dev_add(ddf_dev_t *dev); … … 57 65 }; 58 66 59 static int sun4v_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id) 67 static hw_resource_t console_res[] = { 68 { 69 .type = MEM_RANGE, 70 .res.mem_range = { 71 .address = 0, 72 .size = PAGE_SIZE, 73 .relative = true, 74 .endianness = LITTLE_ENDIAN 75 } 76 }, 77 }; 78 79 static sun4v_fun_t console_data = { 80 .hw_resources = { 81 sizeof(console_res) / sizeof(console_res[0]), 82 console_res 83 }, 84 .pio_window = { 85 .mem = { 86 .base = 0, 87 .size = PAGE_SIZE 88 } 89 } 90 }; 91 92 /** Obtain function soft-state from DDF function node */ 93 static sun4v_fun_t *sun4v_fun(ddf_fun_t *fnode) 94 { 95 return ddf_fun_data_get(fnode); 96 } 97 98 static hw_resource_list_t *sun4v_get_resources(ddf_fun_t *fnode) 99 { 100 sun4v_fun_t *fun = sun4v_fun(fnode); 101 102 assert(fun != NULL); 103 return &fun->hw_resources; 104 } 105 106 static int sun4v_enable_interrupt(ddf_fun_t *fun, int irq) 107 { 108 return true; 109 } 110 111 static pio_window_t *sun4v_get_pio_window(ddf_fun_t *fnode) 112 { 113 sun4v_fun_t *fun = sun4v_fun(fnode); 114 115 assert(fun != NULL); 116 return &fun->pio_window; 117 } 118 119 static hw_res_ops_t fun_hw_res_ops = { 120 .get_resource_list = &sun4v_get_resources, 121 .enable_interrupt = &sun4v_enable_interrupt, 122 }; 123 124 static pio_window_ops_t fun_pio_window_ops = { 125 .get_pio_window = &sun4v_get_pio_window 126 }; 127 128 static ddf_dev_ops_t sun4v_fun_ops; 129 130 static int sun4v_add_fun(ddf_dev_t *dev, const char *name, 131 const char *str_match_id, sun4v_fun_t *fun_proto) 60 132 { 61 133 ddf_msg(LVL_NOTE, "Adding function '%s'.", name); … … 72 144 } 73 145 146 sun4v_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(sun4v_fun_t)); 147 if (fun == NULL) { 148 rc = ENOMEM; 149 goto error; 150 } 151 152 *fun = *fun_proto; 153 74 154 /* Add match ID */ 75 155 rc = ddf_fun_add_match_id(fnode, str_match_id, 100); … … 79 159 } 80 160 161 /* Set provided operations to the device. */ 162 ddf_fun_set_ops(fnode, &sun4v_fun_ops); 163 81 164 /* Register function. */ 82 if (ddf_fun_bind(fnode) != EOK) { 165 rc = ddf_fun_bind(fnode); 166 if (rc != EOK) { 83 167 ddf_msg(LVL_ERROR, "Failed binding function %s.", name); 84 168 goto error; … … 98 182 int rc; 99 183 100 rc = sun4v_add_fun(dev, "console", "sun4v/console" );184 rc = sun4v_add_fun(dev, "console", "sun4v/console", &console_data); 101 185 if (rc != EOK) 102 186 return rc; … … 108 192 static int sun4v_dev_add(ddf_dev_t *dev) 109 193 { 110 ddf_msg(LVL_ NOTE, "sun4v_dev_add, device handle = %d",194 ddf_msg(LVL_DEBUG, "sun4v_dev_add, device handle = %d", 111 195 (int)ddf_dev_get_handle(dev)); 112 196 … … 119 203 } 120 204 205 static int sun4v_init(void) 206 { 207 int rc; 208 sysarg_t paddr; 209 210 sun4v_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops; 211 sun4v_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops; 212 213 rc = ddf_log_init(NAME); 214 if (rc != EOK) { 215 printf(NAME ": Failed initializing logging service\n"); 216 return rc; 217 } 218 219 rc = sysinfo_get_value("niagara.inbuf.address", &paddr); 220 if (rc != EOK) { 221 ddf_msg(LVL_ERROR, "niagara.inbuf.address not set (%d)", rc); 222 return rc; 223 } 224 225 console_data.pio_window.mem.base = paddr; 226 return EOK; 227 } 228 121 229 int main(int argc, char *argv[]) 122 230 { … … 125 233 printf(NAME ": Sun4v platform driver\n"); 126 234 127 rc = ddf_log_init(NAME); 128 if (rc != EOK) { 129 printf(NAME ": Failed initializing logging service"); 235 rc = sun4v_init(); 236 if (rc != EOK) 130 237 return 1; 131 }132 238 133 239 return ddf_driver_main(&sun4v_driver);
Note:
See TracChangeset
for help on using the changeset viewer.