Changeset 243cb86 in mainline for uspace/drv
- Timestamp:
- 2010-12-12T10:50:19Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8365533
- Parents:
- 101ef25c (diff), ebb98c5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 17 added
- 1 deleted
- 16 edited
- 3 moved
-
isa/isa.c (modified) (2 diffs)
-
ns8250/ns8250.c (modified) (2 diffs)
-
pciintel/pci.c (modified) (2 diffs)
-
root/root.c (modified) (6 diffs)
-
rootia32/rootia32.ma (deleted)
-
rootpc/Makefile (moved) (moved from uspace/drv/rootia32/Makefile ) (1 diff)
-
rootpc/rootpc.c (moved) (moved from uspace/drv/rootia32/rootia32.c ) (10 diffs)
-
rootpc/rootpc.ma (added)
-
rootvirt/Makefile (added)
-
rootvirt/devices.def (added)
-
rootvirt/rootvirt.c (added)
-
rootvirt/rootvirt.ma (added)
-
test1/Makefile (added)
-
test1/test1.c (added)
-
test1/test1.ma (added)
-
test2/Makefile (added)
-
test2/test2.c (added)
-
test2/test2.ma (added)
-
uhci/Makefile (modified) (1 diff)
-
uhci/main.c (modified) (3 diffs)
-
uhci/transfers.c (added)
-
uhci/uhci.h (added)
-
uhci/uhci.ma (modified) (1 diff)
-
usbhub/Makefile (added)
-
usbhub/main.c (added)
-
usbhub/usbhub.h (added)
-
usbhub/usbhub.ma (added)
-
usbhub/utils.c (moved) (moved from uspace/lib/usb/src/hubdrv.c ) (7 diffs)
-
usbkbd/main.c (modified) (6 diffs)
-
vhc/conn.h (modified) (2 diffs)
-
vhc/connhost.c (modified) (8 diffs)
-
vhc/debug.c (modified) (1 diff)
-
vhc/hcd.c (modified) (5 diffs)
-
vhc/hub.c (modified) (3 diffs)
-
vhc/hub.h (modified) (2 diffs)
-
vhc/vhc.ma (modified) (1 diff)
-
vhc/vhcd.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/isa/isa.c
r101ef25c r243cb86 282 282 283 283 printf(NAME ": added io range (addr=0x%x, size=0x%x) to " 284 "device %s\n", addr, len, dev->name); 284 "device %s\n", (unsigned int) addr, (unsigned int) len, 285 dev->name); 285 286 } 286 287 } … … 489 490 static int isa_add_device(device_t *dev) 490 491 { 491 printf(NAME ": isa_add_device, device handle = %d\n", dev->handle); 492 printf(NAME ": isa_add_device, device handle = %d\n", 493 (int) dev->handle); 492 494 493 495 /* Add child devices. */ -
uspace/drv/ns8250/ns8250.c
r101ef25c r243cb86 274 274 275 275 /* Gain control over port's registers. */ 276 if (pio_enable((void *) data->io_addr, REG_COUNT,276 if (pio_enable((void *)(uintptr_t) data->io_addr, REG_COUNT, 277 277 (void **) &data->port)) { 278 278 printf(NAME ": error - cannot gain the port %#" PRIx32 " for device " … … 727 727 { 728 728 printf(NAME ": ns8250_add_device %s (handle = %d)\n", 729 dev->name, dev->handle);729 dev->name, (int) dev->handle); 730 730 731 731 int res = ns8250_dev_initialize(dev); -
uspace/drv/pciintel/pci.c
r101ef25c r243cb86 324 324 printf(NAME ": device %s : ", dev->name); 325 325 printf("address = %" PRIx64, range_addr); 326 printf(", size = %x\n", range_size);326 printf(", size = %x\n", (unsigned int) range_size); 327 327 } 328 328 … … 489 489 (uint32_t) hw_resources.resources[0].res.io_range.address; 490 490 491 if (pio_enable((void *) bus_data->conf_io_addr, 8,491 if (pio_enable((void *)(uintptr_t)bus_data->conf_io_addr, 8, 492 492 &bus_data->conf_addr_port)) { 493 493 printf(NAME ": failed to enable configuration ports.\n"); -
uspace/drv/root/root.c
r101ef25c r243cb86 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2010 Vojtech Horky 3 4 * All rights reserved. 4 5 * … … 53 54 #define NAME "root" 54 55 56 #define PLATFORM_DEVICE_NAME "hw" 57 #define PLATFORM_DEVICE_MATCH_ID STRING(UARCH) 58 #define PLATFORM_DEVICE_MATCH_SCORE 100 59 60 #define VIRTUAL_DEVICE_NAME "virt" 61 #define VIRTUAL_DEVICE_MATCH_ID "rootvirt" 62 #define VIRTUAL_DEVICE_MATCH_SCORE 100 63 55 64 static int root_add_device(device_t *dev); 56 65 … … 66 75 }; 67 76 77 /** Create the device which represents the root of virtual device tree. 78 * 79 * @param parent Parent of the newly created device. 80 * @return Error code. 81 */ 82 static int add_virtual_root_child(device_t *parent) 83 { 84 printf(NAME ": adding new child for virtual devices.\n"); 85 printf(NAME ": device node is `%s' (%d %s)\n", VIRTUAL_DEVICE_NAME, 86 VIRTUAL_DEVICE_MATCH_SCORE, VIRTUAL_DEVICE_MATCH_ID); 87 88 int res = child_device_register_wrapper(parent, VIRTUAL_DEVICE_NAME, 89 VIRTUAL_DEVICE_MATCH_ID, VIRTUAL_DEVICE_MATCH_SCORE, 90 NULL); 91 92 return res; 93 } 94 68 95 /** Create the device which represents the root of HW device tree. 69 96 * … … 74 101 { 75 102 printf(NAME ": adding new child for platform device.\n"); 103 printf(NAME ": device node is `%s' (%d %s)\n", PLATFORM_DEVICE_NAME, 104 PLATFORM_DEVICE_MATCH_SCORE, PLATFORM_DEVICE_MATCH_ID); 76 105 77 int res = EOK; 78 device_t *platform = NULL; 79 match_id_t *match_id = NULL; 80 81 /* Create new device. */ 82 platform = create_device(); 83 if (NULL == platform) { 84 res = ENOMEM; 85 goto failure; 86 } 87 88 platform->name = "hw"; 89 printf(NAME ": the new device's name is %s.\n", platform->name); 90 91 /* Initialize match id list. */ 92 match_id = create_match_id(); 93 if (NULL == match_id) { 94 res = ENOMEM; 95 goto failure; 96 } 97 98 /* TODO - replace this with some better solution (sysinfo ?) */ 99 match_id->id = STRING(UARCH); 100 match_id->score = 100; 101 add_match_id(&platform->match_ids, match_id); 102 103 /* Register child device. */ 104 res = child_device_register(platform, parent); 105 if (EOK != res) 106 goto failure; 107 106 int res = child_device_register_wrapper(parent, PLATFORM_DEVICE_NAME, 107 PLATFORM_DEVICE_MATCH_ID, PLATFORM_DEVICE_MATCH_SCORE, 108 NULL); 109 108 110 return res; 109 110 failure:111 if (NULL != match_id)112 match_id->id = NULL;113 114 if (NULL != platform) {115 platform->name = NULL;116 delete_device(platform);117 }118 119 return res;120 }121 122 /** Create virtual USB host controller device.123 * Note that the virtual HC is actually device and driver in one124 * task.125 *126 * @param parent Parent device.127 * @return Error code.128 */129 static int add_virtual_usb_host_controller(device_t *parent)130 {131 printf(NAME ": adding virtual host contoller.\n");132 133 int rc;134 device_t *vhc = NULL;135 match_id_t *match_id = NULL;136 137 vhc = create_device();138 if (vhc == NULL) {139 rc = ENOMEM;140 goto failure;141 }142 143 vhc->name = "vhc";144 printf(NAME ": the new device's name is %s.\n", vhc->name);145 146 /* Initialize match id list. */147 match_id = create_match_id();148 if (match_id == NULL) {149 rc = ENOMEM;150 goto failure;151 }152 153 match_id->id = "usb&hc=vhc";154 match_id->score = 100;155 add_match_id(&vhc->match_ids, match_id);156 157 /* Register child device. */158 rc = child_device_register(vhc, parent);159 if (rc != EOK)160 goto failure;161 162 return EOK;163 164 failure:165 if (match_id != NULL)166 match_id->id = NULL;167 168 if (vhc != NULL) {169 vhc->name = NULL;170 delete_device(vhc);171 }172 173 return rc;174 111 } 175 112 … … 184 121 dev->handle); 185 122 123 /* 124 * Register virtual devices root. 125 * We ignore error occurrence because virtual devices shall not be 126 * vital for the system. 127 */ 128 add_virtual_root_child(dev); 129 186 130 /* Register root device's children. */ 187 131 int res = add_platform_child(dev); … … 189 133 printf(NAME ": failed to add child device for platform.\n"); 190 134 191 /* Register virtual USB host controller. */192 int rc = add_virtual_usb_host_controller(dev);193 if (EOK != rc) {194 printf(NAME ": failed to add child device - virtual USB HC.\n");195 }196 197 135 return res; 198 136 } -
uspace/drv/rootpc/Makefile
r101ef25c r243cb86 30 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a 31 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include 32 BINARY = root ia3232 BINARY = rootpc 33 33 34 34 SOURCES = \ 35 root ia32.c35 rootpc.c 36 36 37 37 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/rootpc/rootpc.c
r101ef25c r243cb86 28 28 29 29 /** 30 * @defgroup root_ ia32 Root HW device driver for ia32platform.31 * @brief HelenOS root HW device driver for ia32 platform.30 * @defgroup root_pc Root HW device driver for ia32 and amd64 platform. 31 * @brief HelenOS root HW device driver for ia32 and amd64 platform. 32 32 * @{ 33 33 */ … … 53 53 #include <device/hw_res.h> 54 54 55 #define NAME "root ia32"56 57 typedef struct root ia32_child_dev_data {55 #define NAME "rootpc" 56 57 typedef struct rootpc_child_dev_data { 58 58 hw_resource_list_t hw_resources; 59 } root ia32_child_dev_data_t;60 61 static int root ia32_add_device(device_t *dev);62 static void root_ ia32_init(void);59 } rootpc_child_dev_data_t; 60 61 static int rootpc_add_device(device_t *dev); 62 static void root_pc_init(void); 63 63 64 64 /** The root device driver's standard operations. */ 65 static driver_ops_t root ia32_ops = {66 .add_device = &root ia32_add_device65 static driver_ops_t rootpc_ops = { 66 .add_device = &rootpc_add_device 67 67 }; 68 68 69 69 /** The root device driver structure. */ 70 static driver_t root ia32_driver = {70 static driver_t rootpc_driver = { 71 71 .name = NAME, 72 .driver_ops = &root ia32_ops72 .driver_ops = &rootpc_ops 73 73 }; 74 74 … … 82 82 }; 83 83 84 static root ia32_child_dev_data_t pci_data = {84 static rootpc_child_dev_data_t pci_data = { 85 85 .hw_resources = { 86 86 1, … … 89 89 }; 90 90 91 static hw_resource_list_t *root ia32_get_child_resources(device_t *dev)92 { 93 root ia32_child_dev_data_t *data;94 95 data = (root ia32_child_dev_data_t *) dev->driver_data;91 static hw_resource_list_t *rootpc_get_child_resources(device_t *dev) 92 { 93 rootpc_child_dev_data_t *data; 94 95 data = (rootpc_child_dev_data_t *) dev->driver_data; 96 96 if (NULL == data) 97 97 return NULL; … … 100 100 } 101 101 102 static bool root ia32_enable_child_interrupt(device_t *dev)102 static bool rootpc_enable_child_interrupt(device_t *dev) 103 103 { 104 104 /* TODO */ … … 108 108 109 109 static resource_iface_t child_res_iface = { 110 &root ia32_get_child_resources,111 &root ia32_enable_child_interrupt112 }; 113 114 /* Initialized in root_ ia32_init() function. */115 static device_ops_t root ia32_child_ops;110 &rootpc_get_child_resources, 111 &rootpc_enable_child_interrupt 112 }; 113 114 /* Initialized in root_pc_init() function. */ 115 static device_ops_t rootpc_child_ops; 116 116 117 117 static bool 118 root ia32_add_child(device_t *parent, const char *name, const char *str_match_id,119 root ia32_child_dev_data_t *drv_data)118 rootpc_add_child(device_t *parent, const char *name, const char *str_match_id, 119 rootpc_child_dev_data_t *drv_data) 120 120 { 121 121 printf(NAME ": adding new child device '%s'.\n", name); … … 142 142 143 143 /* Set provided operations to the device. */ 144 child->ops = &root ia32_child_ops;144 child->ops = &rootpc_child_ops; 145 145 146 146 /* Register child device. */ … … 164 164 } 165 165 166 static bool root ia32_add_children(device_t *dev)167 { 168 return root ia32_add_child(dev, "pci0", "intel_pci", &pci_data);166 static bool rootpc_add_children(device_t *dev) 167 { 168 return rootpc_add_child(dev, "pci0", "intel_pci", &pci_data); 169 169 } 170 170 … … 175 175 * @return Zero on success, negative error number otherwise. 176 176 */ 177 static int rootia32_add_device(device_t *dev) 178 { 179 printf(NAME ": rootia32_add_device, device handle = %d\n", dev->handle); 177 static int rootpc_add_device(device_t *dev) 178 { 179 printf(NAME ": rootpc_add_device, device handle = %d\n", 180 (int)dev->handle); 180 181 181 182 /* Register child devices. */ 182 if (!root ia32_add_children(dev)) {183 if (!rootpc_add_children(dev)) { 183 184 printf(NAME ": failed to add child devices for platform " 184 185 "ia32.\n"); … … 188 189 } 189 190 190 static void root_ ia32_init(void)191 { 192 root ia32_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface;191 static void root_pc_init(void) 192 { 193 rootpc_child_ops.interfaces[HW_RES_DEV_IFACE] = &child_res_iface; 193 194 } 194 195 195 196 int main(int argc, char *argv[]) 196 197 { 197 printf(NAME ": HelenOS root ia32device driver\n");198 root_ ia32_init();199 return driver_main(&root ia32_driver);198 printf(NAME ": HelenOS rootpc device driver\n"); 199 root_pc_init(); 200 return driver_main(&rootpc_driver); 200 201 } 201 202 -
uspace/drv/uhci/Makefile
r101ef25c r243cb86 33 33 34 34 SOURCES = \ 35 main.c 35 main.c \ 36 transfers.c 36 37 37 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/uhci/main.c
r101ef25c r243cb86 27 27 */ 28 28 #include <usb/hcdhubd.h> 29 #include <usb/debug.h> 29 30 #include <errno.h> 31 #include "uhci.h" 30 32 31 static int enqueue_transfer_out(usb_hc_device_t *hc, 32 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint, 33 void *buffer, size_t size, 34 usb_hcd_transfer_callback_out_t callback, void *arg) 35 { 36 printf("UHCI: transfer OUT [%d.%d (%s); %u]\n", 37 dev->address, endpoint->endpoint, 38 usb_str_transfer_type(endpoint->transfer_type), 39 size); 40 return ENOTSUP; 41 } 42 43 static int enqueue_transfer_setup(usb_hc_device_t *hc, 44 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint, 45 void *buffer, size_t size, 46 usb_hcd_transfer_callback_out_t callback, void *arg) 47 { 48 printf("UHCI: transfer SETUP [%d.%d (%s); %u]\n", 49 dev->address, endpoint->endpoint, 50 usb_str_transfer_type(endpoint->transfer_type), 51 size); 52 return ENOTSUP; 53 } 54 55 static int enqueue_transfer_in(usb_hc_device_t *hc, 56 usb_hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint, 57 void *buffer, size_t size, 58 usb_hcd_transfer_callback_in_t callback, void *arg) 59 { 60 printf("UHCI: transfer IN [%d.%d (%s); %u]\n", 61 dev->address, endpoint->endpoint, 62 usb_str_transfer_type(endpoint->transfer_type), 63 size); 64 return ENOTSUP; 65 } 66 67 static usb_hcd_transfer_ops_t uhci_transfer_ops = { 68 .transfer_out = enqueue_transfer_out, 69 .transfer_in = enqueue_transfer_in, 70 .transfer_setup = enqueue_transfer_setup 33 static device_ops_t uhci_ops = { 34 .interfaces[USBHC_DEV_IFACE] = &uhci_iface, 71 35 }; 72 36 73 static int uhci_add_ hc(usb_hc_device_t *device)37 static int uhci_add_device(device_t *device) 74 38 { 75 device->transfer_ops = &uhci_transfer_ops; 39 usb_dprintf(NAME, 1, "uhci_add_device() called\n"); 40 device->ops = &uhci_ops; 76 41 77 42 /* 78 43 * We need to announce the presence of our root hub. 79 44 */ 45 usb_dprintf(NAME, 2, "adding root hub\n"); 80 46 usb_hcd_add_root_hub(device); 81 47 … … 83 49 } 84 50 85 usb_hc_driver_t uhci_driver = { 86 .name = "uhci", 87 .add_hc = uhci_add_hc 51 static driver_ops_t uhci_driver_ops = { 52 .add_device = uhci_add_device, 53 }; 54 55 static driver_t uhci_driver = { 56 .name = NAME, 57 .driver_ops = &uhci_driver_ops 88 58 }; 89 59 … … 93 63 * Do some global initializations. 94 64 */ 65 sleep(5); 66 usb_dprintf_enable(NAME, 5); 95 67 96 return usb_hcd_main(&uhci_driver);68 return driver_main(&uhci_driver); 97 69 } -
uspace/drv/uhci/uhci.ma
r101ef25c r243cb86 1 1 10 pci/ven=8086&dev=7020 2 10 usb&hc=uhci 3 10 usb&hc=uhci&hub 2 -
uspace/drv/usbhub/utils.c
r101ef25c r243cb86 33 33 * @brief Hub driver. 34 34 */ 35 #include < usb/hcdhubd.h>35 #include <driver.h> 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb/usbdrv.h> 38 39 #include <usb/descriptor.h> 39 40 #include <driver.h> … … 41 42 #include <errno.h> 42 43 #include <usb/classes/hub.h> 43 #include " hcdhubd_private.h"44 #include "usbhub.h" 44 45 45 46 static void check_hub_changes(void); … … 108 109 //********************************************* 109 110 110 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);111 112 111 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 113 112 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 114 //get parent device115 /// @TODO this code is not correct116 device_t * my_hcd = device;117 while (my_hcd->parent)118 my_hcd = my_hcd->parent;119 //dev->120 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);121 //we add the hub into the first hc122 //link_t *link_hc = hc_list.next;123 //usb_hc_device_t *hc = list_get_instance(link_hc,124 // usb_hc_device_t, link);125 //must get generic device info126 127 113 128 114 return result; … … 135 121 */ 136 122 int usb_add_hub_device(device_t *dev) { 137 usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); 138 set_hub_address(hc, 5); 123 printf(NAME ": add_hub_device(handle=%d)\n", (int) dev->handle); 139 124 140 125 check_hub_changes(); … … 145 130 * connected devices. 146 131 */ 147 //insert hub into list148 //find owner hcd149 device_t * my_hcd = dev;150 while (my_hcd->parent)151 my_hcd = my_hcd->parent;152 //dev->153 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);154 my_hcd = dev;155 while (my_hcd->parent)156 my_hcd = my_hcd->parent;157 //dev->158 159 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name);160 132 161 133 //create the hub structure 162 134 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 163 164 165 //append into the list 166 //we add the hub into the first hc 167 list_append(&hub_info->link, &hc->hubs); 168 169 135 (void)hub_info; 170 136 171 137 return EOK; … … 173 139 } 174 140 175 /** Sample usage of usb_hc_async functions.176 * This function sets hub address using standard SET_ADDRESS request.177 *178 * @warning This function shall be removed once you are familiar with179 * the usb_hc_ API.180 *181 * @param hc Host controller the hub belongs to.182 * @param address New hub address.183 */184 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) {185 printf("%s: setting hub address to %d\n", hc->generic->name, address);186 usb_target_t target = {0, 0};187 usb_handle_t handle;188 int rc;189 190 usb_device_request_setup_packet_t setup_packet = {191 .request_type = 0,192 .request = USB_DEVREQ_SET_ADDRESS,193 .index = 0,194 .length = 0,195 };196 setup_packet.value = address;197 198 rc = usb_hc_async_control_write_setup(hc, target,199 &setup_packet, sizeof (setup_packet), &handle);200 if (rc != EOK) {201 return;202 }203 204 rc = usb_hc_async_wait_for(handle);205 if (rc != EOK) {206 return;207 }208 209 rc = usb_hc_async_control_write_status(hc, target, &handle);210 if (rc != EOK) {211 return;212 }213 214 rc = usb_hc_async_wait_for(handle);215 if (rc != EOK) {216 return;217 }218 219 printf("%s: hub address changed\n", hc->generic->name);220 }221 141 222 142 /** Check changes on all known hubs. … … 224 144 static void check_hub_changes(void) { 225 145 /* 226 * Iterate through all HCs.146 * Iterate through all hubs. 227 147 */ 228 link_t *link_hc; 229 for (link_hc = hc_list.next; 230 link_hc != &hc_list; 231 link_hc = link_hc->next) { 232 usb_hc_device_t *hc = list_get_instance(link_hc, 233 usb_hc_device_t, link); 234 /* 235 * Iterate through all their hubs. 236 */ 237 link_t *link_hub; 238 for (link_hub = hc->hubs.next; 239 link_hub != &hc->hubs; 240 link_hub = link_hub->next) { 241 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 242 usb_hcd_hub_info_t, link); 243 244 /* 245 * Check status change pipe of this hub. 246 */ 247 usb_target_t target = { 248 .address = hub->device->address, 249 .endpoint = 1 250 }; 251 252 // FIXME: count properly 253 size_t byte_length = (hub->port_count / 8) + 1; 254 255 void *change_bitmap = malloc(byte_length); 256 size_t actual_size; 257 usb_handle_t handle; 258 259 /* 260 * Send the request. 261 * FIXME: check returned value for possible errors 262 */ 263 usb_hc_async_interrupt_in(hc, target, 264 change_bitmap, byte_length, &actual_size, 265 &handle); 266 267 usb_hc_async_wait_for(handle); 268 269 /* 270 * TODO: handle the changes. 271 */ 148 for (; false; ) { 149 /* 150 * Check status change pipe of this hub. 151 */ 152 usb_target_t target = { 153 .address = 5, 154 .endpoint = 1 155 }; 156 157 size_t port_count = 7; 158 159 /* 160 * Connect to respective HC. 161 */ 162 int hc = usb_drv_hc_connect(NULL, 0); 163 if (hc < 0) { 164 continue; 272 165 } 166 167 // FIXME: count properly 168 size_t byte_length = (port_count / 8) + 1; 169 170 void *change_bitmap = malloc(byte_length); 171 size_t actual_size; 172 usb_handle_t handle; 173 174 /* 175 * Send the request. 176 * FIXME: check returned value for possible errors 177 */ 178 usb_drv_async_interrupt_in(hc, target, 179 change_bitmap, byte_length, &actual_size, 180 &handle); 181 182 usb_drv_async_wait_for(handle); 183 184 /* 185 * TODO: handle the changes. 186 */ 187 188 /* 189 * WARNING: sample code, will not work out of the box. 190 * And does not contain code for checking for errors. 191 */ 192 #if 0 193 /* 194 * Before opening the port, we must acquire the default 195 * address. 196 */ 197 usb_drv_reserve_default_address(hc); 198 199 usb_address_t new_device_address = usb_drv_request_address(hc); 200 201 // TODO: open the port 202 203 // TODO: send request for setting address to new_device_address 204 205 /* 206 * Once new address is set, we can release the default 207 * address. 208 */ 209 usb_drv_release_default_address(hc); 210 211 /* 212 * Obtain descriptors and create match ids for devman. 213 */ 214 215 // TODO: get device descriptors 216 217 // TODO: create match ids 218 219 // TODO: add child device 220 221 // child_device_register sets the device handle 222 // TODO: store it here 223 devman_handle_t new_device_handle = 0; 224 225 /* 226 * Inform the HC that the new device has devman handle 227 * assigned. 228 */ 229 usb_drv_bind_address(hc, new_device_address, new_device_handle); 230 231 /* 232 * That's all. 233 */ 234 #endif 235 236 237 /* 238 * Hang-up the HC-connected phone. 239 */ 240 ipc_hangup(hc); 273 241 } 274 242 } -
uspace/drv/usbkbd/main.c
r101ef25c r243cb86 32 32 #include <fibril.h> 33 33 #include <usb/classes/hid.h> 34 #include <usb/classes/hidparser.h> 35 #include <usb/devreq.h> 34 36 35 37 #define BUFFER_SIZE 32 … … 37 39 38 40 static const usb_endpoint_t CONTROL_EP = 0; 41 42 /* 43 * Callbacks for parser 44 */ 45 static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count, 46 void *arg) 47 { 48 49 } 50 51 /* 52 * Kbd functions 53 */ 54 static int usbkbd_get_descriptors() 55 { 56 // copy-pasted: 57 58 /* Prepare the setup packet. */ 59 usb_device_request_setup_packet_t setup_packet = { 60 .request_type = 128, 61 .request = USB_DEVREQ_GET_DESCRIPTOR, 62 .index = 0, 63 .length = sizeof(usb_standard_device_descriptor_t) 64 }; 65 66 setup_packet.value_high = USB_DESCTYPE_DEVICE; 67 setup_packet.value_low = 0; 68 69 /* Prepare local descriptor. */ 70 size_t actually_transferred = 0; 71 usb_standard_device_descriptor_t descriptor_tmp; 72 73 /* Perform the control read transaction. */ 74 int rc = usb_drv_psync_control_read(phone, target, 75 &setup_packet, sizeof(setup_packet), 76 &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred); 77 78 if (rc != EOK) { 79 return rc; 80 } 81 82 // end of copy-paste 83 } 39 84 40 85 static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev) … … 68 113 69 114 // TODO: get descriptors 70 115 usbkbd_get_descriptors(); 71 116 // TODO: parse descriptors and save endpoints 72 117 … … 75 120 76 121 static void usbkbd_process_interrupt_in(usb_hid_dev_kbd_t *kbd_dev, 77 char*buffer, size_t actual_size)122 uint8_t *buffer, size_t actual_size) 78 123 { 79 124 /* … … 81 126 * now only take last 6 bytes and process, i.e. send to kbd 82 127 */ 128 129 usb_hid_report_in_callbacks_t *callbacks = 130 (usb_hid_report_in_callbacks_t *)malloc( 131 sizeof(usb_hid_report_in_callbacks_t)); 132 callbacks->keyboard = usbkbd_process_keycodes; 133 134 usb_hid_parse_report(kbd_dev->parser, buffer, callbacks, NULL); 83 135 } 84 136 … … 87 139 int rc; 88 140 usb_handle_t handle; 89 charbuffer[BUFFER_SIZE];141 uint8_t buffer[BUFFER_SIZE]; 90 142 size_t actual_size; 91 143 //usb_endpoint_t poll_endpoint = 1; -
uspace/drv/vhc/conn.h
r101ef25c r243cb86 38 38 #include <usb/usb.h> 39 39 #include <usb/hcdhubd.h> 40 #include <usbhc_iface.h> 40 41 #include "vhcd.h" 41 42 #include "devices.h" … … 44 45 45 46 usb_hcd_transfer_ops_t vhc_transfer_ops; 47 usbhc_iface_t vhc_iface; 48 49 void address_init(void); 50 46 51 47 52 void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); -
uspace/drv/vhc/connhost.c
r101ef25c r243cb86 36 36 #include <errno.h> 37 37 #include <usb/usb.h> 38 #include <usb/hcd.h> 38 39 39 40 #include "vhcd.h" … … 43 44 typedef struct { 44 45 usb_direction_t direction; 45 usb _hcd_transfer_callback_out_t out_callback;46 usb _hcd_transfer_callback_in_t in_callback;47 usb_hc_device_t *hc;46 usbhc_iface_transfer_out_callback_t out_callback; 47 usbhc_iface_transfer_in_callback_t in_callback; 48 device_t *dev; 48 49 void *arg; 49 50 } transfer_info_t; … … 56 57 switch (transfer->direction) { 57 58 case USB_DIRECTION_IN: 58 transfer->in_callback(transfer-> hc,59 size, outcome,59 transfer->in_callback(transfer->dev, 60 outcome, size, 60 61 transfer->arg); 61 62 break; 62 63 case USB_DIRECTION_OUT: 63 transfer->out_callback(transfer-> hc,64 transfer->out_callback(transfer->dev, 64 65 outcome, 65 66 transfer->arg); … … 73 74 } 74 75 75 static transfer_info_t *create_transfer_info( usb_hc_device_t *hc,76 static transfer_info_t *create_transfer_info(device_t *dev, 76 77 usb_direction_t direction, void *arg) 77 78 { … … 82 83 transfer->out_callback = NULL; 83 84 transfer->arg = arg; 84 transfer-> hc = hc;85 transfer->dev = dev; 85 86 86 87 return transfer; 87 88 } 88 89 89 static int enqueue_transfer_out( usb_hc_device_t *hc,90 usb_ hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,90 static int enqueue_transfer_out(device_t *dev, 91 usb_target_t target, usb_transfer_type_t transfer_type, 91 92 void *buffer, size_t size, 92 usb _hcd_transfer_callback_out_t callback, void *arg)93 { 94 printf(NAME ": transfer OUT [%d.%d (%s); % u]\n",95 dev->address, endpoint->endpoint,96 usb_str_transfer_type( endpoint->transfer_type),93 usbhc_iface_transfer_out_callback_t callback, void *arg) 94 { 95 printf(NAME ": transfer OUT [%d.%d (%s); %zu]\n", 96 target.address, target.endpoint, 97 usb_str_transfer_type(transfer_type), 97 98 size); 98 99 99 100 transfer_info_t *transfer 100 = create_transfer_info( hc, USB_DIRECTION_OUT, arg);101 = create_transfer_info(dev, USB_DIRECTION_OUT, arg); 101 102 transfer->out_callback = callback; 102 103 usb_target_t target = {104 .address = dev->address,105 .endpoint = endpoint->endpoint106 };107 103 108 104 hc_add_transaction_to_device(false, target, buffer, size, … … 112 108 } 113 109 114 static int enqueue_transfer_setup( usb_hc_device_t *hc,115 usb_ hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,110 static int enqueue_transfer_setup(device_t *dev, 111 usb_target_t target, usb_transfer_type_t transfer_type, 116 112 void *buffer, size_t size, 117 usb _hcd_transfer_callback_out_t callback, void *arg)118 { 119 printf(NAME ": transfer SETUP [%d.%d (%s); % u]\n",120 dev->address, endpoint->endpoint,121 usb_str_transfer_type( endpoint->transfer_type),113 usbhc_iface_transfer_out_callback_t callback, void *arg) 114 { 115 printf(NAME ": transfer SETUP [%d.%d (%s); %zu]\n", 116 target.address, target.endpoint, 117 usb_str_transfer_type(transfer_type), 122 118 size); 123 119 124 120 transfer_info_t *transfer 125 = create_transfer_info( hc, USB_DIRECTION_OUT, arg);121 = create_transfer_info(dev, USB_DIRECTION_OUT, arg); 126 122 transfer->out_callback = callback; 127 128 usb_target_t target = {129 .address = dev->address,130 .endpoint = endpoint->endpoint131 };132 123 133 124 hc_add_transaction_to_device(true, target, buffer, size, … … 137 128 } 138 129 139 static int enqueue_transfer_in( usb_hc_device_t *hc,140 usb_ hcd_attached_device_info_t *dev, usb_hc_endpoint_info_t *endpoint,130 static int enqueue_transfer_in(device_t *dev, 131 usb_target_t target, usb_transfer_type_t transfer_type, 141 132 void *buffer, size_t size, 142 usb _hcd_transfer_callback_in_t callback, void *arg)143 { 144 printf(NAME ": transfer IN [%d.%d (%s); % u]\n",145 dev->address, endpoint->endpoint,146 usb_str_transfer_type( endpoint->transfer_type),133 usbhc_iface_transfer_in_callback_t callback, void *arg) 134 { 135 printf(NAME ": transfer IN [%d.%d (%s); %zu]\n", 136 target.address, target.endpoint, 137 usb_str_transfer_type(transfer_type), 147 138 size); 148 139 149 140 transfer_info_t *transfer 150 = create_transfer_info( hc, USB_DIRECTION_IN, arg);141 = create_transfer_info(dev, USB_DIRECTION_IN, arg); 151 142 transfer->in_callback = callback; 152 153 usb_target_t target = {154 .address = dev->address,155 .endpoint = endpoint->endpoint156 };157 143 158 144 hc_add_transaction_from_device(target, buffer, size, … … 163 149 164 150 165 usb_hcd_transfer_ops_t vhc_transfer_ops = { 166 .transfer_out = enqueue_transfer_out, 167 .transfer_in = enqueue_transfer_in, 168 .transfer_setup = enqueue_transfer_setup 151 static int interrupt_out(device_t *dev, usb_target_t target, 152 void *data, size_t size, 153 usbhc_iface_transfer_out_callback_t callback, void *arg) 154 { 155 return enqueue_transfer_out(dev, target, USB_TRANSFER_INTERRUPT, 156 data, size, 157 callback, arg); 158 } 159 160 static int interrupt_in(device_t *dev, usb_target_t target, 161 void *data, size_t size, 162 usbhc_iface_transfer_in_callback_t callback, void *arg) 163 { 164 return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT, 165 data, size, 166 callback, arg); 167 } 168 169 static int control_write_setup(device_t *dev, usb_target_t target, 170 void *data, size_t size, 171 usbhc_iface_transfer_out_callback_t callback, void *arg) 172 { 173 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL, 174 data, size, 175 callback, arg); 176 } 177 178 static int control_write_data(device_t *dev, usb_target_t target, 179 void *data, size_t size, 180 usbhc_iface_transfer_out_callback_t callback, void *arg) 181 { 182 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL, 183 data, size, 184 callback, arg); 185 } 186 187 static int control_write_status(device_t *dev, usb_target_t target, 188 usbhc_iface_transfer_in_callback_t callback, void *arg) 189 { 190 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL, 191 NULL, 0, 192 callback, arg); 193 } 194 195 static int control_read_setup(device_t *dev, usb_target_t target, 196 void *data, size_t size, 197 usbhc_iface_transfer_out_callback_t callback, void *arg) 198 { 199 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL, 200 data, size, 201 callback, arg); 202 } 203 204 static int control_read_data(device_t *dev, usb_target_t target, 205 void *data, size_t size, 206 usbhc_iface_transfer_in_callback_t callback, void *arg) 207 { 208 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL, 209 data, size, 210 callback, arg); 211 } 212 213 static int control_read_status(device_t *dev, usb_target_t target, 214 usbhc_iface_transfer_out_callback_t callback, void *arg) 215 { 216 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL, 217 NULL, 0, 218 callback, arg); 219 } 220 221 static usb_address_keeping_t addresses; 222 223 224 static int reserve_default_address(device_t *dev) 225 { 226 usb_address_keeping_reserve_default(&addresses); 227 return EOK; 228 } 229 230 static int release_default_address(device_t *dev) 231 { 232 usb_address_keeping_release_default(&addresses); 233 return EOK; 234 } 235 236 static int request_address(device_t *dev, usb_address_t *address) 237 { 238 usb_address_t addr = usb_address_keeping_request(&addresses); 239 if (addr < 0) { 240 return (int)addr; 241 } 242 243 *address = addr; 244 return EOK; 245 } 246 247 static int release_address(device_t *dev, usb_address_t address) 248 { 249 return usb_address_keeping_release(&addresses, address); 250 } 251 252 static int bind_address(device_t *dev, usb_address_t address, 253 devman_handle_t handle) 254 { 255 usb_address_keeping_devman_bind(&addresses, address, handle); 256 return EOK; 257 } 258 259 static int tell_address(device_t *dev, devman_handle_t handle, 260 usb_address_t *address) 261 { 262 usb_address_t addr = usb_address_keeping_find(&addresses, handle); 263 if (addr < 0) { 264 return addr; 265 } 266 267 *address = addr; 268 return EOK; 269 } 270 271 void address_init(void) 272 { 273 usb_address_keeping_init(&addresses, 50); 274 } 275 276 usbhc_iface_t vhc_iface = { 277 .tell_address = tell_address, 278 279 .reserve_default_address = reserve_default_address, 280 .release_default_address = release_default_address, 281 .request_address = request_address, 282 .bind_address = bind_address, 283 .release_address = release_address, 284 285 .interrupt_out = interrupt_out, 286 .interrupt_in = interrupt_in, 287 288 .control_write_setup = control_write_setup, 289 .control_write_data = control_write_data, 290 .control_write_status = control_write_status, 291 292 .control_read_setup = control_read_setup, 293 .control_read_data = control_read_data, 294 .control_read_status = control_read_status 169 295 }; 170 296 -
uspace/drv/vhc/debug.c
r101ef25c r243cb86 35 35 #include <stdio.h> 36 36 #include <ipc/ipc.h> 37 #include <usb/debug.h> 37 38 38 39 #include "vhcd.h" 39 40 40 /** Current debug level. */41 int debug_level = 0;42 43 /** Debugging printf.44 * This function is intended for single-line messages as it45 * automatically prints debugging prefix at the beginning of the46 * line.47 *48 * @see printf49 * @param level Debugging level.50 */51 void dprintf(int level, const char *format, ...)52 {53 if (level > debug_level) {54 return;55 }56 57 printf("%s(%d): ", NAME, level);58 va_list args;59 va_start(args, format);60 vprintf(format, args);61 va_end(args);62 printf("\n");63 }64 41 65 42 /** Debug print informing of invalid call. -
uspace/drv/vhc/hcd.c
r101ef25c r243cb86 52 52 #include "conn.h" 53 53 54 static device_ops_t vhc_ops = { 55 .interfaces[USBHC_DEV_IFACE] = &vhc_iface, 56 .default_handler = default_connection_handler 57 }; 54 58 55 59 static int vhc_count = 0; 56 static int vhc_add_device( usb_hc_device_t *dev)60 static int vhc_add_device(device_t *dev) 57 61 { 58 62 /* … … 65 69 vhc_count++; 66 70 67 dev->transfer_ops = &vhc_transfer_ops; 68 dev->generic->ops->default_handler = default_connection_handler; 71 dev->ops = &vhc_ops; 72 73 /* 74 * Initialize address management. 75 */ 76 address_init(); 69 77 70 78 /* 71 79 * Initialize our hub and announce its presence. 72 80 */ 73 hub_init(); 74 usb_hcd_add_root_hub(dev); 81 hub_init(dev); 75 82 76 83 printf("%s: virtual USB host controller ready.\n", NAME); … … 79 86 } 80 87 81 static usb_hc_driver_t vhc_driver = { 88 static driver_ops_t vhc_driver_ops = { 89 .add_device = vhc_add_device, 90 }; 91 92 static driver_t vhc_driver = { 82 93 .name = NAME, 83 . add_hc = &vhc_add_device94 .driver_ops = &vhc_driver_ops 84 95 }; 85 96 … … 99 110 printf("%s: virtual USB host controller driver.\n", NAME); 100 111 101 debug_level = 10;112 usb_dprintf_enable(NAME, 10); 102 113 103 114 fid_t fid = fibril_create(hc_manager_fibril, NULL); … … 114 125 sleep(4); 115 126 116 return usb_hcd_main(&vhc_driver);127 return driver_main(&vhc_driver); 117 128 } 118 129 -
uspace/drv/vhc/hub.c
r101ef25c r243cb86 37 37 #include <usbvirt/device.h> 38 38 #include <errno.h> 39 #include <str_error.h> 39 40 #include <stdlib.h> 41 #include <driver.h> 40 42 41 43 #include "vhcd.h" 42 44 #include "hub.h" 43 45 #include "hubintern.h" 46 #include "conn.h" 44 47 45 48 … … 148 151 hub_device_t hub_dev; 149 152 153 static usb_address_t hub_set_address(usbvirt_device_t *hub) 154 { 155 usb_address_t new_address; 156 int rc = vhc_iface.request_address(NULL, &new_address); 157 if (rc != EOK) { 158 return rc; 159 } 160 161 usb_device_request_setup_packet_t setup_packet = { 162 .request_type = 0, 163 .request = USB_DEVREQ_SET_ADDRESS, 164 .index = 0, 165 .length = 0, 166 }; 167 setup_packet.value = new_address; 168 169 hub->transaction_setup(hub, 0, &setup_packet, sizeof(setup_packet)); 170 hub->transaction_in(hub, 0, NULL, 0, NULL); 171 172 return new_address; 173 } 174 150 175 /** Initialize virtual hub. */ 151 void hub_init( void)176 void hub_init(device_t *hc_dev) 152 177 { 153 178 size_t i; … … 163 188 164 189 dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT); 190 191 usb_address_t hub_address = hub_set_address(&virthub_dev); 192 if (hub_address < 0) { 193 dprintf(1, "problem changing hub address (%s)", 194 str_error(hub_address)); 195 } 196 197 dprintf(2, "virtual hub address changed to %d", hub_address); 198 199 char *id; 200 int rc = asprintf(&id, "usb&hub"); 201 if (rc <= 0) { 202 return; 203 } 204 devman_handle_t hub_handle; 205 rc = child_device_register_wrapper(hc_dev, "hub", id, 10, &hub_handle); 206 if (rc != EOK) { 207 free(id); 208 } 209 210 vhc_iface.bind_address(NULL, hub_address, hub_handle); 211 212 dprintf(2, "virtual hub has devman handle %d", (int) hub_handle); 165 213 } 166 214 -
uspace/drv/vhc/hub.h
r101ef25c r243cb86 37 37 38 38 #include <usbvirt/device.h> 39 #include <driver.h> 39 40 40 41 #include "devices.h" … … 47 48 extern usbvirt_device_t virthub_dev; 48 49 49 void hub_init( void);50 void hub_init(device_t *); 50 51 size_t hub_add_device(virtdev_connection_t *); 51 52 void hub_remove_device(virtdev_connection_t *); -
uspace/drv/vhc/vhc.ma
r101ef25c r243cb86 1 1 10 usb&hc=vhc 2 10 usb&hc=vhc&hub 2 -
uspace/drv/vhc/vhcd.h
r101ef25c r243cb86 36 36 #define VHCD_VHCD_H_ 37 37 38 #include <usb/debug.h> 39 38 40 #define NAME "vhc" 39 41 #define NAME_DEV "hcd-virt-dev" … … 43 45 #define DEVMAP_PATH_DEV NAMESPACE "/" NAME_DEV 44 46 45 extern int debug_level; 46 void dprintf(int, const char *, ...); 47 #define dprintf(level, format, ...) \ 48 usb_dprintf(NAME, (level), format "\n", ##__VA_ARGS__) 47 49 void dprintf_inval_call(int, ipc_call_t, ipcarg_t); 48 50
Note:
See TracChangeset
for help on using the changeset viewer.
