[libbsd PATCH v2 1/2] rtemsbsd/bus: Add PCI support to the nexus bus

chrisj at rtems.org chrisj at rtems.org
Wed Feb 17 04:21:03 UTC 2021


From: Chris Johns <chrisj at rtems.org>

- Add PCI IO region support

- Add support map buffers to PCI address space

Closes #4245
---
 rtemsbsd/include/machine/bus.h        | 282 ++++++++++++++++----------
 rtemsbsd/rtems/rtems-kernel-bus-dma.c |   5 +-
 rtemsbsd/rtems/rtems-kernel-nexus.c   |  50 ++++-
 3 files changed, 222 insertions(+), 115 deletions(-)

diff --git a/rtemsbsd/include/machine/bus.h b/rtemsbsd/include/machine/bus.h
index 2f0e7ad6..42148ee3 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,7 +127,7 @@
 #endif
 
 #ifdef __i386__
-  #error "your include paths are wrong"
+  #error "x86 has its own bus.h; check your include paths are correct"
 #endif
 
 /*
@@ -144,6 +148,7 @@
 /*
  * Bus access.
  */
+#define BUS_SPACE_INVALID_DATA	(~0)
 #define BUS_SPACE_UNRESTRICTED	(~0U)
 
 /*
@@ -222,6 +227,93 @@ bus_space_barrier(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
 	/* Do nothing */
 }
 
+
+/*
+ * BSP or linear inline memory access.
+ */
+#include <bsp.h>
+
+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
@@ -231,28 +323,28 @@ static __inline uint8_t
 bus_space_read_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
 {
 	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)
 {
 	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)
 {
 	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)
 {
 	uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
-	return (*bsp);
+	return bsp_bus_space_read_8(bsp);
 }
 
 
@@ -266,7 +358,7 @@ bus_space_write_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
     uint8_t val)
 {
 	uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
-	*bsp = val;
+	bsp_bus_space_write_1(bsp, val);
 }
 
 static __inline void
@@ -274,7 +366,7 @@ bus_space_write_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
     uint16_t val)
 {
 	uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
-	*bsp = val;
+	bsp_bus_space_write_2(bsp, val);
 }
 
 static __inline void
@@ -282,7 +374,7 @@ bus_space_write_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
     uint32_t val)
 {
 	uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
-	*bsp = val;
+	bsp_bus_space_write_4(bsp, val);
 }
 
 static __inline void
@@ -290,7 +382,7 @@ bus_space_write_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size
     uint64_t val)
 {
 	uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
-	*bsp = val;
+	bsp_bus_space_write_8(bsp, val);
 }
 
 
@@ -305,7 +397,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 +407,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 +417,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 +427,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 +443,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 +453,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 +463,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 +473,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 +488,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 +498,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 +508,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 +518,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 +535,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 +545,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 +555,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 +565,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 +583,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 +593,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 +603,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 +613,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 +628,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 +638,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 +648,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 +658,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 +676,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 +699,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 +722,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 +745,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..741307c2 100644
--- a/rtemsbsd/rtems/rtems-kernel-nexus.c
+++ b/rtemsbsd/rtems/rtems-kernel-nexus.c
@@ -59,9 +59,33 @@
 #include <rtems/bsd/bsd.h>
 #include <rtems/irq-extension.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 +101,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 +135,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 +180,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 +189,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 +211,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 +219,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 +251,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.27.0



More information about the devel mailing list