From patchwork Tue Jan 29 05:43:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuo-Jung Su X-Patchwork-Id: 216435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E57B82C0094 for ; Tue, 29 Jan 2013 16:44:53 +1100 (EST) Received: from localhost ([::1]:44111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0404-0008Uz-2X for incoming@patchwork.ozlabs.org; Tue, 29 Jan 2013 00:44:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U03zn-00087g-QB for qemu-devel@nongnu.org; Tue, 29 Jan 2013 00:44:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U03zj-0008Hx-SN for qemu-devel@nongnu.org; Tue, 29 Jan 2013 00:44:35 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:34645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U03zj-0008Hp-Ij for qemu-devel@nongnu.org; Tue, 29 Jan 2013 00:44:31 -0500 Received: by mail-pa0-f45.google.com with SMTP id bg2so171171pad.4 for ; Mon, 28 Jan 2013 21:44:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=p8zha0u5HOp7VU5w54ePyCyL+DXfjYU+PVweWSBD5do=; b=e3YyXn+bkkSoAyuDbhMIaL6o3rwLOW9c1L7fBmdhPqs4697oXl/8kr1WXICqDd4Mq2 HlGMlwHafVdTVyZg9ekQOuzaHMfpXutezcHkm9VK0WIGE81D38Lp9rlE3iN0xLrdqiTk DAZQVmgZjoLEEKzf1Pn85B5zXZUS5mqBRcS2fVNhkBQAbRP1ScBfWTTm06VciiEvlD1M ZAt3eXJvn7qg3JpdgO8suuC3KquyvgSeZPKyQpcV1yTnNnR57Uwxmf1h7DHBZUon+ELN qxb3YmPrzlsizs1P3k4oLtGGPPABAauv3nslAbHIlJpMEWA8lxE5ON3apJFSANLRNc8F pwNQ== X-Received: by 10.68.232.169 with SMTP id tp9mr1127604pbc.1.1359438270779; Mon, 28 Jan 2013 21:44:30 -0800 (PST) Received: from localhost.localdomain ([220.132.37.35]) by mx.google.com with ESMTPS id ai8sm7724443pbd.14.2013.01.28.21.44.27 (version=TLSv1 cipher=DES-CBC3-SHA bits=168/168); Mon, 28 Jan 2013 21:44:30 -0800 (PST) From: Kuo-Jung Su To: qemu-devel@nongnu.org Date: Tue, 29 Jan 2013 13:43:53 +0800 Message-Id: <1359438234-5337-2-git-send-email-dantesu@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359438234-5337-1-git-send-email-dantesu@gmail.com> References: <1359438234-5337-1-git-send-email-dantesu@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.220.45 Cc: Peter Crosthwaite , Gerd Hoffmann , Kuo-Jung Su , Andreas Subject: [Qemu-devel] [PATCH 1/2] usb-ehci: replace PORTSC macros with variables X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kuo-Jung Su Replace PORTSC macros with variables which could then be configured in ehci_xxxx_class_init(...) Signed-off-by: Kuo-Jung Su Cc: Gerd Hoffmann Cc: Andreas Cc: Peter Crosthwaite --- hw/usb/hcd-ehci-sysbus.c | 6 ++++++ hw/usb/hcd-ehci.c | 21 +++++++++++++-------- hw/usb/hcd-ehci.h | 12 ++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c index e504703..ae2db1a 100644 --- a/hw/usb/hcd-ehci-sysbus.c +++ b/hw/usb/hcd-ehci-sysbus.c @@ -41,6 +41,8 @@ static void usb_ehci_sysbus_realizefn(DeviceState *dev, Error **errp) s->capsbase = sec->capsbase; s->opregbase = sec->opregbase; + s->portscbase = sec->portscbase; + s->portnr = sec->portnr; s->dma = &dma_context_memory; usb_ehci_initfn(s, dev); @@ -72,6 +74,8 @@ static void ehci_xlnx_class_init(ObjectClass *oc, void *data) sec->capsbase = 0x100; sec->opregbase = 0x140; + sec->portscbase = 0x44; + sec->portnr = NB_PORTS; } static const TypeInfo ehci_xlnx_type_info = { @@ -86,6 +90,8 @@ static void ehci_exynos4210_class_init(ObjectClass *oc, void *data) sec->capsbase = 0x0; sec->opregbase = 0x10; + sec->portscbase = 0x44; + sec->portnr = NB_PORTS; } static const TypeInfo ehci_exynos4210_type_info = { diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 7040659..4c17990 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -988,7 +988,7 @@ static uint64_t ehci_port_read(void *ptr, hwaddr addr, uint32_t val; val = s->portsc[addr >> 2]; - trace_usb_ehci_portsc_read(addr + PORTSC_BEGIN, addr >> 2, val); + trace_usb_ehci_portsc_read(addr + s->portscbase, addr >> 2, val); return val; } @@ -1029,7 +1029,7 @@ static void ehci_port_write(void *ptr, hwaddr addr, uint32_t old = *portsc; USBDevice *dev = s->ports[port].dev; - trace_usb_ehci_portsc_write(addr + PORTSC_BEGIN, addr >> 2, val); + trace_usb_ehci_portsc_write(addr + s->portscbase, addr >> 2, val); /* Clear rwc bits */ *portsc &= ~(val & PORTSC_RWC_MASK); @@ -1062,7 +1062,7 @@ static void ehci_port_write(void *ptr, hwaddr addr, *portsc &= ~PORTSC_RO_MASK; *portsc |= val; - trace_usb_ehci_portsc_change(addr + PORTSC_BEGIN, addr >> 2, *portsc, old); + trace_usb_ehci_portsc_change(addr + s->portscbase, addr >> 2, *portsc, old); } static void ehci_opreg_write(void *ptr, hwaddr addr, @@ -2510,7 +2510,7 @@ void usb_ehci_initfn(EHCIState *s, DeviceState *dev) s->caps[0x01] = 0x00; s->caps[0x02] = 0x00; s->caps[0x03] = 0x01; /* HC version */ - s->caps[0x04] = NB_PORTS; /* Number of downstream ports */ + s->caps[0x04] = s->portnr; /* Number of downstream ports */ s->caps[0x05] = 0x00; /* No companion ports at present */ s->caps[0x06] = 0x00; s->caps[0x07] = 0x00; @@ -2518,8 +2518,13 @@ void usb_ehci_initfn(EHCIState *s, DeviceState *dev) s->caps[0x0a] = 0x00; s->caps[0x0b] = 0x00; + if (s->portnr > NB_PORTS) { + hw_error("hcd-ehci: too many ports! max. port number=%d\n", NB_PORTS); + exit(1); + } + usb_bus_new(&s->bus, &ehci_bus_ops, dev); - for(i = 0; i < NB_PORTS; i++) { + for (i = 0; i < s->portnr; i++) { usb_register_port(&s->bus, &s->ports[i], s, i, &ehci_port_ops, USB_SPEED_MASK_HIGH); s->ports[i].dev = 0; @@ -2538,13 +2543,13 @@ void usb_ehci_initfn(EHCIState *s, DeviceState *dev) memory_region_init_io(&s->mem_caps, &ehci_mmio_caps_ops, s, "capabilities", CAPA_SIZE); memory_region_init_io(&s->mem_opreg, &ehci_mmio_opreg_ops, s, - "operational", PORTSC_BEGIN); + "operational", s->portscbase); memory_region_init_io(&s->mem_ports, &ehci_mmio_port_ops, s, - "ports", PORTSC_END - PORTSC_BEGIN); + "ports", 4 * s->portnr); memory_region_add_subregion(&s->mem, s->capsbase, &s->mem_caps); memory_region_add_subregion(&s->mem, s->opregbase, &s->mem_opreg); - memory_region_add_subregion(&s->mem, s->opregbase + PORTSC_BEGIN, + memory_region_add_subregion(&s->mem, s->opregbase + s->portscbase, &s->mem_ports); } diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index e95bb7e..e587b67 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -40,11 +40,7 @@ #define MMIO_SIZE 0x1000 #define CAPA_SIZE 0x10 -#define PORTSC 0x0044 -#define PORTSC_BEGIN PORTSC -#define PORTSC_END (PORTSC + 4 * NB_PORTS) - -#define NB_PORTS 6 /* Number of downstream ports */ +#define NB_PORTS 6 /* Max. Number of downstream ports */ typedef struct EHCIPacket EHCIPacket; typedef struct EHCIQueue EHCIQueue; @@ -268,6 +264,8 @@ struct EHCIState { int companion_count; uint16_t capsbase; uint16_t opregbase; + uint16_t portscbase; + uint16_t portnr; /* properties */ uint32_t maxframes; @@ -278,7 +276,7 @@ struct EHCIState { */ uint8_t caps[CAPA_SIZE]; union { - uint32_t opreg[PORTSC_BEGIN/sizeof(uint32_t)]; + uint32_t opreg[0x44/sizeof(uint32_t)]; struct { uint32_t usbcmd; uint32_t usbsts; @@ -361,6 +359,8 @@ typedef struct SysBusEHCIClass { uint16_t capsbase; uint16_t opregbase; + uint16_t portscbase; + uint16_t portnr; } SysBusEHCIClass; #endif