Changes in uspace/drv/platform/sun4v/sun4v.c [7aa94304:c1694b6b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/platform/sun4v/sun4v.c
r7aa94304 rc1694b6b 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 <str_error.h> 44 #include <ops/hw_res.h> 45 #include <ops/pio_window.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 #include <sysinfo.h> 45 49 46 50 #define NAME "sun4v" 51 52 typedef struct sun4v_fun { 53 hw_resource_list_t hw_resources; 54 pio_window_t pio_window; 55 } sun4v_fun_t; 47 56 48 57 static int sun4v_dev_add(ddf_dev_t *dev); … … 57 66 }; 58 67 59 static int sun4v_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id) 68 static hw_resource_t console_res[] = { 69 { 70 .type = MEM_RANGE, 71 .res.mem_range = { 72 .address = 0, 73 .size = PAGE_SIZE, 74 .relative = true, 75 .endianness = LITTLE_ENDIAN 76 } 77 }, 78 { 79 .type = MEM_RANGE, 80 .res.mem_range = { 81 .address = 0, 82 .size = PAGE_SIZE, 83 .relative = true, 84 .endianness = LITTLE_ENDIAN 85 } 86 }, 87 }; 88 89 static sun4v_fun_t console_data = { 90 .hw_resources = { 91 sizeof(console_res) / sizeof(console_res[0]), 92 console_res 93 }, 94 .pio_window = { 95 .mem = { 96 .base = 0, 97 .size = PAGE_SIZE 98 } 99 } 100 }; 101 102 /** Obtain function soft-state from DDF function node */ 103 static sun4v_fun_t *sun4v_fun(ddf_fun_t *fnode) 104 { 105 return ddf_fun_data_get(fnode); 106 } 107 108 static hw_resource_list_t *sun4v_get_resources(ddf_fun_t *fnode) 109 { 110 sun4v_fun_t *fun = sun4v_fun(fnode); 111 112 assert(fun != NULL); 113 return &fun->hw_resources; 114 } 115 116 static int sun4v_enable_interrupt(ddf_fun_t *fun, int irq) 117 { 118 return true; 119 } 120 121 static pio_window_t *sun4v_get_pio_window(ddf_fun_t *fnode) 122 { 123 sun4v_fun_t *fun = sun4v_fun(fnode); 124 125 assert(fun != NULL); 126 return &fun->pio_window; 127 } 128 129 static hw_res_ops_t fun_hw_res_ops = { 130 .get_resource_list = &sun4v_get_resources, 131 .enable_interrupt = &sun4v_enable_interrupt, 132 }; 133 134 static pio_window_ops_t fun_pio_window_ops = { 135 .get_pio_window = &sun4v_get_pio_window 136 }; 137 138 static ddf_dev_ops_t sun4v_fun_ops; 139 140 static int sun4v_add_fun(ddf_dev_t *dev, const char *name, 141 const char *str_match_id, sun4v_fun_t *fun_proto) 60 142 { 61 143 ddf_msg(LVL_NOTE, "Adding function '%s'.", name); … … 72 154 } 73 155 156 sun4v_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(sun4v_fun_t)); 157 if (fun == NULL) { 158 rc = ENOMEM; 159 goto error; 160 } 161 162 *fun = *fun_proto; 163 74 164 /* Add match ID */ 75 165 rc = ddf_fun_add_match_id(fnode, str_match_id, 100); … … 79 169 } 80 170 171 /* Set provided operations to the device. */ 172 ddf_fun_set_ops(fnode, &sun4v_fun_ops); 173 81 174 /* Register function. */ 82 if (ddf_fun_bind(fnode) != EOK) { 175 rc = ddf_fun_bind(fnode); 176 if (rc != EOK) { 83 177 ddf_msg(LVL_ERROR, "Failed binding function %s.", name); 84 178 goto error; … … 98 192 int rc; 99 193 100 rc = sun4v_add_fun(dev, "console", "sun4v/console" );194 rc = sun4v_add_fun(dev, "console", "sun4v/console", &console_data); 101 195 if (rc != EOK) 102 196 return rc; … … 108 202 static int sun4v_dev_add(ddf_dev_t *dev) 109 203 { 110 ddf_msg(LVL_ NOTE, "sun4v_dev_add, device handle = %d",204 ddf_msg(LVL_DEBUG, "sun4v_dev_add, device handle = %d", 111 205 (int)ddf_dev_get_handle(dev)); 112 206 … … 119 213 } 120 214 215 static int sun4v_init(void) 216 { 217 int rc; 218 sysarg_t paddr; 219 220 sun4v_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops; 221 sun4v_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops; 222 223 rc = ddf_log_init(NAME); 224 if (rc != EOK) { 225 printf(NAME ": Failed initializing logging service\n"); 226 return rc; 227 } 228 229 rc = sysinfo_get_value("niagara.inbuf.address", &paddr); 230 if (rc != EOK) { 231 ddf_msg(LVL_ERROR, "niagara.inbuf.address not set: %s", str_error(rc)); 232 return rc; 233 } 234 235 console_res[0].res.mem_range.address = paddr; 236 237 rc = sysinfo_get_value("niagara.outbuf.address", &paddr); 238 if (rc != EOK) { 239 ddf_msg(LVL_ERROR, "niagara.outbuf.address not set: %s", str_error(rc)); 240 return rc; 241 } 242 243 console_res[1].res.mem_range.address = paddr; 244 return EOK; 245 } 246 121 247 int main(int argc, char *argv[]) 122 248 { … … 125 251 printf(NAME ": Sun4v platform driver\n"); 126 252 127 rc = ddf_log_init(NAME); 128 if (rc != EOK) { 129 printf(NAME ": Failed initializing logging service"); 253 rc = sun4v_init(); 254 if (rc != EOK) 130 255 return 1; 131 }132 256 133 257 return ddf_driver_main(&sun4v_driver);
Note:
See TracChangeset
for help on using the changeset viewer.