Changes in / [1c6c4092:0f31e2b] in mainline
- Files:
-
- 10 added
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r1c6c4092 r0f31e2b 89 89 ./uspace/drv/usbhid/usbhid 90 90 ./uspace/drv/usbmid/usbmid 91 ./uspace/drv/usbmouse/usbmouse 91 92 ./uspace/drv/vhc/vhc 92 93 ./uspace/srv/bd/ata_bd/ata_bd -
Makefile
r1c6c4092 r0f31e2b 42 42 CONFIG_HEADER = config.h 43 43 44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check 44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check distfile dist 45 45 46 46 all: $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) … … 64 64 endif 65 65 66 # Autotool (detects compiler features) 67 66 68 $(COMMON_MAKEFILE): autotool 67 69 $(COMMON_HEADER): autotool … … 70 72 $(AUTOTOOL) 71 73 -[ -f $(COMMON_HEADER_PREV) ] && diff -q $(COMMON_HEADER_PREV) $(COMMON_HEADER) && mv -f $(COMMON_HEADER_PREV) $(COMMON_HEADER) 74 75 # Build-time configuration 72 76 73 77 $(CONFIG_MAKEFILE): config_default … … 84 88 $(CONFIG) $< 85 89 90 # Distribution files 91 92 distfile: all 93 $(MAKE) -C dist distfile 94 95 dist: 96 $(MAKE) -C dist dist 97 98 # Cleaning 99 86 100 distclean: clean 87 rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc 101 rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc dist/HelenOS-* 88 102 89 103 clean: -
boot/arch/amd64/Makefile.inc
r1c6c4092 r0f31e2b 48 48 usbhid \ 49 49 usbmid \ 50 usbmouse \ 50 51 vhc 51 52 -
boot/arch/sparc64/include/arch.h
r1c6c4092 r0f31e2b 41 41 #define STACK_BIAS 2047 42 42 #define STACK_WINDOW_SAVE_AREA_SIZE (16 * 8) 43 #define STACK_ARG_SAVE_AREA_SIZE (6 * 8) 43 44 44 45 #define NWINDOWS 8 -
boot/arch/sparc64/src/asm.S
r1c6c4092 r0f31e2b 152 152 .global ofw 153 153 ofw: 154 save %sp, - STACK_WINDOW_SAVE_AREA_SIZE, %sp154 save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp 155 155 set ofw_cif, %l0 156 156 ldx [%l0], %l0 -
boot/arch/sparc64/src/main.c
r1c6c4092 r0f31e2b 190 190 bootinfo.memmap.zones[0].start += OBP_BIAS; 191 191 bootinfo.memmap.zones[0].size -= OBP_BIAS; 192 bootinfo.memmap.total -= OBP_BIAS; 192 193 } 193 194 … … 204 205 bootinfo.physmem_start = ofw_get_physmem_start(); 205 206 ofw_memmap(&bootinfo.memmap); 207 208 if (arch == ARCH_SUN4V) 209 sun4v_fixups(); 206 210 207 211 void *bootinfo_pa = ofw_translate(&bootinfo); … … 253 257 254 258 /* 255 * At this point, we claim the physical memory that we are256 * going to use. We should be safe in case of the virtual259 * At this point, we claim and map the physical memory that we 260 * are going to use. We should be safe in case of the virtual 257 261 * address space because the OpenFirmware, according to its 258 * SPARC binding, should restrict its use of virtual memory 259 * to addresses from [0xffd00000; 0xffefffff] and 260 * [0xfe000000; 0xfeffffff]. 261 * 262 * We don't map this piece of memory. We simply rely on 263 * SILO to have it done for us already in this case. 264 * 265 * XXX SILO only maps 8 MB for us here. We should improve 266 * this code to be totally independent on the behavior 267 * of SILO. 268 * 262 * SPARC binding, should restrict its use of virtual memory to 263 * addresses from [0xffd00000; 0xffefffff] and [0xfe000000; 264 * 0xfeffffff]. 269 265 */ 270 266 ofw_claim_phys(bootinfo.physmem_start + dest[i - 1], 271 267 ALIGN_UP(components[i - 1].inflated, PAGE_SIZE)); 268 269 ofw_map(bootinfo.physmem_start + dest[i - 1], dest[i - 1], 270 ALIGN_UP(components[i - 1].inflated, PAGE_SIZE), -1); 272 271 273 272 int err = inflate(components[i - 1].start, components[i - 1].size, … … 304 303 sun4u_smp(); 305 304 306 if (arch == ARCH_SUN4V)307 sun4v_fixups();308 309 305 printf("Booting the kernel ...\n"); 310 306 jump_to_kernel(bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, subarch, -
boot/generic/src/balloc.c
r1c6c4092 r0f31e2b 65 65 void *balloc_rebase(void *ptr) 66 66 { 67 return (void *) (( uintptr_t) ptr - phys_base+ ballocs->base);67 return (void *) (((uintptr_t) ptr - phys_base) + ballocs->base); 68 68 } -
kernel/arch/sparc64/src/sun4v/asm.S
r1c6c4092 r0f31e2b 41 41 .global switch_to_userspace 42 42 switch_to_userspace: 43 wrpr PSTATE_PRIV_BIT, %pstate 44 save %o1, -STACK_WINDOW_SAVE_AREA_SIZE, %sp 43 save %o1, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp 45 44 flushw 46 45 wrpr %g0, 0, %cleanwin ! avoid information leak -
tools/toolchain.sh
r1c6c4092 r0f31e2b 28 28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 # 30 31 GMP_MAIN=<<EOF 32 #define GCC_GMP_VERSION_NUM(a, b, c) \ 33 (((a) << 16L) | ((b) << 8) | (c)) 34 35 #define GCC_GMP_VERSION \ 36 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL) 37 38 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,2) 39 choke me 40 #endif 41 EOF 42 43 MPFR_MAIN=<<EOF 44 #if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2) 45 choke me 46 #endif 47 EOF 48 49 MPC_MAIN=<<EOF 50 #if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1) 51 choke me 52 #endif 53 EOF 54 55 # 56 # Check if the library described in the argument 57 # exists and has acceptable version. 58 # 59 check_dependency() { 60 DEPENDENCY="$1" 61 HEADER="$2" 62 BODY="$3" 63 64 FNAME="/tmp/conftest-$$" 65 66 echo "#include ${HEADER}" > "${FNAME}.c" 67 echo >> "${FNAME}.c" 68 echo "int main()" >> "${FNAME}.c" 69 echo "{" >> "${FNAME}.c" 70 echo "${BODY}" >> "${FNAME}.c" 71 echo " return 0;" >> "${FNAME}.c" 72 echo "}" >> "${FNAME}.c" 73 74 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log" 75 RC="$?" 76 77 if [ "$RC" -ne "0" ] ; then 78 echo " ${DEPENDENCY} not found, too old or compiler error." 79 echo " Please recheck manually the source file \"${FNAME}.c\"." 80 echo " The compilation of the toolchain is probably going to fail," 81 echo " you have been warned." 82 echo 83 echo " ===== Compiler output =====" 84 cat "${FNAME}.log" 85 echo " ===========================" 86 echo 87 else 88 echo " ${DEPENDENCY} found" 89 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c" 90 fi 91 } 92 93 check_dependecies() { 94 echo ">>> Basic dependency check" 95 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}" 96 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}" 97 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}" 98 echo 99 } 30 100 31 101 check_error() { … … 69 139 echo " sparc64 SPARC V9" 70 140 echo " all build all targets" 141 echo 142 echo "The toolchain will be installed to the directory specified by" 143 echo "the CROSS_PREFIX environment variable. If the variable is not" 144 echo "defined, /usr/local will be used by default." 71 145 echo 72 146 … … 118 192 echo " - native C library with headers" 119 193 echo 120 121 show_countdown 10122 194 } 123 195 … … 281 353 282 354 show_dependencies 355 check_dependecies 356 show_countdown 10 283 357 284 358 case "$1" in -
uspace/Makefile
r1c6c4092 r0f31e2b 122 122 drv/usbhub \ 123 123 drv/usbmid \ 124 drv/usbmouse \ 124 125 drv/vhc 125 126 endif … … 138 139 drv/usbhub \ 139 140 drv/usbmid \ 141 drv/usbmouse \ 140 142 drv/vhc 141 143 endif -
uspace/app/bdsh/cmds/modules/mount/mount.c
r1c6c4092 r0f31e2b 31 31 #include <vfs/vfs.h> 32 32 #include <errno.h> 33 #include <getopt.h> 33 34 #include "config.h" 34 35 #include "util.h" … … 40 41 static const char *cmdname = "mount"; 41 42 42 /* Dispays help for mount in various levels */ 43 static struct option const long_options[] = { 44 { "help", no_argument, 0, 'h' }, 45 { 0, 0, 0, 0 } 46 }; 47 48 49 /* Displays help for mount in various levels */ 43 50 void help_cmd_mount(unsigned int level) 44 51 { … … 59 66 unsigned int argc; 60 67 const char *mopts = ""; 61 int rc ;68 int rc, c, opt_ind; 62 69 63 70 argc = cli_count_args(argv); 64 71 72 for (c = 0, optind = 0, opt_ind = 0; c != -1;) { 73 c = getopt_long(argc, argv, "h", long_options, &opt_ind); 74 switch (c) { 75 case 'h': 76 help_cmd_mount(HELP_LONG); 77 return CMD_SUCCESS; 78 } 79 } 80 65 81 if ((argc < 4) || (argc > 5)) { 66 printf("%s: invalid number of arguments. \n",82 printf("%s: invalid number of arguments. Try `mount --help'\n", 67 83 cmdname); 68 84 return CMD_FAILURE; -
uspace/doc/doxygroups.h
r1c6c4092 r0f31e2b 245 245 246 246 /** 247 * @defgroup drvusbmouse USB mouse driver 248 * @ingroup usb 249 * @brief USB driver for mouse with boot protocol. 250 */ 251 252 /** 247 253 * @defgroup drvusbuhci UHCI driver 248 254 * @ingroup usb -
uspace/drv/pciintel/pci.c
r1c6c4092 r0f31e2b 59 59 #include <ddi.h> 60 60 #include <libarch/ddi.h> 61 #include <pci_dev_iface.h> 61 62 62 63 #include "pci.h" … … 121 122 } 122 123 124 static int pci_config_space_write_16(ddf_fun_t *fun, uint32_t address, uint16_t data) 125 { 126 if (address > 254) 127 return EINVAL; 128 pci_conf_write_16(PCI_FUN(fun), address, data); 129 return EOK; 130 } 131 132 123 133 static hw_res_ops_t pciintel_hw_res_ops = { 124 134 &pciintel_get_resources, … … 126 136 }; 127 137 128 static ddf_dev_ops_t pci_fun_ops; 138 static pci_dev_iface_t pci_dev_ops = { 139 .config_space_read_8 = NULL, 140 .config_space_read_16 = NULL, 141 .config_space_read_32 = NULL, 142 .config_space_write_8 = NULL, 143 .config_space_write_16 = &pci_config_space_write_16, 144 .config_space_write_32 = NULL 145 }; 146 147 static ddf_dev_ops_t pci_fun_ops = { 148 .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops, 149 .interfaces[PCI_DEV_IFACE] = &pci_dev_ops 150 }; 129 151 130 152 static int pci_add_device(ddf_dev_t *); … … 593 615 { 594 616 pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops; 617 pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops; 595 618 } 596 619 -
uspace/drv/uhci-hcd/main.c
r1c6c4092 r0f31e2b 34 34 #include <ddf/driver.h> 35 35 #include <ddf/interrupt.h> 36 #include <device/hw_res.h> 37 #include <errno.h> 38 #include <str_error.h> 39 36 40 #include <usb_iface.h> 37 41 #include <usb/ddfiface.h> 38 #include <device/hw_res.h>39 40 #include <errno.h>41 42 42 #include <usb/debug.h> 43 43 … … 50 50 51 51 static int uhci_add_device(ddf_dev_t *device); 52 53 52 /*----------------------------------------------------------------------------*/ 54 53 static driver_ops_t uhci_driver_ops = { … … 70 69 } 71 70 /*----------------------------------------------------------------------------*/ 72 #define CHECK_RET_RETURN(ret, message...) \73 if (ret != EOK) { \74 usb_log_error(message); \75 return ret; \76 }77 78 71 static int uhci_add_device(ddf_dev_t *device) 79 72 { 80 73 assert(device); 74 uhci_t *hcd = NULL; 75 #define CHECK_RET_FREE_HC_RETURN(ret, message...) \ 76 if (ret != EOK) { \ 77 usb_log_error(message); \ 78 if (hcd != NULL) \ 79 free(hcd); \ 80 return ret; \ 81 } 81 82 82 83 usb_log_info("uhci_add_device() called\n"); … … 88 89 int ret = 89 90 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq); 90 91 CHECK_RET_RETURN(ret, 91 CHECK_RET_FREE_HC_RETURN(ret, 92 92 "Failed(%d) to get I/O addresses:.\n", ret, device->handle); 93 93 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n", 94 94 io_reg_base, io_reg_size, irq); 95 95 96 // ret = pci_enable_interrupts(device); 97 // CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret); 96 ret = pci_disable_legacy(device); 97 CHECK_RET_FREE_HC_RETURN(ret, 98 "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret)); 98 99 99 uhci_t *uhci_hc = malloc(sizeof(uhci_t)); 100 ret = (uhci_hc != NULL) ? EOK : ENOMEM; 101 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n"); 100 #if 0 101 ret = pci_enable_interrupts(device); 102 if (ret != EOK) { 103 usb_log_warning( 104 "Failed(%d) to enable interrupts, fall back to polling.\n", 105 ret); 106 } 107 #endif 102 108 103 ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size); 104 if (ret != EOK) { 105 usb_log_error("Failed to init uhci-hcd.\n"); 106 free(uhci_hc); 107 return ret; 108 } 109 hcd = malloc(sizeof(uhci_t)); 110 ret = (hcd != NULL) ? EOK : ENOMEM; 111 CHECK_RET_FREE_HC_RETURN(ret, 112 "Failed(%d) to allocate memory for uhci hcd.\n", ret); 113 114 ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size); 115 CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", 116 ret); 117 #undef CHECK_RET_FREE_HC_RETURN 109 118 110 119 /* 111 * We might free uhci_hc, but that does not matter since no one120 * We might free hcd, but that does not matter since no one 112 121 * else would access driver_data anyway. 113 122 */ 114 device->driver_data = uhci_hc; 123 device->driver_data = hcd; 124 125 ddf_fun_t *rh = NULL; 126 #define CHECK_RET_FINI_FREE_RETURN(ret, message...) \ 127 if (ret != EOK) { \ 128 usb_log_error(message); \ 129 if (hcd != NULL) {\ 130 uhci_fini(hcd); \ 131 free(hcd); \ 132 } \ 133 if (rh != NULL) \ 134 free(rh); \ 135 return ret; \ 136 } 137 138 /* It does no harm if we register this on polling */ 115 139 ret = register_interrupt_handler(device, irq, irq_handler, 116 &uhci_hc->interrupt_code); 117 if (ret != EOK) { 118 usb_log_error("Failed to register interrupt handler.\n"); 119 uhci_fini(uhci_hc); 120 free(uhci_hc); 121 return ret; 122 } 140 &hcd->interrupt_code); 141 CHECK_RET_FINI_FREE_RETURN(ret, 142 "Failed(%d) to register interrupt handler.\n", ret); 123 143 124 ddf_fun_t *rh;125 144 ret = setup_root_hub(&rh, device); 126 if (ret != EOK) { 127 usb_log_error("Failed to setup uhci root hub.\n"); 128 uhci_fini(uhci_hc); 129 free(uhci_hc); 130 return ret; 131 } 132 rh->driver_data = uhci_hc->ddf_instance; 145 CHECK_RET_FINI_FREE_RETURN(ret, 146 "Failed(%d) to setup UHCI root hub.\n", ret); 147 rh->driver_data = hcd->ddf_instance; 133 148 134 149 ret = ddf_fun_bind(rh); 135 if (ret != EOK) { 136 usb_log_error("Failed to register root hub.\n"); 137 uhci_fini(uhci_hc); 138 free(uhci_hc); 139 free(rh); 140 return ret; 141 } 150 CHECK_RET_FINI_FREE_RETURN(ret, 151 "Failed(%d) to register UHCI root hub.\n", ret); 142 152 143 153 return EOK; 154 #undef CHECK_RET_FINI_FREE_RETURN 144 155 } 145 156 /*----------------------------------------------------------------------------*/ -
uspace/drv/uhci-hcd/pci.c
r1c6c4092 r0f31e2b 40 40 41 41 #include <usb/debug.h> 42 #include <pci_dev_iface.h> 42 43 43 44 #include "pci.h" … … 128 129 return enabled ? EOK : EIO; 129 130 } 131 /*----------------------------------------------------------------------------*/ 132 int pci_disable_legacy(ddf_dev_t *device) 133 { 134 assert(device); 135 int parent_phone = devman_parent_device_connect(device->handle, 136 IPC_FLAG_BLOCKING); 137 if (parent_phone < 0) { 138 return parent_phone; 139 } 140 141 /* See UHCI design guide for these values, 142 * write all WC bits in USB legacy register */ 143 sysarg_t address = 0xc0; 144 sysarg_t value = 0x8f00; 145 146 int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE), 147 IPC_M_CONFIG_SPACE_WRITE_16, address, value); 148 async_hangup(parent_phone); 149 150 return rc; 151 } 152 /*----------------------------------------------------------------------------*/ 130 153 /** 131 154 * @} -
uspace/drv/uhci-hcd/pci.h
r1c6c4092 r0f31e2b 40 40 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *); 41 41 int pci_enable_interrupts(ddf_dev_t *); 42 int pci_disable_legacy(ddf_dev_t *); 42 43 43 44 #endif -
uspace/drv/uhci-hcd/uhci.c
r1c6c4092 r0f31e2b 90 90 .interfaces[USBHC_DEV_IFACE] = &uhci_iface, 91 91 }; 92 92 /*----------------------------------------------------------------------------*/ 93 93 static int uhci_init_transfer_lists(uhci_t *instance); 94 94 static int uhci_init_mem_structures(uhci_t *instance); … … 115 115 } else (void) 0 116 116 117 /* 118 * Create UHCI function. 119 */ 117 /* Create UHCI function. */ 120 118 instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci"); 121 119 ret = (instance->ddf_instance == NULL) ? ENOMEM : EOK; 122 CHECK_RET_DEST_FUN_RETURN(ret, "Failed to create UHCI device function.\n"); 120 CHECK_RET_DEST_FUN_RETURN(ret, 121 "Failed to create UHCI device function.\n"); 123 122 124 123 instance->ddf_instance->ops = &uhci_ops; … … 126 125 127 126 ret = ddf_fun_bind(instance->ddf_instance); 128 CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to bind UHCI device function: %s.\n", 127 CHECK_RET_DEST_FUN_RETURN(ret, 128 "Failed(%d) to bind UHCI device function: %s.\n", 129 129 ret, str_error(ret)); 130 130 … … 132 132 regs_t *io; 133 133 ret = pio_enable(regs, reg_size, (void**)&io); 134 CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to gain access to registers at %p: %s.\n", 134 CHECK_RET_DEST_FUN_RETURN(ret, 135 "Failed(%d) to gain access to registers at %p: %s.\n", 135 136 ret, str_error(ret), io); 136 137 instance->registers = io; 137 usb_log_debug("Device registers at %p(%u) accessible.\n", io, reg_size); 138 usb_log_debug("Device registers at %p(%u) accessible.\n", 139 io, reg_size); 138 140 139 141 ret = uhci_init_mem_structures(instance); 140 CHECK_RET_DEST_FUN_RETURN(ret, "Failed to initialize UHCI memory structures.\n"); 142 CHECK_RET_DEST_FUN_RETURN(ret, 143 "Failed to initialize UHCI memory structures.\n"); 141 144 142 145 uhci_init_hw(instance); 143 144 instance->cleaner =fibril_create(uhci_interrupt_emulator, instance);146 instance->cleaner = 147 fibril_create(uhci_interrupt_emulator, instance); 145 148 fibril_add_ready(instance->cleaner); 146 149 … … 155 158 void uhci_init_hw(uhci_t *instance) 156 159 { 160 assert(instance); 161 157 162 /* reset everything, who knows what touched it before us */ 158 163 pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET); … … 171 176 /* enable all interrupts, but resume interrupt */ 172 177 pio_write_16(&instance->registers->usbintr, 173 178 UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET); 174 179 175 180 /* Start the hc with large(64B) packet FSBR */ … … 200 205 interrupt_commands[1].addr = (void*)&instance->registers->usbsts; 201 206 instance->interrupt_code.cmdcount = 202 207 sizeof(uhci_cmds) / sizeof(irq_cmd_t); 203 208 } 204 209 … … 249 254 ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL"); 250 255 CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list."); 256 251 257 ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL"); 252 258 CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list."); 259 253 260 ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW"); 254 261 CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list."); 262 255 263 ret = transfer_list_init(&instance->transfers_interrupt, "INTERRUPT"); 256 264 CHECK_RET_CLEAR_RETURN(ret, "Failed to init INTERRUPT list."); … … 292 300 low_speed, batch->transfer_type, batch->max_packet_size)) { 293 301 usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n", 294 302 low_speed ? "LOW" : "FULL" , batch->transfer_type, 295 303 batch->max_packet_size); 296 304 return ENOTSUP; … … 309 317 { 310 318 assert(instance); 311 // if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0)312 // return;313 // usb_log_debug2("UHCI interrupt: %X.\n", status);314 319 transfer_list_remove_finished(&instance->transfers_interrupt); 315 320 transfer_list_remove_finished(&instance->transfers_control_slow); … … 340 345 uhci_t *instance = (uhci_t*)arg; 341 346 assert(instance); 347 348 #define QH(queue) \ 349 instance->transfers_##queue.queue_head 350 342 351 while (1) { 343 352 const uint16_t cmd = pio_read_16(&instance->registers->usbcmd); 344 353 const uint16_t sts = pio_read_16(&instance->registers->usbsts); 345 const uint16_t intr = pio_read_16(&instance->registers->usbintr); 354 const uint16_t intr = 355 pio_read_16(&instance->registers->usbintr); 356 346 357 if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) { 347 358 usb_log_debug2("Command: %X Status: %X Intr: %x\n", … … 353 364 if (frame_list != addr_to_phys(instance->frame_list)) { 354 365 usb_log_debug("Framelist address: %p vs. %p.\n", 355 frame_list, addr_to_phys(instance->frame_list)); 356 } 366 frame_list, addr_to_phys(instance->frame_list)); 367 } 368 357 369 int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff; 358 370 usb_log_debug2("Framelist item: %d \n", frnum ); 359 371 360 queue_head_t* qh = instance->transfers_interrupt.queue_head;361 362 if ( (instance->frame_list[frnum] & (~0xf)) != (uintptr_t)addr_to_phys(qh)) {372 uintptr_t expected_pa = instance->frame_list[frnum] & (~0xf); 373 uintptr_t real_pa = addr_to_phys(QH(interrupt)); 374 if (expected_pa != real_pa) { 363 375 usb_log_debug("Interrupt QH: %p vs. %p.\n", 364 instance->frame_list[frnum] & (~0xf), addr_to_phys(qh)); 365 } 366 367 if ((qh->next_queue & (~0xf)) 368 != (uintptr_t)addr_to_phys(instance->transfers_control_slow.queue_head)) { 369 usb_log_debug("Control Slow QH: %p vs. %p.\n", qh->next_queue & (~0xf), 370 addr_to_phys(instance->transfers_control_slow.queue_head)); 371 } 372 qh = instance->transfers_control_slow.queue_head; 373 374 if ((qh->next_queue & (~0xf)) 375 != (uintptr_t)addr_to_phys(instance->transfers_control_full.queue_head)) { 376 usb_log_debug("Control Full QH: %p vs. %p.\n", qh->next_queue & (~0xf), 377 addr_to_phys(instance->transfers_control_full.queue_head));\ 378 } 379 qh = instance->transfers_control_full.queue_head; 380 381 if ((qh->next_queue & (~0xf)) 382 != (uintptr_t)addr_to_phys(instance->transfers_bulk_full.queue_head)) { 383 usb_log_debug("Bulk QH: %p vs. %p.\n", qh->next_queue & (~0xf), 384 addr_to_phys(instance->transfers_bulk_full.queue_head)); 385 } 386 /* 387 uint16_t cmd = pio_read_16(&instance->registers->usbcmd); 388 cmd |= UHCI_CMD_RUN_STOP; 389 pio_write_16(&instance->registers->usbcmd, cmd); 390 */ 376 expected_pa, real_pa); 377 } 378 379 expected_pa = QH(interrupt)->next_queue & (~0xf); 380 real_pa = addr_to_phys(QH(control_slow)); 381 if (expected_pa != real_pa) { 382 usb_log_debug("Control Slow QH: %p vs. %p.\n", 383 expected_pa, real_pa); 384 } 385 386 expected_pa = QH(control_slow)->next_queue & (~0xf); 387 real_pa = addr_to_phys(QH(control_full)); 388 if (expected_pa != real_pa) { 389 usb_log_debug("Control Full QH: %p vs. %p.\n", 390 expected_pa, real_pa); 391 } 392 393 expected_pa = QH(control_full)->next_queue & (~0xf); 394 real_pa = addr_to_phys(QH(bulk_full)); 395 if (expected_pa != real_pa ) { 396 usb_log_debug("Bulk QH: %p vs. %p.\n", 397 expected_pa, real_pa); 398 } 391 399 async_usleep(UHCI_DEBUGER_TIMEOUT); 392 400 } 393 401 return 0; 402 #undef QH 394 403 } 395 404 /*----------------------------------------------------------------------------*/ 396 405 bool allowed_usb_packet( 397 406 bool low_speed, usb_transfer_type_t transfer, size_t size) 398 407 { 399 408 /* see USB specification chapter 5.5-5.8 for magic numbers used here */ 400 switch(transfer) { 401 case USB_TRANSFER_ISOCHRONOUS: 402 return (!low_speed && size < 1024); 403 case USB_TRANSFER_INTERRUPT: 404 return size <= (low_speed ? 8 : 64); 405 case USB_TRANSFER_CONTROL: /* device specifies its own max size */ 406 return (size <= (low_speed ? 8 : 64)); 407 case USB_TRANSFER_BULK: /* device specifies its own max size */ 408 return (!low_speed && size <= 64); 409 switch(transfer) 410 { 411 case USB_TRANSFER_ISOCHRONOUS: 412 return (!low_speed && size < 1024); 413 case USB_TRANSFER_INTERRUPT: 414 return size <= (low_speed ? 8 : 64); 415 case USB_TRANSFER_CONTROL: /* device specifies its own max size */ 416 return (size <= (low_speed ? 8 : 64)); 417 case USB_TRANSFER_BULK: /* device specifies its own max size */ 418 return (!low_speed && size <= 64); 409 419 } 410 420 return false; -
uspace/drv/usbhid/hiddev.c
r1c6c4092 r0f31e2b 149 149 usb_log_info("Processing descriptors...\n"); 150 150 151 // get the first configuration descriptor152 usb_standard_configuration_descriptor_t config_desc;153 154 151 int rc; 155 rc = usb_request_get_bare_configuration_descriptor(&hid_dev->ctrl_pipe, 156 0, &config_desc); 157 158 if (rc != EOK) { 159 usb_log_error("Failed to get bare config descriptor: %s.\n", 152 153 uint8_t *descriptors = NULL; 154 size_t descriptors_size; 155 rc = usb_request_get_full_configuration_descriptor_alloc( 156 &hid_dev->ctrl_pipe, 0, (void **) &descriptors, &descriptors_size); 157 if (rc != EOK) { 158 usb_log_error("Failed to retrieve config descriptor: %s.\n", 160 159 str_error(rc)); 161 160 return rc; 162 }163 164 // prepare space for all underlying descriptors165 uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length);166 if (descriptors == NULL) {167 usb_log_error("No memory!.\n");168 return ENOMEM;169 }170 171 size_t transferred = 0;172 // get full configuration descriptor173 rc = usb_request_get_full_configuration_descriptor(&hid_dev->ctrl_pipe,174 0, descriptors, config_desc.total_length, &transferred);175 176 if (rc != EOK) {177 usb_log_error("Failed to get full config descriptor: %s.\n",178 str_error(rc));179 free(descriptors);180 return rc;181 }182 183 if (transferred != config_desc.total_length) {184 usb_log_error("Configuration descriptor has wrong size (%u, "185 "expected %u).\n", transferred, config_desc.total_length);186 free(descriptors);187 return ELIMIT;188 161 } 189 162 … … 201 174 202 175 rc = usb_endpoint_pipe_initialize_from_configuration( 203 endpoint_mapping, 1, descriptors, config_desc.total_length,176 endpoint_mapping, 1, descriptors, descriptors_size, 204 177 &hid_dev->wire); 205 178 … … 233 206 assert(endpoint_mapping[0].interface != NULL); 234 207 235 rc = usbhid_dev_get_report_descriptor(hid_dev, descriptors, transferred, 208 rc = usbhid_dev_get_report_descriptor(hid_dev, 209 descriptors, descriptors_size, 236 210 (uint8_t *)endpoint_mapping[0].interface); 237 211 -
uspace/drv/usbhid/kbddev.c
r1c6c4092 r0f31e2b 255 255 usb_log_debug2("\nLock keys after: 0x%x\n\n", kbd_dev->lock_keys); 256 256 257 if (key = KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) {257 if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) { 258 258 // do not send anything to the console, this is our business 259 259 return; … … 289 289 290 290 usb_log_debug2("Sending key %d to the console\n", ev.key); 291 assert(kbd_dev->console_phone != -1); 291 if (kbd_dev->console_phone < 0) { 292 usb_log_warning( 293 "Connection to console not ready, key discarded.\n"); 294 return; 295 } 292 296 293 297 async_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, -
uspace/drv/usbhid/usbhid.ma
r1c6c4092 r0f31e2b 1 10 usb&class=hid 2 10 usb&class=HID 1 100 usb&interface&class=HID&subclass=0x01&protocol=0x01 3 2 10 usb&interface&class=HID 4 10 usb&hid -
uspace/drv/usbhub/usbhub.c
r1c6c4092 r0f31e2b 149 149 } 150 150 151 / /configuration descriptor152 /// \TODO check other configurations?153 usb_standard_configuration_descriptor_t config_descriptor;154 opResult = usb_request_get_ bare_configuration_descriptor(151 /* Retrieve full configuration descriptor. */ 152 uint8_t *descriptors = NULL; 153 size_t descriptors_size = 0; 154 opResult = usb_request_get_full_configuration_descriptor_alloc( 155 155 &hub->endpoints.control, 0, 156 &config_descriptor); 157 if(opResult!=EOK){ 158 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult); 156 (void **) &descriptors, &descriptors_size); 157 if (opResult != EOK) { 158 usb_log_error("Could not get configuration descriptor: %s.\n", 159 str_error(opResult)); 159 160 return opResult; 160 161 } 161 //set configuration 162 usb_standard_configuration_descriptor_t *config_descriptor 163 = (usb_standard_configuration_descriptor_t *) descriptors; 164 165 /* Set configuration. */ 162 166 opResult = usb_request_set_configuration(&hub->endpoints.control, 163 config_descriptor.configuration_number); 164 165 if (opResult != EOK) { 166 dprintf(USB_LOG_LEVEL_ERROR, 167 "something went wrong when setting hub`s configuration, %d", 168 opResult); 167 config_descriptor->configuration_number); 168 169 if (opResult != EOK) { 170 usb_log_error("Failed to set hub configuration: %s.\n", 171 str_error(opResult)); 169 172 return opResult; 170 173 } 171 174 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d", 172 config_descriptor.configuration_number); 173 174 //full configuration descriptor 175 size_t transferred = 0; 176 uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length); 177 if (descriptors == NULL) { 178 dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory"); 179 return ENOMEM; 180 } 181 opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control, 182 0, descriptors, 183 config_descriptor.total_length, &transferred); 184 if(opResult!=EOK){ 185 free(descriptors); 186 dprintf(USB_LOG_LEVEL_ERROR, 187 "could not get full configuration descriptor, %d",opResult); 188 return opResult; 189 } 190 if (transferred != config_descriptor.total_length) { 191 dprintf(USB_LOG_LEVEL_ERROR, 192 "received incorrect full configuration descriptor"); 193 return ELIMIT; 194 } 175 config_descriptor->configuration_number); 195 176 196 177 usb_endpoint_mapping_t endpoint_mapping[1] = { … … 204 185 opResult = usb_endpoint_pipe_initialize_from_configuration( 205 186 endpoint_mapping, 1, 206 descriptors, config_descriptor.total_length,187 descriptors, descriptors_size, 207 188 &hub->device_connection); 208 189 if (opResult != EOK) { -
uspace/drv/usbmid/explore.c
r1c6c4092 r0f31e2b 42 42 #include "usbmid.h" 43 43 44 /** Allocate and retrieve full configuration descriptor.45 *46 * @param[in] dev USB device.47 * @param[in] config_index Configuration index.48 * @param[out] size Pointer where to store size of the allocated buffer.49 * @return Allocated full configuration descriptor.50 * @retval NULL Error occured.51 */52 static void *get_configuration_descriptor(usbmid_device_t *dev,53 size_t config_index, size_t *size)54 {55 usb_standard_configuration_descriptor_t config_descriptor;56 int rc = usb_request_get_bare_configuration_descriptor(&dev->ctrl_pipe,57 config_index, &config_descriptor);58 if (rc != EOK) {59 usb_log_error("Failed getting configuration descriptor: %s.\n",60 str_error(rc));61 return NULL;62 }63 64 void *full_config_descriptor = malloc(config_descriptor.total_length);65 if (full_config_descriptor == NULL) {66 usb_log_fatal("Out of memory (wanted: %zuB).\n",67 (size_t) config_descriptor.total_length);68 return NULL;69 }70 71 size_t full_config_descriptor_size;72 rc = usb_request_get_full_configuration_descriptor(&dev->ctrl_pipe,73 config_index,74 full_config_descriptor, config_descriptor.total_length,75 &full_config_descriptor_size);76 if (rc != EOK) {77 usb_log_error("Failed getting configuration descriptor: %s.\n",78 str_error(rc));79 free(full_config_descriptor);80 return NULL;81 }82 83 if (full_config_descriptor_size != config_descriptor.total_length) {84 usb_log_error("Failed getting full configuration descriptor.\n");85 free(full_config_descriptor);86 return NULL;87 }88 89 if (size != NULL) {90 *size = full_config_descriptor_size;91 }92 93 return full_config_descriptor;94 }95 96 44 /** Find starting indexes of all interface descriptors in a configuration. 97 45 * … … 178 126 179 127 size_t config_descriptor_size; 180 uint8_t *config_descriptor_raw = get_configuration_descriptor(dev, 0, 181 &config_descriptor_size); 182 if (config_descriptor_raw == NULL) { 128 uint8_t *config_descriptor_raw = NULL; 129 rc = usb_request_get_full_configuration_descriptor_alloc( 130 &dev->ctrl_pipe, 0, 131 (void **) &config_descriptor_raw, &config_descriptor_size); 132 if (rc != EOK) { 133 usb_log_error("Failed getting full config descriptor: %s.\n", 134 str_error(rc)); 183 135 return false; 184 136 } -
uspace/lib/c/generic/loader.c
r1c6c4092 r0f31e2b 160 160 int rc = async_data_write_start(ldr->phone_id, (void *) pa, pa_len); 161 161 if (rc != EOK) { 162 free(pa); 162 163 async_wait_for(req, NULL); 163 164 return rc; -
uspace/lib/c/generic/vfs/vfs.c
r1c6c4092 r0f31e2b 69 69 char *ncwd_path; 70 70 char *ncwd_path_nc; 71 size_t total_size; 71 72 72 73 fibril_mutex_lock(&cwd_mutex); … … 77 78 return NULL; 78 79 } 79 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 80 total_size = cwd_size + 1 + size + 1; 81 ncwd_path_nc = malloc(total_size); 80 82 if (!ncwd_path_nc) { 81 83 fibril_mutex_unlock(&cwd_mutex); 82 84 return NULL; 83 85 } 84 str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path);86 str_cpy(ncwd_path_nc, total_size, cwd_path); 85 87 ncwd_path_nc[cwd_size] = '/'; 86 88 ncwd_path_nc[cwd_size + 1] = '\0'; 87 89 } else { 88 ncwd_path_nc = malloc(size + 1); 90 total_size = size + 1; 91 ncwd_path_nc = malloc(total_size); 89 92 if (!ncwd_path_nc) { 90 93 fibril_mutex_unlock(&cwd_mutex); … … 93 96 ncwd_path_nc[0] = '\0'; 94 97 } 95 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);98 str_append(ncwd_path_nc, total_size, path); 96 99 ncwd_path = canonify(ncwd_path_nc, retlen); 97 100 if (!ncwd_path) { -
uspace/lib/c/include/ipc/dev_iface.h
r1c6c4092 r0f31e2b 38 38 CHAR_DEV_IFACE, 39 39 40 /** Interface provided by any PCI device. */ 41 PCI_DEV_IFACE, 42 40 43 /** Interface provided by any USB device. */ 41 44 USB_DEV_IFACE, -
uspace/lib/drv/Makefile
r1c6c4092 r0f31e2b 38 38 generic/remote_hw_res.c \ 39 39 generic/remote_usb.c \ 40 generic/remote_pci.c \ 40 41 generic/remote_usbhc.c 41 42 -
uspace/lib/drv/generic/dev_iface.c
r1c6c4092 r0f31e2b 43 43 #include "remote_usb.h" 44 44 #include "remote_usbhc.h" 45 #include "remote_pci.h" 45 46 46 47 static iface_dipatch_table_t remote_ifaces = { … … 48 49 &remote_hw_res_iface, 49 50 &remote_char_dev_iface, 51 &remote_pci_iface, 50 52 &remote_usb_iface, 51 53 &remote_usbhc_iface -
uspace/lib/usb/include/usb/request.h
r1c6c4092 r0f31e2b 106 106 int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *, int, 107 107 void *, size_t, size_t *); 108 int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *, 109 int, void **, size_t *); 108 110 int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t); 109 111 -
uspace/lib/usb/src/request.c
r1c6c4092 r0f31e2b 412 412 } 413 413 414 /** Retrieve full configuration descriptor, allocate space for it. 415 * 416 * The function takes care that full configuration descriptor is returned 417 * (i.e. the function will fail when less data then descriptor.totalLength 418 * is returned). 419 * 420 * @param[in] pipe Control endpoint pipe (session must be already started). 421 * @param[in] index Configuration index. 422 * @param[out] descriptor_ptr Where to store pointer to allocated buffer. 423 * @param[out] descriptor_size Where to store the size of the descriptor. 424 * @return Error code. 425 */ 426 int usb_request_get_full_configuration_descriptor_alloc( 427 usb_endpoint_pipe_t *pipe, int index, 428 void **descriptor_ptr, size_t *descriptor_size) 429 { 430 int rc; 431 432 if (descriptor_ptr == NULL) { 433 return EBADMEM; 434 } 435 436 usb_standard_configuration_descriptor_t bare_config; 437 rc = usb_request_get_bare_configuration_descriptor(pipe, index, 438 &bare_config); 439 if (rc != EOK) { 440 return rc; 441 } 442 443 if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) { 444 return ENOENT; 445 } 446 if (bare_config.total_length < sizeof(bare_config)) { 447 return ELIMIT; 448 } 449 450 void *buffer = malloc(bare_config.total_length); 451 if (buffer == NULL) { 452 return ENOMEM; 453 } 454 455 size_t transferred = 0; 456 rc = usb_request_get_full_configuration_descriptor(pipe, index, 457 buffer, bare_config.total_length, &transferred); 458 if (rc != EOK) { 459 free(buffer); 460 return rc; 461 } 462 463 if (transferred != bare_config.total_length) { 464 free(buffer); 465 return ELIMIT; 466 } 467 468 /* Everything looks okay, copy the pointers. */ 469 470 *descriptor_ptr = buffer; 471 472 if (descriptor_size != NULL) { 473 *descriptor_size = bare_config.total_length; 474 } 475 476 return EOK; 477 } 478 414 479 /** Set configuration of USB device. 415 480 * … … 504 569 * 505 570 * @param[in] pipe Control endpoint pipe (session must be already started). 506 * @param[in] index String index (in native endianess). 571 * @param[in] index String index (in native endianess), 572 * first index has number 1 (index from descriptors can be used directly). 507 573 * @param[in] lang String language (in native endianess). 508 574 * @param[out] string_ptr Where to store allocated string in native encoding. … … 515 581 return EBADMEM; 516 582 } 517 /* Index is actually one byte value. */ 518 if (index > 0xFF) { 583 /* 584 * Index is actually one byte value and zero index is used 585 * to retrieve list of supported languages. 586 */ 587 if ((index < 1) || (index > 0xFF)) { 519 588 return ERANGE; 520 589 } -
uspace/srv/devmap/devmap.c
r1c6c4092 r0f31e2b 123 123 static devmap_handle_t last_handle = 0; 124 124 static devmap_device_t *null_devices[NULL_DEVICES]; 125 126 /* 127 * Dummy list for null devices. This is necessary so that null devices can 128 * be used just as any other devices, e.g. in devmap_device_unregister_core(). 129 */ 130 static LIST_INITIALIZE(dummy_null_driver_devices); 125 131 126 132 static devmap_handle_t devmap_create_handle(void) … … 953 959 device->name = dev_name; 954 960 955 /* Insert device into list of all devices 956 and into null devices array */ 961 /* 962 * Insert device into list of all devices and into null devices array. 963 * Insert device into a dummy list of null driver's devices so that it 964 * can be safely removed later. 965 */ 957 966 list_append(&device->devices, &devices_list); 967 list_append(&device->driver_devices, &dummy_null_driver_devices); 958 968 null_devices[i] = device; 959 969 -
uspace/srv/fs/fat/fat_dentry.c
r1c6c4092 r0f31e2b 42 42 static bool is_d_char(const char ch) 43 43 { 44 if (isalnum(ch) || ch == '_' )44 if (isalnum(ch) || ch == '_' || ch == '-') 45 45 return true; 46 46 else -
uspace/srv/fs/fat/fat_ops.c
r1c6c4092 r0f31e2b 325 325 uint16_t_le2host(d->firstc)); 326 326 if (rc != EOK) { 327 (void) block_put(b); 327 328 (void) fat_node_put(FS_NODE(nodep)); 328 329 return rc; … … 811 812 fibril_mutex_unlock(&childp->idx->lock); 812 813 childp->lnkcnt = 0; 814 childp->refcnt++; /* keep the node in memory until destroyed */ 813 815 childp->dirty = true; 814 816 fibril_mutex_unlock(&childp->lock); … … 1488 1490 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1489 1491 fs_node_t *fn; 1492 fat_node_t *nodep; 1490 1493 int rc; 1491 1494 … … 1499 1502 return; 1500 1503 } 1504 1505 nodep = FAT_NODE(fn); 1506 /* 1507 * We should have exactly two references. One for the above 1508 * call to fat_node_get() and one from fat_unlink(). 1509 */ 1510 assert(nodep->refcnt == 2); 1501 1511 1502 1512 rc = fat_destroy_node(fn); -
uspace/srv/hid/console/console.c
r1c6c4092 r0f31e2b 41 41 #include <ipc/ns.h> 42 42 #include <errno.h> 43 #include <str_error.h> 43 44 #include <ipc/console.h> 44 45 #include <unistd.h> … … 64 65 #define NAME "console" 65 66 #define NAMESPACE "term" 67 /** Interval for checking for new keyboard (1/4s). */ 68 #define HOTPLUG_WATCH_INTERVAL (1000 * 250) 66 69 67 70 /** Phone to the keyboard driver. */ … … 712 715 } 713 716 714 static int connect_keyboard(char *path) 717 static int connect_keyboard_or_mouse(const char *devname, 718 async_client_conn_t handler, const char *path) 715 719 { 716 720 int fd = open(path, O_RDONLY); … … 725 729 } 726 730 727 /* NB: The callback connection is slotted for removal */ 728 sysarg_t phonehash; 729 sysarg_t taskhash; 730 int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, SERVICE_CONSOLE, 731 0, 0, NULL, NULL, NULL, &taskhash, &phonehash); 731 int rc = async_connect_to_me(phone, SERVICE_CONSOLE, 0, 0, handler); 732 732 if (rc != EOK) { 733 printf(NAME ": Failed to create callback from input device\n"); 733 printf(NAME ": " \ 734 "Failed to create callback from input device: %s.\n", 735 str_error(rc)); 734 736 return rc; 735 737 } 736 738 737 async_new_connection(taskhash, phonehash, 0, NULL, keyboard_events); 738 739 printf(NAME ": we got a hit (new keyboard \"%s\").\n", path); 739 printf(NAME ": found %s \"%s\".\n", devname, path); 740 740 741 741 return phone; 742 742 } 743 743 744 /** Try to connect to given keyboard, bypassing provided libc routines. 744 static int connect_keyboard(const char *path) 745 { 746 return connect_keyboard_or_mouse("keyboard", keyboard_events, path); 747 } 748 749 static int connect_mouse(const char *path) 750 { 751 return connect_keyboard_or_mouse("mouse", mouse_events, path); 752 } 753 754 struct hid_class_info { 755 char *classname; 756 int (*connection_func)(const char *); 757 }; 758 759 /** Periodically check for new keyboards in /dev/class/. 745 760 * 746 * @param devmap_path Path to keyboard without /dev prefix.747 * @return Phone or error code.761 * @param arg Class name. 762 * @return This function should never exit. 748 763 */ 749 static int connect_keyboard_bypass(char *devmap_path) 750 { 751 int devmap_phone = async_connect_me_to_blocking(PHONE_NS, 752 SERVICE_DEVMAP, DEVMAP_CLIENT, 0); 753 if (devmap_phone < 0) { 754 return devmap_phone; 755 } 756 ipc_call_t answer; 757 aid_t req = async_send_2(devmap_phone, DEVMAP_DEVICE_GET_HANDLE, 758 0, 0, &answer); 759 760 sysarg_t retval = async_data_write_start(devmap_phone, 761 devmap_path, str_size(devmap_path)); 762 if (retval != EOK) { 763 async_wait_for(req, NULL); 764 async_hangup(devmap_phone); 765 return retval; 766 } 767 768 async_wait_for(req, &retval); 769 770 if (retval != EOK) { 771 async_hangup(devmap_phone); 772 return retval; 773 } 774 775 devmap_handle_t handle = (devmap_handle_t) IPC_GET_ARG1(answer); 776 777 async_hangup(devmap_phone); 778 779 int phone = async_connect_me_to(PHONE_NS, 780 SERVICE_DEVMAP, DEVMAP_CONNECT_TO_DEVICE, handle); 781 if (phone < 0) { 782 return phone; 783 } 784 785 /* NB: The callback connection is slotted for removal */ 786 sysarg_t phonehash; 787 sysarg_t taskhash; 788 int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, SERVICE_CONSOLE, 789 0, 0, NULL, NULL, NULL, &taskhash, &phonehash); 790 if (rc != EOK) { 791 printf(NAME ": Failed to create callback from input device\n"); 792 return rc; 793 } 794 795 async_new_connection(taskhash, phonehash, 0, NULL, keyboard_events); 796 797 printf(NAME ": we got a hit (new keyboard \"/dev/%s\").\n", 798 devmap_path); 799 800 return phone; 801 } 802 803 804 static int check_new_keyboards(void *arg) 805 { 806 char *class_name = (char *) arg; 807 808 int index = 1; 764 static int check_new_device_fibril(void *arg) 765 { 766 struct hid_class_info *dev_info = arg; 767 768 size_t index = 1; 809 769 810 770 while (true) { 811 async_usleep( 1 * 500 * 1000);771 async_usleep(HOTPLUG_WATCH_INTERVAL); 812 772 char *path; 813 int rc = asprintf(&path, "class/%s\\%d", class_name, index); 773 int rc = asprintf(&path, "/dev/class/%s\\%zu", 774 dev_info->classname, index); 814 775 if (rc < 0) { 815 776 continue; 816 777 } 817 778 rc = 0; 818 rc = connect_keyboard_bypass(path);779 rc = dev_info->connection_func(path); 819 780 if (rc > 0) { 820 781 /* We do not allow unplug. */ … … 831 792 /** Start a fibril monitoring hot-plugged keyboards. 832 793 */ 833 static void check_new_keyboards_in_background() 834 { 835 fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard"); 794 static void check_new_devices_in_background(int (*connection_func)(const char *), 795 const char *classname) 796 { 797 struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info)); 798 if (dev_info == NULL) { 799 printf(NAME ": " \ 800 "out of memory, will not start hot-plug-watch fibril.\n"); 801 return; 802 } 803 int rc; 804 805 rc = asprintf(&dev_info->classname, "%s", classname); 806 if (rc < 0) { 807 printf(NAME ": failed to format classname: %s.\n", 808 str_error(rc)); 809 return; 810 } 811 dev_info->connection_func = connection_func; 812 813 fid_t fid = fibril_create(check_new_device_fibril, (void *)dev_info); 836 814 if (!fid) { 837 printf(NAME ": failed to create hot-plug-watch fibril.\n"); 815 printf(NAME 816 ": failed to create hot-plug-watch fibril for %s.\n", 817 classname); 838 818 return; 839 819 } … … 849 829 } 850 830 851 /* Connect to mouse device */ 852 mouse_phone = -1; 853 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 854 855 if (mouse_fd < 0) { 856 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 857 goto skip_mouse; 858 } 859 860 mouse_phone = fd_phone(mouse_fd); 831 mouse_phone = connect_mouse("/dev/hid_in/mouse"); 861 832 if (mouse_phone < 0) { 862 printf(NAME ": Failed to connect to mouse device\n"); 863 goto skip_mouse; 864 } 865 866 if (async_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, mouse_events) 867 != 0) { 868 printf(NAME ": Failed to create callback from mouse device\n"); 869 mouse_phone = -1; 870 goto skip_mouse; 871 } 872 873 skip_mouse: 833 printf(NAME ": Failed to connect to mouse device: %s.\n", 834 str_error(mouse_phone)); 835 } 874 836 875 837 /* Connect to framebuffer driver */ … … 955 917 956 918 /* Start fibril for checking on hot-plugged keyboards. */ 957 check_new_keyboards_in_background(); 919 check_new_devices_in_background(connect_keyboard, "keyboard"); 920 check_new_devices_in_background(connect_mouse, "mouse"); 958 921 959 922 return true;
Note:
See TracChangeset
for help on using the changeset viewer.