From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f172.google.com (mail-pf0-f172.google.com [209.85.192.172]) by dpdk.org (Postfix) with ESMTP id 9E5642716 for ; Wed, 16 Dec 2015 16:05:59 +0100 (CET) Received: by mail-pf0-f172.google.com with SMTP id o64so13388599pfb.3 for ; Wed, 16 Dec 2015 07:05:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mvista-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2vwoOhwj4quyup5gKglSJaInnTB0JBYCMuXIOAYVpGQ=; b=rQISNzI+t0/VzbbC4M48eY7AjLyzC435ngkW2YFgGo6oiPoC4u45NKdnVjPGarWjjL OoktiVLpxduTaUywZKprXm5B0h/sa37F87W70PInVvxD2udIpEvY0ybrJzfN+ky9v2+o dFiAElrJymGz3s7TOkDaiQ0EF5nG3BDB0jFBWsmSl1WsfInVOYUm/zdYX9qicTrCwT8d DuSe8i00pb7nIL1vTbTf88L4SPy2U/se9PMg/8KhhSu9iVR60ruPysZvu/YMrpFU3bEI j/qPoywsVgm6aAYJtyoq5oAZzDf3vmthFhbGV4hRjh30zOsgN65myeVUEx0Ej6W6XAlk XSJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=2vwoOhwj4quyup5gKglSJaInnTB0JBYCMuXIOAYVpGQ=; b=IjzyLwjhxnVJiHJHMXbB0GTqVI+XuGt6FDKUSiyS2l1U7gT5yFDic4rEh1G/OF/iGw Wzdnr4YslOTBMHScvo3WXjb1IlmjaRZBcbIVV4W93lWz0nJUlSzTYh5yRnJeqlBAZrKe adaYqlUDQonjfueqlwcKFnqrpaLekPRkpOrDYfGn5s4G298fnY0DfV3hMcBTZGliNdkW JLlebx15MibQ5c7W4Y2pfICJBO7/UEW1U3EXIDlGk8v+ukK3r87swm1VyuYQZW0+3/PC tTYPJD3s05Q/TqcSH6udJJ99SAx1iQS0hXH/Ll8KG1LtrNL6g/qH3Z/Mt6lstIqwUPYv +SvA== X-Gm-Message-State: ALoCoQkTkWX10o/51ENF8fCT5nE+Z42CZiI2v7a/XGA5o5bg9ULuqKQZwZDdJXsN3qmMda4IUW4gn7YYrF0g2gg6Zies1Oj2BNE8UyUIkCkTZbk8MCgCx3I= MIME-Version: 1.0 X-Received: by 10.98.67.130 with SMTP id l2mr6029055pfi.93.1450278358993; Wed, 16 Dec 2015 07:05:58 -0800 (PST) Received: by 10.66.13.233 with HTTP; Wed, 16 Dec 2015 07:05:58 -0800 (PST) In-Reply-To: <20151216145846.GX29571@yliu-dev.sh.intel.com> References: <1450098032-21198-1-git-send-email-sshukla@mvista.com> <1450098032-21198-6-git-send-email-sshukla@mvista.com> <20151216134850.GU29571@yliu-dev.sh.intel.com> <20151216142326.GV29571@yliu-dev.sh.intel.com> <20151216145846.GX29571@yliu-dev.sh.intel.com> Date: Wed, 16 Dec 2015 20:35:58 +0530 Message-ID: From: Santosh Shukla To: Yuanhan Liu Content-Type: text/plain; charset=UTF-8 Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [ [PATCH v2] 05/13] virtio: change io_base datatype from uint32_t to uint64_type X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Dec 2015 15:06:00 -0000 On Wed, Dec 16, 2015 at 8:28 PM, Yuanhan Liu wrote: > On Wed, Dec 16, 2015 at 08:09:40PM +0530, Santosh Shukla wrote: >> On Wed, Dec 16, 2015 at 7:53 PM, Yuanhan Liu >> wrote: >> > On Wed, Dec 16, 2015 at 07:31:57PM +0530, Santosh Shukla wrote: >> >> On Wed, Dec 16, 2015 at 7:18 PM, Yuanhan Liu >> >> wrote: >> >> > On Mon, Dec 14, 2015 at 06:30:24PM +0530, Santosh Shukla wrote: >> >> >> In x86 case io_base to store ioport address not more than 65535 ioports. i.e..0 >> >> >> to ffff but in non-x86 case in particular arm64 it need to store more than 32 >> >> >> bit address so changing io_base datatype from 32 to 64. >> >> >> >> >> >> Signed-off-by: Santosh Shukla >> >> >> --- >> >> >> drivers/net/virtio/virtio_ethdev.c | 2 +- >> >> >> drivers/net/virtio/virtio_pci.h | 4 ++-- >> >> >> 2 files changed, 3 insertions(+), 3 deletions(-) >> >> >> >> >> >> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c >> >> >> index d928339..620e0d4 100644 >> >> >> --- a/drivers/net/virtio/virtio_ethdev.c >> >> >> +++ b/drivers/net/virtio/virtio_ethdev.c >> >> >> @@ -1291,7 +1291,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) >> >> >> return -1; >> >> >> >> >> >> hw->use_msix = virtio_has_msix(&pci_dev->addr); >> >> >> - hw->io_base = (uint32_t)(uintptr_t)pci_dev->mem_resource[0].addr; >> >> >> + hw->io_base = (uint64_t)(uintptr_t)pci_dev->mem_resource[0].addr; >> >> > >> >> > I'd suggest to move the io_base assignment (and cast) into virtio_ioport_init() >> >> > so that we could do the correct cast there, say cast it to uint32_t for >> >> > X86, and uint64_t for others. >> >> > >> >> >> >> Ok. >> >> >> >> This was deliberately done considering your 1.0 virtio spec patch do >> >> care for uint64_t types and in arm64 case, If I plan to use those >> >> future patches, IMO it make more sense to me keep it in uint64_t way; >> > >> > I did different cast, 32 bit for legacy virtio pci device, and 64 bit >> > for modern virtio pci device. >> > >> >> Also in x86 case max address could of type 0x1000-101f and so forth; >> >> changing data-type to uint64_t default wont effect such address, >> >> right? >> > >> > Right, but what's the harm of doing the right cast? :) >> > >> >> Agree. >> >> >> And hw->io_base by looking at virtio_pci.h function like >> >> inb/outb etc.. takes io_base address as unsigned long types which is >> >> arch dependent; i.e.. 4 byte for 32 bit and 8 for 64 bit so the lower >> >> level rd/wr apis are taking care of data-types accordingly. >> > >> > Didn't get it. inb/outb takes "unsigned short" arguments, but not >> > "unsigned long". >> > >> >> sys/io.h in x86 case using unsigned short int types.. >> >> include/asm-generic/io.h for arm64 using it unsigned long (from linux >> header files) >> >> In such case keeping >> #define VIRTIO_PCI_REG_ADDR(hw, reg) \ >> (unsigned short)((hw)->io_base + (reg)) >> >> would be x86 specific and what I thought and used in this patch is >> >> #define VIRTIO_PCI_REG_ADDR(hw, reg) \ >> (unsigned long)((hw)->io_base + (reg)) >> >> to avoid ifdef ARM or non-x86..clutter, I know data-type is not right >> fit for x86 sys/io.h but considering possible address inside >> hw->io_base, wont effect functionality and performance my any mean. >> That is why at virtio_ethdev_init() i choose to keep it in hw->io_base >> = (uint64_t) types. >> >> Otherwise I'll have to duplicate VIRTIO_PCI_REG_XXX definition for >> non-x86 case, Pl. suggest better alternative. Thanks > > > My understanding is that if you have done the right cast in the first > time (at the io_base assignment), casting from a short type to a longer > type will not matter: the upper bits will be filled with zero. > > So, I guess we are fine here. I'm thinking that the extra cast in > VIRTIO_PCI_REG_ADDR() is not necessary, as C will do the right > cast for different inb(), say cast it to "unsigned short" for x86, > and "unsigned long" for your arm implementation. The same to > other io helpers. > so to summarize and correct me if i misunderstood, keep hw->io_base = (uint64_t) and remove extra cast {i.e.. (unsigned short) for x86 or (unsigned long) for non-x86/arm64 case} in VIRTIO_PCI_REG_ADDR(). did I got everything alright? > --yliu