[PATCH rtems-libbsd v3 1/3] rtemsbsd/bus: Add PCI support to the nexus bus
Chris Johns
chrisj at rtems.org
Mon Aug 9 01:21:51 UTC 2021
- Add PCI IO region support
- Add support map buffers to PCI address space
- Add BSP conditional IO space support. Some PC implementations
have PCI IO space mapped differently to memory space and this needs
to be reflected in the busspace.
- Include bsp.h to pick per BSP configuration.
Closes #4245
---
rtemsbsd/include/machine/bus.h | 370 ++++++++++++++++++--------
rtemsbsd/rtems/rtems-kernel-bus-dma.c | 5 +-
rtemsbsd/rtems/rtems-kernel-nexus.c | 52 +++-
3 files changed, 312 insertions(+), 115 deletions(-)
diff --git a/rtemsbsd/include/machine/bus.h b/rtemsbsd/include/machine/bus.h
index 2f0e7ad6..999f5d45 100644
--- a/rtemsbsd/include/machine/bus.h
+++ b/rtemsbsd/include/machine/bus.h
@@ -6,9 +6,13 @@
* @brief TODO.
*
* File origin from FreeBSD 'sys/amd64/include/bus.h'.
+ *
+ * Conditionally supports PCI IO regions (IO Ports).
*/
/*-
+ * Copyright (c) 2021 Chris Johns. All rights reserved.
+ *
* Copyright (c) 2009, 2015 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
@@ -25,7 +29,7 @@
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer as
* the first lines of this file unmodified.
@@ -34,7 +38,7 @@
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -123,9 +127,46 @@
#endif
#ifdef __i386__
- #error "your include paths are wrong"
+ #error "x86 has its own bus.h; check your include paths are correct"
#endif
+#include <bsp.h>
+
+/*
+ * BSP PCI Support
+ *
+ * The RTEMS Nexus bus support can optionaly support PC PCI spaces that
+ * mapped to BSP speciic address spaces. Add the following define to
+ * the BSP header file to enable this support:
+ *
+ * #define BSP_HAS_PC_PCI
+ *
+ * If enabled a BSP must the following IO region calls:
+ *
+ * inb : read 8 bits
+ * outb : write 8 bits
+ * inw : read 16 bits
+ * outw : write 16 bits
+ * inl : read 32 bits
+ * outl : write 32 bits
+ *
+ * The BSP needs to provide the DRAM address space offset
+ * PCI_DRAM_OFFSET. This is the base address of the DRAM as seen by a
+ * PCI master.
+ *
+ * i386 BSPs have a special bus.h file and do not use this file.
+ */
+
+#ifdef BSP_HAS_PC_PCI
+
+/*
+ * Values for the bus space tag, not to be used directly by MI code.
+ */
+#define BSP_BUS_SPACE_IO 0 /* space is i/o space */
+#define BSP_BUS_SPACE_MEM 1 /* space is mem space */
+
+#endif /* BSP_HAS_PC_PCI */
+
/*
* Bus address alignment.
*/
@@ -144,6 +185,7 @@
/*
* Bus access.
*/
+#define BUS_SPACE_INVALID_DATA (~0)
#define BUS_SPACE_UNRESTRICTED (~0U)
/*
@@ -222,6 +264,102 @@ bus_space_barrier(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
/* Do nothing */
}
+/*
+ * BSP Bus Space Map Support
+ *
+ * Provide as C macros in the BSP header (bsp.h) the following:
+ *
+ * RTEMS_BSP_READ_1
+ * RTEMS_BSP_READ_2
+ * RTEMS_BSP_READ_4
+ * RTEMS_BSP_READ_8
+ * RTEMS_BSP_WRITE_1
+ * RTEMS_BSP_WRITE_2
+ * RTEMS_BSP_WRITE_4
+ * RTEMS_BSP_WRITE_8
+ */
+
+static __inline uint8_t
+bsp_bus_space_read_1(const uint8_t __volatile *bsp)
+{
+#if defined(RTEMS_BSP_READ_1)
+ return RTEMS_BSP_READ_1(bsp);
+#else
+ return (*bsp);
+#endif
+}
+
+static __inline uint16_t
+bsp_bus_space_read_2(const uint16_t __volatile *bsp)
+{
+#if defined(RTEMS_BSP_READ_2)
+ return RTEMS_BSP_READ_2(bsp);
+#else
+ return (*bsp);
+#endif
+}
+
+static __inline uint32_t
+bsp_bus_space_read_4(const uint32_t __volatile *bsp)
+{
+#if defined(RTEMS_BSP_READ_4)
+ return RTEMS_BSP_READ_4(bsp);
+#else
+ return (*bsp);
+#endif
+}
+
+static __inline uint64_t
+bsp_bus_space_read_8(const uint64_t __volatile *bsp)
+{
+#if defined(RTEMS_BSP_READ_8)
+ return RTEMS_BSP_READ_8(bsp);
+#else
+ return (*bsp);
+#endif
+}
+
+static __inline void
+bsp_bus_space_write_1(uint8_t __volatile *bsp, uint8_t val)
+{
+#if defined(RTEMS_BSP_WRITE_1)
+ RTEMS_BSP_WRITE_1(bsp, val);
+#else
+ *bsp = val;
+#endif
+}
+
+static __inline void
+bsp_bus_space_write_2(uint16_t __volatile *bsp, uint16_t val)
+{
+#if defined(RTEMS_BSP_WRITE_2)
+ RTEMS_BSP_WRITE_2(bsp, val);
+#else
+ *bsp = val;
+#endif
+}
+
+static __inline void
+bsp_bus_space_write_4(uint32_t __volatile *bsp, uint32_t val)
+{
+#if defined(RTEMS_BSP_WRITE_4)
+ RTEMS_BSP_WRITE_4(bsp, val);
+#else
+ *bsp = val;
+#endif
+}
+
+static __inline void
+bsp_bus_space_write_8(uint64_t __volatile *bsp, uint64_t val)
+{
+#if defined(RTEMS_BSP_WRITE_8)
+ RTEMS_BSP_WRITE_8(bsp, val);
+#else
+ *bsp = val;
+#endif
+}
+
+
/*
* Read 1 unit of data from bus space described by the tag, handle and ofs
* tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
@@ -230,29 +368,48 @@ bus_space_barrier(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
static __inline uint8_t
bus_space_read_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ return inb(bsh + ofs);
+ }
+#endif
uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
- return (*bsp);
+ return bsp_bus_space_read_1(bsp);
}
static __inline uint16_t
bus_space_read_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ return inw(bsh + ofs);
+ }
+#endif
uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
- return (*bsp);
+ return bsp_bus_space_read_2(bsp);
}
static __inline uint32_t
bus_space_read_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ return inl(bsh + ofs);
+ }
+#endif
uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
- return (*bsp);
+ return bsp_bus_space_read_4(bsp);
}
static __inline uint64_t
bus_space_read_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO)
+ return BUS_SPACE_INVALID_DATA;
+#endif
uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
- return (*bsp);
+ return bsp_bus_space_read_8(bsp);
}
@@ -265,32 +422,55 @@ static __inline void
bus_space_write_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
uint8_t val)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ outb(val, bsh + ofs);
+ return;
+ }
+#endif
uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
- *bsp = val;
+ bsp_bus_space_write_1(bsp, val);
}
static __inline void
bus_space_write_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
uint16_t val)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ outw(val, bsh + ofs);
+ return;
+ }
+#endif
uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
- *bsp = val;
+ bsp_bus_space_write_2(bsp, val);
}
static __inline void
bus_space_write_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
uint32_t val)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ outl(val, bsh + ofs);
+ return;
+ }
+#endif
uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
- *bsp = val;
+ bsp_bus_space_write_4(bsp, val);
}
static __inline void
bus_space_write_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
uint64_t val)
{
+#ifdef BSP_HAS_PC_PCI
+ if (bst == BSP_BUS_SPACE_IO) {
+ return;
+ }
+#endif
uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
- *bsp = val;
+ bsp_bus_space_write_8(bsp, val);
}
@@ -305,7 +485,7 @@ bus_space_read_multi_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bufp++ = *bsp;
+ *bufp++ = bsp_bus_space_read_1(bsp);
}
}
@@ -315,7 +495,7 @@ bus_space_read_multi_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bufp++ = *bsp;
+ *bufp++ = bsp_bus_space_read_2(bsp);
}
}
@@ -325,7 +505,7 @@ bus_space_read_multi_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bufp++ = *bsp;
+ *bufp++ = bsp_bus_space_read_4(bsp);
}
}
@@ -335,7 +515,7 @@ bus_space_read_multi_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bufp++ = *bsp;
+ *bufp++ = bsp_bus_space_read_8(bsp);
}
}
@@ -351,7 +531,7 @@ bus_space_write_multi_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = *bufp++;
+ bsp_bus_space_write_1(bsp, *bufp++);
}
}
@@ -361,7 +541,7 @@ bus_space_write_multi_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = *bufp++;
+ bsp_bus_space_write_2(bsp, *bufp++);
}
}
@@ -371,7 +551,7 @@ bus_space_write_multi_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = *bufp++;
+ bsp_bus_space_write_4(bsp, *bufp++);
}
}
@@ -381,7 +561,7 @@ bus_space_write_multi_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = *bufp++;
+ bsp_bus_space_write_8(bsp, *bufp++);
}
}
@@ -396,10 +576,9 @@ static __inline void
bus_space_read_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint8_t *bufp, bus_size_t count)
{
+ uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
- *bufp++ = *bsp;
- ofs += 1;
+ *bufp++ = bsp_bus_space_read_1(bsp++);
}
}
@@ -407,10 +586,9 @@ static __inline void
bus_space_read_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint16_t *bufp, bus_size_t count)
{
+ uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
- *bufp++ = *bsp;
- ofs += 2;
+ *bufp++ = bsp_bus_space_read_2(bsp++);
}
}
@@ -418,10 +596,9 @@ static __inline void
bus_space_read_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint32_t *bufp, bus_size_t count)
{
+ uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
- *bufp++ = *bsp;
- ofs += 4;
+ *bufp++ = bsp_bus_space_read_4(bsp++);
}
}
@@ -429,10 +606,9 @@ static __inline void
bus_space_read_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint64_t *bufp, bus_size_t count)
{
+ uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
- *bufp++ = *bsp;
- ofs += 8;
+ *bufp++ = bsp_bus_space_read_8(bsp++);
}
}
@@ -447,10 +623,9 @@ static __inline void
bus_space_write_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, const uint8_t *bufp, bus_size_t count)
{
+ uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
- *bsp = *bufp++;
- ofs += 1;
+ bsp_bus_space_write_1(bsp++, *bufp++);
}
}
@@ -458,10 +633,9 @@ static __inline void
bus_space_write_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, const uint16_t *bufp, bus_size_t count)
{
+ uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
- *bsp = *bufp++;
- ofs += 2;
+ bsp_bus_space_write_2(bsp++, *bufp++);
}
}
@@ -469,10 +643,9 @@ static __inline void
bus_space_write_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, const uint32_t *bufp, bus_size_t count)
{
+ uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
- *bsp = *bufp++;
- ofs += 4;
+ bsp_bus_space_write_4(bsp++, *bufp++);
}
}
@@ -480,10 +653,9 @@ static __inline void
bus_space_write_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, const uint64_t *bufp, bus_size_t count)
{
+ uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
- *bsp = *bufp++;
- ofs += 8;
+ bsp_bus_space_write_8(bsp++, *bufp++);
}
}
@@ -499,7 +671,7 @@ bus_space_set_multi_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = val;
+ bsp_bus_space_write_1(bsp, val);
}
}
@@ -509,7 +681,7 @@ bus_space_set_multi_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = val;
+ bsp_bus_space_write_2(bsp, val);
}
}
@@ -519,7 +691,7 @@ bus_space_set_multi_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = val;
+ bsp_bus_space_write_4(bsp, val);
}
}
@@ -529,7 +701,7 @@ bus_space_set_multi_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
{
uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- *bsp = val;
+ bsp_bus_space_write_8(bsp, val);
}
}
@@ -544,10 +716,9 @@ static __inline void
bus_space_set_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint8_t val, bus_size_t count)
{
+ uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
- *bsp = val;
- ofs += 1;
+ bsp_bus_space_write_1(bsp++, val);
}
}
@@ -555,10 +726,9 @@ static __inline void
bus_space_set_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint16_t val, bus_size_t count)
{
+ uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
- *bsp = val;
- ofs += 2;
+ bsp_bus_space_write_2(bsp++, val);
}
}
@@ -566,10 +736,9 @@ static __inline void
bus_space_set_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint32_t val, bus_size_t count)
{
+ uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
- *bsp = val;
- ofs += 4;
+ bsp_bus_space_write_4(bsp++, val);
}
}
@@ -577,10 +746,9 @@ static __inline void
bus_space_set_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
bus_size_t ofs, uint64_t val, bus_size_t count)
{
+ uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
while (count-- > 0) {
- uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
- *bsp = val;
- ofs += 8;
+ bsp_bus_space_write_8(bsp++, val);
}
}
@@ -596,23 +764,21 @@ static __inline void
bus_space_copy_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
{
- bus_addr_t dst = bsh1 + ofs1;
- bus_addr_t src = bsh2 + ofs2;
- uint8_t __volatile *dstp = (uint8_t __volatile *) dst;
- uint8_t __volatile *srcp = (uint8_t __volatile *) src;
+ uint8_t __volatile *dst = (uint8_t __volatile *)(bsh1 + ofs1);
+ uint8_t __volatile *src = (uint8_t __volatile *)(bsh2 + ofs2);
if (dst > src) {
src += count - 1;
dst += count - 1;
while (count-- > 0) {
- *dstp = *srcp;
- src -= 1;
- dst -= 1;
+ bsp_bus_space_write_1(dst, bsp_bus_space_read_1(src));
+ src--;
+ dst--;
}
} else {
while (count-- > 0) {
- *dstp = *srcp;
- src += 1;
- dst += 1;
+ bsp_bus_space_write_1(dst, bsp_bus_space_read_1(src));
+ src++;
+ dst++;
}
}
}
@@ -621,23 +787,21 @@ static __inline void
bus_space_copy_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
{
- bus_addr_t dst = bsh1 + ofs1;
- bus_addr_t src = bsh2 + ofs2;
- uint16_t __volatile *dstp = (uint16_t __volatile *) dst;
- uint16_t __volatile *srcp = (uint16_t __volatile *) src;
+ uint16_t __volatile *dst = (uint16_t __volatile *)(bsh1 + ofs1);
+ uint16_t __volatile *src = (uint16_t __volatile *)(bsh2 + ofs2);;
if (dst > src) {
- src += (count - 1) << 1;
- dst += (count - 1) << 1;
+ src += count - 1;
+ dst += count - 1;
while (count-- > 0) {
- *dstp = *srcp;
- src -= 2;
- dst -= 2;
+ bsp_bus_space_write_2(dst, bsp_bus_space_read_2(src));
+ src--;
+ dst--;
}
} else {
while (count-- > 0) {
- *dstp = *srcp;
- src += 2;
- dst += 2;
+ bsp_bus_space_write_2(dst, bsp_bus_space_read_2(src));
+ src++;
+ dst++;
}
}
}
@@ -646,23 +810,21 @@ static __inline void
bus_space_copy_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
{
- bus_addr_t dst = bsh1 + ofs1;
- bus_addr_t src = bsh2 + ofs2;
- uint32_t __volatile *dstp = (uint32_t __volatile *) dst;
- uint32_t __volatile *srcp = (uint32_t __volatile *) src;
+ uint32_t __volatile *dst = (uint32_t __volatile *)(bsh1 + ofs1);
+ uint32_t __volatile *src = (uint32_t __volatile *)(bsh2 + ofs2);;
if (dst > src) {
- src += (count - 1) << 2;
- dst += (count - 1) << 2;
+ src += count - 1;
+ dst += count - 1;
while (count-- > 0) {
- *dstp = *srcp;
- src -= 4;
- dst -= 4;
+ bsp_bus_space_write_4(dst, bsp_bus_space_read_4(src));
+ src--;
+ dst--;
}
} else {
while (count-- > 0) {
- *dstp = *srcp;
- src += 4;
- dst += 4;
+ bsp_bus_space_write_4(dst, bsp_bus_space_read_4(src));
+ src++;
+ dst++;
}
}
}
@@ -671,23 +833,21 @@ static __inline void
bus_space_copy_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
{
- bus_addr_t dst = bsh1 + ofs1;
- bus_addr_t src = bsh2 + ofs2;
- uint64_t __volatile *dstp = (uint64_t __volatile *) dst;
- uint64_t __volatile *srcp = (uint64_t __volatile *) src;
+ uint64_t __volatile *dst = (uint64_t __volatile *)(bsh1 + ofs1);
+ uint64_t __volatile *src = (uint64_t __volatile *)(bsh2 + ofs2);;
if (dst > src) {
- src += (count - 1) << 3;
- dst += (count - 1) << 3;
+ src += count - 1;
+ dst += count - 1;
while (count-- > 0) {
- *dstp = *srcp;
- src -= 8;
- dst -= 8;
+ bsp_bus_space_write_8(dst, bsp_bus_space_read_8(src));
+ src--;
+ dst--;
}
} else {
while (count-- > 0) {
- *dstp = *srcp;
- src += 8;
- dst += 8;
+ bsp_bus_space_write_8(dst, bsp_bus_space_read_8(src));
+ src++;
+ dst++;
}
}
}
diff --git a/rtemsbsd/rtems/rtems-kernel-bus-dma.c b/rtemsbsd/rtems/rtems-kernel-bus-dma.c
index 977ba1c6..45c4287d 100644
--- a/rtemsbsd/rtems/rtems-kernel-bus-dma.c
+++ b/rtemsbsd/rtems/rtems-kernel-bus-dma.c
@@ -251,7 +251,6 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
if (*vaddr == NULL) {
free(*mapp, M_DEVBUF);
-
return ENOMEM;
}
@@ -292,6 +291,10 @@ bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dma_segment_t segs[],
vm_offset_t vaddr = (vm_offset_t)buf;
int seg;
+#ifdef RTEMS_BSP_PCI_MEM_REGION_BASE
+ vaddr += RTEMS_BSP_PCI_MEM_REGION_BASE;
+#endif
+
lastaddr = *lastaddrp;
bmask = ~(dmat->boundary - 1);
diff --git a/rtemsbsd/rtems/rtems-kernel-nexus.c b/rtemsbsd/rtems/rtems-kernel-nexus.c
index bf840a17..8fc879fe 100644
--- a/rtemsbsd/rtems/rtems-kernel-nexus.c
+++ b/rtemsbsd/rtems/rtems-kernel-nexus.c
@@ -59,9 +59,35 @@
#include <rtems/bsd/bsd.h>
#include <rtems/irq-extension.h>
+#include <bsp.h>
+
+/*
+ * BSP PCI Support
+ *
+ * The RTEMS Nexus bus support can optionaly support PCI spaces that
+ * map to BSP speciic address spaces. The BSP needs to provide the
+ * following:
+ *
+ * RTEMS_BSP_PCI_IO_REGION_BASE
+ * The base address of the IO port region of the address space
+ *
+ * RTEMS_BSP_PCI_MEM_REGION_BASE
+ * The base address of the memory region of the address space
+ *
+ * i386 (x86) BSPs have a special bus.h file and do not use these settings.
+ */
+
/* #define DISABLE_INTERRUPT_EXTENSION */
-#if defined(__i386__) || defined(FDT)
+#if defined(__i386__)
+#define RTEMS_BSP_PCI_IO_REGION_BASE 0
+#endif
+
+#if !defined(RTEMS_BSP_PCI_MEM_REGION_BASE)
+#define RTEMS_BSP_PCI_MEM_REGION_BASE 0
+#endif
+
+#if defined(RTEMS_BSP_PCI_IO_REGION_BASE) || defined(FDT)
#define ENABLE_RESOURCE_ACTIVATE_DEACTIVATE
#endif
@@ -77,7 +103,7 @@ static struct rman mem_rman;
static struct rman irq_rman;
-#ifdef __i386__
+#if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
static struct rman port_rman;
#endif
@@ -111,9 +137,9 @@ nexus_probe(device_t dev)
err = rman_manage_region(&irq_rman, irq_rman.rm_start, irq_rman.rm_end);
BSD_ASSERT(err == 0);
-#ifdef __i386__
+#if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
port_rman.rm_start = 0;
- port_rman.rm_end = 0xffff;
+ port_rman.rm_end = ~0UL;
port_rman.rm_type = RMAN_ARRAY;
port_rman.rm_descr = "I/O ports";
err = rman_init(&port_rman) != 0;
@@ -156,6 +182,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
struct resource *res = NULL;
struct rman *rm;
const rtems_bsd_device *nd;
+ rman_res_t base = RTEMS_BSP_PCI_MEM_REGION_BASE;
switch (type) {
case SYS_RES_MEMORY:
@@ -164,9 +191,10 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
case SYS_RES_IRQ:
rm = &irq_rman;
break;
-#ifdef __i386__
+#if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
case SYS_RES_IOPORT:
rm = &port_rman;
+ base = RTEMS_BSP_PCI_IO_REGION_BASE;
break;
#endif
default:
@@ -185,7 +213,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
if (res != NULL) {
rman_set_rid(res, *rid);
rman_set_bushandle(res,
- rman_get_start(res));
+ rman_get_start(res) + base);
}
};
@@ -193,7 +221,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
}
}
-#ifdef __i386__
+#if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
/*
* FIXME: This is a quick and dirty hack. Simply reserve resources of
* this kind. See also pci_reserve_map().
@@ -225,16 +253,22 @@ nexus_activate_resource(device_t bus, device_t child, int type, int rid,
{
switch (type) {
-#ifdef __i386__
+#if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
case SYS_RES_IOPORT:
+#ifdef __i386__
rman_set_bustag(res, X86_BUS_SPACE_IO);
+#else
+ rman_set_bushandle(res,
+ rman_get_start(res) + RTEMS_BSP_PCI_IO_REGION_BASE);
+#endif
break;
#endif
case SYS_RES_MEMORY:
#ifdef __i386__
rman_set_bustag(res, X86_BUS_SPACE_MEM);
#else
- rman_set_bushandle(res, rman_get_start(res));
+ rman_set_bushandle(res,
+ rman_get_start(res) + RTEMS_BSP_PCI_MEM_REGION_BASE);
#endif
break;
}
--
2.24.1
More information about the devel
mailing list