From: John Garry <john.garry@huawei.com>
To: <bhelgaas@google.com>, <lorenzo.pieralisi@arm.com>, <arnd@arndb.de>
Cc: <linux-pci@vger.kernel.org>, <rjw@rjwysocki.net>,
<linux-arm-kernel@lists.infradead.org>, <will.deacon@arm.com>,
<wangkefeng.wang@huawei.com>, <linuxarm@huawei.com>,
<andriy.shevchenko@linux.intel.com>,
<linux-kernel@vger.kernel.org>, <catalin.marinas@arm.com>,
John Garry <john.garry@huawei.com>
Subject: [PATCH v4 1/3] lib: logic_pio: Use logical PIO low-level accessors for !CONFIG_INDIRECT_PIO
Date: Tue, 11 Jun 2019 22:12:52 +0800 [thread overview]
Message-ID: <1560262374-67875-2-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1560262374-67875-1-git-send-email-john.garry@huawei.com>
Currently we only use logical PIO low-level accessors for when
CONFIG_INDIRECT_PIO is enabled.
Otherwise we just use inb/out et all directly.
It is useful to now use logical PIO accessors for all cases, so we can add
legality checks to accesses. Such a check would be for ensuring that the
PCI IO port has been IO remapped prior to the access.
Using the logical PIO accesses will add a little processing overhead, but
that's ok as IO port accesses are relatively slow anyway.
Some changes are also made to stop spilling so many lines under
CONFIG_INDIRECT_PIO.
Signed-off-by: John Garry <john.garry@huawei.com>
---
include/linux/logic_pio.h | 7 ++--
lib/logic_pio.c | 83 ++++++++++++++++++++++++++++-----------
2 files changed, 63 insertions(+), 27 deletions(-)
diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h
index cbd9d8495690..06d22b2ec99f 100644
--- a/include/linux/logic_pio.h
+++ b/include/linux/logic_pio.h
@@ -37,7 +37,7 @@ struct logic_pio_host_ops {
size_t dwidth, unsigned int count);
};
-#ifdef CONFIG_INDIRECT_PIO
+#if defined(PCI_IOBASE)
u8 logic_inb(unsigned long addr);
void logic_outb(u8 value, unsigned long addr);
void logic_outw(u16 value, unsigned long addr);
@@ -102,6 +102,7 @@ void logic_outsl(unsigned long addr, const void *buffer, unsigned int count);
#define outsl logic_outsl
#endif
+#if defined(CONFIG_INDIRECT_PIO)
/*
* We reserve 0x4000 bytes for Indirect IO as so far this library is only
* used by the HiSilicon LPC Host. If needed, we can reserve a wider IO
@@ -109,10 +110,10 @@ void logic_outsl(unsigned long addr, const void *buffer, unsigned int count);
*/
#define PIO_INDIRECT_SIZE 0x4000
#define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
-#else
+#else /* CONFIG_INDIRECT_PIO */
#define MMIO_UPPER_LIMIT IO_SPACE_LIMIT
#endif /* CONFIG_INDIRECT_PIO */
-
+#endif /* PCI_IOBASE */
struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode);
unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
resource_size_t hw_addr, resource_size_t size);
diff --git a/lib/logic_pio.c b/lib/logic_pio.c
index feea48fd1a0d..40d9428010e1 100644
--- a/lib/logic_pio.c
+++ b/lib/logic_pio.c
@@ -191,7 +191,8 @@ unsigned long logic_pio_trans_cpuaddr(resource_size_t addr)
return ~0UL;
}
-#if defined(CONFIG_INDIRECT_PIO) && defined(PCI_IOBASE)
+#if defined(PCI_IOBASE)
+#if defined(CONFIG_INDIRECT_PIO)
#define BUILD_LOGIC_IO(bw, type) \
type logic_in##bw(unsigned long addr) \
{ \
@@ -200,11 +201,11 @@ type logic_in##bw(unsigned long addr) \
if (addr < MMIO_UPPER_LIMIT) { \
ret = read##bw(PCI_IOBASE + addr); \
} else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
- struct logic_pio_hwaddr *entry = find_io_range(addr); \
+ struct logic_pio_hwaddr *range = find_io_range(addr); \
+ size_t sz = sizeof(type); \
\
- if (entry && entry->ops) \
- ret = entry->ops->in(entry->hostdata, \
- addr, sizeof(type)); \
+ if (range && range->ops) \
+ ret = range->ops->in(range->hostdata, addr, sz);\
else \
WARN_ON_ONCE(1); \
} \
@@ -216,49 +217,83 @@ void logic_out##bw(type value, unsigned long addr) \
if (addr < MMIO_UPPER_LIMIT) { \
write##bw(value, PCI_IOBASE + addr); \
} else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
- struct logic_pio_hwaddr *entry = find_io_range(addr); \
+ struct logic_pio_hwaddr *range = find_io_range(addr); \
+ size_t sz = sizeof(type); \
\
- if (entry && entry->ops) \
- entry->ops->out(entry->hostdata, \
- addr, value, sizeof(type)); \
+ if (range && range->ops) \
+ range->ops->out(range->hostdata, \
+ addr, value, sz); \
else \
WARN_ON_ONCE(1); \
} \
} \
\
-void logic_ins##bw(unsigned long addr, void *buffer, \
- unsigned int count) \
+void logic_ins##bw(unsigned long addr, void *buf, unsigned int cnt) \
{ \
if (addr < MMIO_UPPER_LIMIT) { \
- reads##bw(PCI_IOBASE + addr, buffer, count); \
+ reads##bw(PCI_IOBASE + addr, buf, cnt); \
} else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
- struct logic_pio_hwaddr *entry = find_io_range(addr); \
+ struct logic_pio_hwaddr *range = find_io_range(addr); \
+ size_t sz = sizeof(type); \
\
- if (entry && entry->ops) \
- entry->ops->ins(entry->hostdata, \
- addr, buffer, sizeof(type), count); \
+ if (range && range->ops) \
+ range->ops->ins(range->hostdata, \
+ addr, buf, sz, cnt); \
else \
WARN_ON_ONCE(1); \
} \
\
} \
\
-void logic_outs##bw(unsigned long addr, const void *buffer, \
- unsigned int count) \
+void logic_outs##bw(unsigned long addr, const void *buf, \
+ unsigned int cnt) \
{ \
if (addr < MMIO_UPPER_LIMIT) { \
- writes##bw(PCI_IOBASE + addr, buffer, count); \
+ writes##bw(PCI_IOBASE + addr, buf, cnt); \
} else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \
- struct logic_pio_hwaddr *entry = find_io_range(addr); \
+ struct logic_pio_hwaddr *range = find_io_range(addr); \
+ size_t sz = sizeof(type); \
\
- if (entry && entry->ops) \
- entry->ops->outs(entry->hostdata, \
- addr, buffer, sizeof(type), count); \
+ if (range && range->ops) \
+ range->ops->outs(range->hostdata, \
+ addr, buf, sz, cnt); \
else \
WARN_ON_ONCE(1); \
} \
}
+#else /* CONFIG_INDIRECT_PIO */
+
+#define BUILD_LOGIC_IO(bw, type) \
+type logic_in##bw(unsigned long addr) \
+{ \
+ type ret = (type)~0; \
+ \
+ if (addr < MMIO_UPPER_LIMIT) \
+ ret = read##bw(PCI_IOBASE + addr); \
+ return ret; \
+} \
+ \
+void logic_out##bw(type value, unsigned long addr) \
+{ \
+ if (addr < MMIO_UPPER_LIMIT) \
+ write##bw(value, PCI_IOBASE + addr); \
+} \
+ \
+void logic_ins##bw(unsigned long addr, void *buf, unsigned int cnt) \
+{ \
+ if (addr < MMIO_UPPER_LIMIT) \
+ reads##bw(PCI_IOBASE + addr, buf, cnt); \
+} \
+ \
+void logic_outs##bw(unsigned long addr, const void *buf, \
+ unsigned int cnt) \
+{ \
+ if (addr < MMIO_UPPER_LIMIT) \
+ writes##bw(PCI_IOBASE + addr, buf, cnt); \
+}
+#endif /* CONFIG_INDIRECT_PIO */
+
BUILD_LOGIC_IO(b, u8)
EXPORT_SYMBOL(logic_inb);
EXPORT_SYMBOL(logic_insb);
@@ -277,4 +312,4 @@ EXPORT_SYMBOL(logic_insl);
EXPORT_SYMBOL(logic_outl);
EXPORT_SYMBOL(logic_outsl);
-#endif /* CONFIG_INDIRECT_PIO && PCI_IOBASE */
+#endif /* PCI_IOBASE */
--
2.17.1
next prev parent reply other threads:[~2019-06-11 14:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-11 14:12 [PATCH v4 0/3] Fix ARM64 crash for accessing unmapped IO port regions John Garry
2019-06-11 14:12 ` John Garry [this message]
2019-06-13 2:39 ` [PATCH v4 1/3] lib: logic_pio: Use logical PIO low-level accessors for !CONFIG_INDIRECT_PIO Bjorn Helgaas
2019-06-13 9:39 ` John Garry
2019-06-13 20:09 ` Bjorn Helgaas
2019-06-14 9:02 ` John Garry
2019-06-14 11:50 ` Bjorn Helgaas
2019-06-14 12:22 ` John Garry
2019-06-13 13:58 ` Bjorn Helgaas
2019-06-13 15:21 ` John Garry
2019-06-11 14:12 ` [PATCH v4 2/3] lib: logic_pio: Reject accesses to unregistered CPU MMIO regions John Garry
2019-06-13 3:20 ` Bjorn Helgaas
2019-06-13 7:47 ` Arnd Bergmann
2019-06-13 10:17 ` John Garry
2019-06-13 13:46 ` Bjorn Helgaas
2019-06-13 14:09 ` John Garry
2019-06-11 14:12 ` [PATCH v4 3/3] lib: logic_pio: Fix up a print John Garry
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=1560262374-67875-2-git-send-email-john.garry@huawei.com \
--to=john.garry@huawei.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=lorenzo.pieralisi@arm.com \
--cc=rjw@rjwysocki.net \
--cc=wangkefeng.wang@huawei.com \
--cc=will.deacon@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).