Changes in uspace/drv/platform/sun4v/sun4v.c [c1694b6b:7aa94304] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/platform/sun4v/sun4v.c
rc1694b6b r7aa94304 36 36 */ 37 37 38 #include <as.h>39 38 #include <assert.h> 39 #include <stdio.h> 40 #include <errno.h> 41 #include <stdlib.h> 42 40 43 #include <ddf/driver.h> 41 44 #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>49 45 50 46 #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;56 47 57 48 static int sun4v_dev_add(ddf_dev_t *dev); … … 66 57 }; 67 58 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) 59 static int sun4v_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id) 142 60 { 143 61 ddf_msg(LVL_NOTE, "Adding function '%s'.", name); … … 154 72 } 155 73 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 164 74 /* Add match ID */ 165 75 rc = ddf_fun_add_match_id(fnode, str_match_id, 100); … … 169 79 } 170 80 171 /* Set provided operations to the device. */172 ddf_fun_set_ops(fnode, &sun4v_fun_ops);173 174 81 /* Register function. */ 175 rc = ddf_fun_bind(fnode); 176 if (rc != EOK) { 82 if (ddf_fun_bind(fnode) != EOK) { 177 83 ddf_msg(LVL_ERROR, "Failed binding function %s.", name); 178 84 goto error; … … 192 98 int rc; 193 99 194 rc = sun4v_add_fun(dev, "console", "sun4v/console" , &console_data);100 rc = sun4v_add_fun(dev, "console", "sun4v/console"); 195 101 if (rc != EOK) 196 102 return rc; … … 202 108 static int sun4v_dev_add(ddf_dev_t *dev) 203 109 { 204 ddf_msg(LVL_ DEBUG, "sun4v_dev_add, device handle = %d",110 ddf_msg(LVL_NOTE, "sun4v_dev_add, device handle = %d", 205 111 (int)ddf_dev_get_handle(dev)); 206 112 … … 213 119 } 214 120 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 247 121 int main(int argc, char *argv[]) 248 122 { … … 251 125 printf(NAME ": Sun4v platform driver\n"); 252 126 253 rc = sun4v_init(); 254 if (rc != EOK) 127 rc = ddf_log_init(NAME); 128 if (rc != EOK) { 129 printf(NAME ": Failed initializing logging service"); 255 130 return 1; 131 } 256 132 257 133 return ddf_driver_main(&sun4v_driver);
Note:
See TracChangeset
for help on using the changeset viewer.