All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bill Wendling <morbo@google.com>
To: kvm@vger.kernel.org, pbonzini@redhat.com
Cc: jmattson@google.com, Bill Wendling <morbo@google.com>
Subject: [kvm-unit-tests PATCH 2/3] pci: use uint64_t for unsigned long values
Date: Thu, 10 Oct 2019 11:35:05 -0700	[thread overview]
Message-ID: <20191010183506.129921-3-morbo@google.com> (raw)
In-Reply-To: <20191010183506.129921-1-morbo@google.com>

The "pci_bar_*" functions work with unsigned long values, but were using
uint32_t for the data types. Clang complains about this. So we bump up
the type to uint64_t.

  lib/pci.c:110:3: error: implicit conversion from 'unsigned long' to 'uint32_t' (aka 'unsigned int') changes value from 18446744073709551612 to 4294967292 [-Werror,-Wconstant-conversion]
                  PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK;
                ^~~~~~~~~~~~~~~~~~~~~~~~
  /usr/local/google/home/morbo/kvm-unit-tests/lib/linux/pci_regs.h:100:36: note: expanded from macro 'PCI_BASE_ADDRESS_IO_MASK'
  #define  PCI_BASE_ADDRESS_IO_MASK       (~0x03UL)
                                           ^~~~~~~
  lib/pci.c:110:30: error: implicit conversion from 'unsigned long' to 'uint32_t' (aka 'unsigned int') changes value from 18446744073709551600 to 4294967280 [-Werror,-Wconstant-conversion]
                  PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK;
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/local/google/home/morbo/kvm-unit-tests/lib/linux/pci_regs.h:99:37: note: expanded from macro 'PCI_BASE_ADDRESS_MEM_MASK'
  #define  PCI_BASE_ADDRESS_MEM_MASK      (~0x0fUL)
                                         ^~~~~~~

Signed-off-by: Bill Wendling <morbo@google.com>
---
 lib/pci.c | 18 +++++++++---------
 lib/pci.h |  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/pci.c b/lib/pci.c
index daa33e1..e554209 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -104,13 +104,13 @@ pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id)
 	return PCIDEVADDR_INVALID;
 }
 
-uint32_t pci_bar_mask(uint32_t bar)
+uint64_t pci_bar_mask(uint32_t bar)
 {
 	return (bar & PCI_BASE_ADDRESS_SPACE_IO) ?
 		PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK;
 }
 
-uint32_t pci_bar_get(struct pci_dev *dev, int bar_num)
+uint64_t pci_bar_get(struct pci_dev *dev, int bar_num)
 {
 	ASSERT_BAR_NUM(bar_num);
 
@@ -120,13 +120,13 @@ uint32_t pci_bar_get(struct pci_dev *dev, int bar_num)
 
 static phys_addr_t __pci_bar_get_addr(struct pci_dev *dev, int bar_num)
 {
-	uint32_t bar = pci_bar_get(dev, bar_num);
-	uint32_t mask = pci_bar_mask(bar);
+	uint64_t bar = pci_bar_get(dev, bar_num);
+	uint64_t mask = pci_bar_mask(bar);
 	uint64_t addr = bar & mask;
 	phys_addr_t phys_addr;
 
 	if (pci_bar_is64(dev, bar_num))
-		addr |= (uint64_t)pci_bar_get(dev, bar_num + 1) << 32;
+		addr |= pci_bar_get(dev, bar_num + 1) << 32;
 
 	phys_addr = pci_translate_addr(dev->bdf, addr);
 	assert(phys_addr != INVALID_PHYS_ADDR);
@@ -189,7 +189,7 @@ static uint32_t pci_bar_size_helper(struct pci_dev *dev, int bar_num)
 
 phys_addr_t pci_bar_size(struct pci_dev *dev, int bar_num)
 {
-	uint32_t bar, size;
+	uint64_t bar, size;
 
 	size = pci_bar_size_helper(dev, bar_num);
 	if (!size)
@@ -210,7 +210,7 @@ phys_addr_t pci_bar_size(struct pci_dev *dev, int bar_num)
 
 bool pci_bar_is_memory(struct pci_dev *dev, int bar_num)
 {
-	uint32_t bar = pci_bar_get(dev, bar_num);
+	uint64_t bar = pci_bar_get(dev, bar_num);
 
 	return !(bar & PCI_BASE_ADDRESS_SPACE_IO);
 }
@@ -222,7 +222,7 @@ bool pci_bar_is_valid(struct pci_dev *dev, int bar_num)
 
 bool pci_bar_is64(struct pci_dev *dev, int bar_num)
 {
-	uint32_t bar = pci_bar_get(dev, bar_num);
+	uint64_t bar = pci_bar_get(dev, bar_num);
 
 	if (bar & PCI_BASE_ADDRESS_SPACE_IO)
 		return false;
@@ -234,7 +234,7 @@ bool pci_bar_is64(struct pci_dev *dev, int bar_num)
 void pci_bar_print(struct pci_dev *dev, int bar_num)
 {
 	phys_addr_t size, start, end;
-	uint32_t bar;
+	uint64_t bar;
 
 	if (!pci_bar_is_valid(dev, bar_num))
 		return;
diff --git a/lib/pci.h b/lib/pci.h
index 689f03c..cd12938 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -60,8 +60,8 @@ extern pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id);
 extern phys_addr_t pci_bar_get_addr(struct pci_dev *dev, int bar_num);
 extern void pci_bar_set_addr(struct pci_dev *dev, int bar_num, phys_addr_t addr);
 extern phys_addr_t pci_bar_size(struct pci_dev *dev, int bar_num);
-extern uint32_t pci_bar_get(struct pci_dev *dev, int bar_num);
-extern uint32_t pci_bar_mask(uint32_t bar);
+extern uint64_t pci_bar_get(struct pci_dev *dev, int bar_num);
+extern uint64_t pci_bar_mask(uint32_t bar);
 extern bool pci_bar_is64(struct pci_dev *dev, int bar_num);
 extern bool pci_bar_is_memory(struct pci_dev *dev, int bar_num);
 extern bool pci_bar_is_valid(struct pci_dev *dev, int bar_num);
-- 
2.23.0.700.g56cf767bdb-goog


  parent reply	other threads:[~2019-10-10 18:35 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 18:35 [kvm-unit-tests PATCH 0/3] Patches for clang compilation Bill Wendling
2019-10-10 18:35 ` [kvm-unit-tests PATCH 1/3] x86: emulator: use "SSE2" for the target Bill Wendling
2019-10-10 18:35 ` Bill Wendling [this message]
2019-10-11  9:12   ` [kvm-unit-tests PATCH 2/3] pci: use uint64_t for unsigned long values Alexandru Elisei
2019-10-12  8:26     ` [kvm-unit-tests PATCH 1/1] " Bill Wendling
2019-10-14 16:33       ` Alexandru Elisei
2019-10-14 16:36       ` Sean Christopherson
2019-10-10 18:35 ` [kvm-unit-tests PATCH 3/3] Makefile: use "-Werror" in cc-option Bill Wendling
2019-10-15  7:29   ` Thomas Huth
2019-10-15  7:57     ` Bill Wendling
2019-10-15  8:12       ` Thomas Huth
2019-10-14 19:24 ` [kvm-unit-tests PATCH 0/4] Patches for clang compilation Bill Wendling
2019-10-14 19:24   ` [kvm-unit-tests PATCH 1/4] x86: emulator: use "SSE2" for the target Bill Wendling
2019-10-14 19:24   ` [kvm-unit-tests PATCH 2/4] pci: cast the masks to the appropriate size Bill Wendling
2019-10-14 19:24   ` [kvm-unit-tests PATCH 3/4] Makefile: use "-Werror" in cc-option Bill Wendling
2019-10-14 19:24   ` [kvm-unit-tests PATCH 4/4] Makefile: add "cxx-option" for C++ builds Bill Wendling
2019-10-14 19:25   ` [kvm-unit-tests PATCH 0/4] Patches for clang compilation Bill Wendling
2019-10-14 23:56     ` Nadav Amit
2019-10-15  0:04       ` Bill Wendling
2019-10-15  0:04 ` [kvm-unit-tests PATCH v2 " Bill Wendling
2019-10-15  0:04   ` [kvm-unit-tests PATCH v2 1/4] x86: emulator: use "SSE2" for the target Bill Wendling
2019-10-15  0:04   ` [kvm-unit-tests PATCH v2 2/4] pci: cast the masks to the appropriate size Bill Wendling
2019-10-15  0:04   ` [kvm-unit-tests PATCH v2 3/4] Makefile: use "-Werror" in cc-option Bill Wendling
2019-10-15  0:04   ` [kvm-unit-tests PATCH v2 4/4] Makefile: add "cxx-option" for C++ builds Bill Wendling
2019-10-30 21:04   ` [kvm-unit-tests PATCH v3 0/6] Patches for clang compilation Bill Wendling
2019-10-30 21:04     ` [kvm-unit-tests PATCH v3 1/6] x86: emulator: use "SSE2" for the target Bill Wendling
2019-11-28  7:31       ` Thomas Huth
2019-10-30 21:04     ` [kvm-unit-tests PATCH v3 2/6] pci: cast the masks to the appropriate size Bill Wendling
2019-11-08  8:39       ` Thomas Huth
2019-10-30 21:04     ` [kvm-unit-tests PATCH v3 3/6] Makefile: use "-Werror" in cc-option Bill Wendling
2019-11-08  8:43       ` Thomas Huth
2019-11-08 20:36         ` Bill Wendling
2019-10-30 21:04     ` [kvm-unit-tests PATCH v3 4/6] Makefile: add "cxx-option" for C++ builds Bill Wendling
2019-11-08  8:48       ` Thomas Huth
2019-10-30 21:04     ` [kvm-unit-tests PATCH v3 5/6] x86: use a non-negative number in shift Bill Wendling
2019-11-08  8:31       ` Thomas Huth
2019-10-30 21:04     ` [kvm-unit-tests PATCH v3 6/6] x86: use inline asm to retrieve stack pointer Bill Wendling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191010183506.129921-3-morbo@google.com \
    --to=morbo@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.