From 9f56364cad42e3310a30f525d9957f956351c554 Mon Sep 17 00:00:00 2001 From: "Wu, Xiaoguang" Date: Thu, 10 May 2018 22:20:18 +0800 Subject: [PATCH] DM USB: xHCI: add log level switch Support log level options, which could change the related log level without code change. The new usage: -s ,xhci,[bus1-port1,bus2-port2]:[tablet]:[log=x] eg: -s 8,xhci,1-2,2-2:log=D eg: -s 7,xhci,tablet eg: -s 7,xhci,1-2,2-2:tablet Note: please follow the board hardware design, assign the ports according to the receptacle connection Change-Id: I44639c7b076d21a40eb8f7b99cea8decc5c13c0c Signed-off-by: Wu, Xiaoguang Reviewed-by: Shuo Liu Reviewed-by: Yu Wang Reviewed-by: Zhao Yakui Acked-by: Eddie Dong --- devicemodel/hw/pci/xhci.c | 44 +++++++++++++++++++++++++++------- devicemodel/hw/usb_core.c | 28 ++++++++++++++++++++++ devicemodel/include/usb_core.h | 1 + 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index bbd1a079a..13bc6572a 100644 --- a/devicemodel/hw/pci/xhci.c +++ b/devicemodel/hw/pci/xhci.c @@ -334,9 +334,11 @@ static int pci_xhci_xfer_complete(struct pci_xhci_vdev *xdev, int *do_intr); static inline int pci_xhci_is_valid_portnum(int n); static int pci_xhci_parse_tablet(struct pci_xhci_vdev *xdev, char *opts); +static int pci_xhci_parse_log_level(struct pci_xhci_vdev *xdev, char *opts); static struct pci_xhci_option_elem xhci_option_table[] = { - {"tablet", pci_xhci_parse_tablet} + {"tablet", pci_xhci_parse_tablet}, + {"log", pci_xhci_parse_log_level} }; static int @@ -3071,9 +3073,9 @@ static void pci_xhci_device_usage(char *opt) { static const char *usage_str = "usage:\r\n" - " -s ,xhci,[bus1-port1,bus2-port2]:[tablet]\r\n" + " -s ,xhci,[bus1-port1,bus2-port2]:[tablet]:[log=x]\r\n" " eg: -s 8,xhci,1-2,2-2\r\n" - " eg: -s 7,xhci,tablet\r\n" + " eg: -s 7,xhci,tablet:log=D\r\n" " eg: -s 7,xhci,1-2,2-2:tablet\r\n" " Note: please follow the board hardware design, assign the " " ports according to the receptacle connection\r\n"; @@ -3082,6 +3084,37 @@ pci_xhci_device_usage(char *opt) UPRINTF(LFTL, "%s", usage_str); } +static int +pci_xhci_parse_log_level(struct pci_xhci_vdev *xdev, char *opts) +{ + char level; + char *s, *o; + int rc = 0; + + assert(opts); + + o = s = strdup(opts); + if (!(s && s[0] == 'l' && s[1] == 'o' && s[2] == 'g')) { + rc = -1; + goto errout; + } + + s = strchr(opts, '='); + if (!s) { + rc = -2; + goto errout; + } + + level = *(s+1); + usb_parse_log_level(level); + +errout: + if (rc) + printf("USB: fail to set log level, rc=%d\r\n", rc); + free(o); + return rc; +} + static int pci_xhci_parse_bus_port(struct pci_xhci_vdev *xdev, char *opts) { @@ -3322,11 +3355,6 @@ pci_xhci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) else error = 0; - /* - * TODO: - * Will add command line option in subsequent patches for calling - * usb_dev_sys_init if new parameters are used. - */ if (usb_dev_sys_init(pci_xhci_native_usb_dev_conn_cb, pci_xhci_native_usb_dev_disconn_cb, pci_xhci_usb_dev_notify_cb, diff --git a/devicemodel/hw/usb_core.c b/devicemodel/hw/usb_core.c index e44ecfca4..5be90f32b 100644 --- a/devicemodel/hw/usb_core.c +++ b/devicemodel/hw/usb_core.c @@ -219,3 +219,31 @@ usb_native_is_port_existed(uint8_t bus_num, uint8_t port_num) close(fd); return 1; } + +void usb_parse_log_level(char level) +{ + switch (level) { + case 'F': + case 'f': + usb_set_log_level(LFTL); + break; + case 'W': + case 'w': + usb_set_log_level(LWRN); + break; + case 'I': + case 'i': + usb_set_log_level(LINF); + break; + case 'D': + case 'd': + usb_set_log_level(LDBG); + break; + case 'V': + case 'v': + usb_set_log_level(LVRB); + break; + default: + usb_set_log_level(LFTL); + } +} diff --git a/devicemodel/include/usb_core.h b/devicemodel/include/usb_core.h index b535bb7c2..b652a1196 100644 --- a/devicemodel/include/usb_core.h +++ b/devicemodel/include/usb_core.h @@ -205,6 +205,7 @@ enum USB_ERRCODE { extern int usb_log_level; inline int usb_get_log_level(void) { return usb_log_level; } inline void usb_set_log_level(int level) { usb_log_level = level; } +void usb_parse_log_level(char level); struct usb_devemu *usb_emu_finddev(char *name); int usb_native_is_bus_existed(uint8_t bus_num); int usb_native_is_ss_port(uint8_t bus_of_port);