Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/mvme68k/include Replace the inline C versions of bu...



details:   https://anonhg.NetBSD.org/src/rev/8dafd7eb2059
branches:  trunk
changeset: 499590:8dafd7eb2059
user:      scw <scw%NetBSD.org@localhost>
date:      Fri Nov 24 09:05:55 2000 +0000

description:
Replace the inline C versions of bus_space_{read,write}_N() with
inline assembler. This generates significantly more efficient code,
and trims ~1KB off the size of an mvme68k GENERIC kernel...

diffstat:

 sys/arch/mvme68k/include/bus_space.h |  234 ++++++++++++++++++++++++++--------
 1 files changed, 178 insertions(+), 56 deletions(-)

diffs (truncated from 362 to 300 lines):

diff -r 2be91cab9447 -r 8dafd7eb2059 sys/arch/mvme68k/include/bus_space.h
--- a/sys/arch/mvme68k/include/bus_space.h      Fri Nov 24 08:54:08 2000 +0000
+++ b/sys/arch/mvme68k/include/bus_space.h      Fri Nov 24 09:05:55 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_space.h,v 1.5 2000/03/18 22:33:05 scw Exp $ */
+/*     $NetBSD: bus_space.h,v 1.6 2000/11/24 09:05:55 scw Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -73,6 +73,7 @@
 
 #ifndef _MVME68K_BUS_SPACE_H_
 #define        _MVME68K_BUS_SPACE_H_
+
 /*
  * Addresses (in bus space).
  */
@@ -82,23 +83,46 @@
 /*
  * Access methods for bus resources and address space.
  */
-typedef int    bus_space_tag_t;
+struct mvme68k_bus_space_tag;
+typedef struct mvme68k_bus_space_tag   *bus_space_tag_t;
 typedef u_long bus_space_handle_t;
 
+struct mvme68k_bus_space_tag {
+       void            *bs_cookie;
+       int             (*bs_map)(void *, bus_addr_t, bus_size_t,
+                                 int, bus_space_handle_t *);
+       void            (*bs_unmap)(void *, bus_space_handle_t, bus_size_t);
+       int             (*bs_peek_1)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int8_t *);
+       int             (*bs_peek_2)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int16_t *);
+       int             (*bs_peek_4)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int32_t *);
+#if 0
+       int             (*bs_peek_8)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int64_t *);
+#endif
+       int             (*bs_poke_1)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int8_t);
+       int             (*bs_poke_2)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int16_t);
+       int             (*bs_poke_4)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int32_t);
+#if 0
+       int             (*bs_poke_8)(void *, bus_space_handle_t,
+                                    bus_size_t, u_int64_t);
+#endif
+};
+
 /*
- * Value for the mvme68k bus space tag, not to be used directly by MI code.
- */
-#define MVME68K_INTIO_BUS_SPACE        0
-#define MVME68K_VME_BUS_SPACE  1
-
-/*
- *     int bus_space_map __P((bus_space_tag_t t, bus_addr_t addr,
- *         bus_size_t size, int flags, bus_space_handle_t *bshp));
+ *     int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
+ *                       bus_size_t size, int flags,
+ *                        bus_space_handle_t *bshp);
  *
  * Map a region of bus space.
  */
-int    bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
-           int, bus_space_handle_t *));
+#define        bus_space_map(tag, offset, size, flags, handlep)                \
+    (*((tag)->bs_map))((tag)->bs_cookie, (offset), (size), (flags), (handlep))
 
 /*
  * Possible values for the 'flags' parameter of bus_space_map()
@@ -108,15 +132,22 @@
 #define        BUS_SPACE_MAP_PREFETCHABLE      0x04
 
 /*
- *     void bus_space_unmap __P((bus_space_tag_t t,
- *         bus_space_handle_t bsh, bus_size_t size));
+ *     void bus_space_unmap(bus_space_tag_t t,
+ *                           bus_space_handle_t bsh, bus_size_t size);
  *
  * Unmap a region of bus space.
  */
-void   bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t, bus_size_t));
+#define bus_space_unmap(tag, handle, size)                             \
+    (*((tag)->bs_unmap))((tag)->bs_cookie, (handle), (size))
 
+/*
+ *     int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t h
+ *         bus_addr_t offset, bus_size_t size, bus_space_handle_t *newh);
+ *
+ * Allocate a sub-region of an existing map
+ */
 #define        bus_space_subregion(t, h, o, s, hp)                             \
-     (*(hp)=(h)+(o))
+     ((*(hp)=(h)+(o)), 0)
 
 /*
  * Allocation and deallocation operations.
@@ -127,30 +158,95 @@
 #define        bus_space_free(t, h, s)
 
 /*
- *     u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
- *         bus_space_handle_t bsh, bus_size_t offset));
+ *     int bus_space_peek_N(bus_space_tag_t tag,
+ *         bus_space_handle_t bsh, bus_size_t offset, u_intN_t *valuep);
+ *
+ * Cautiously read 1, 2, 4 or 8 byte quantity from bus space described
+ * by tag/handle/offset.
+ * If no hardware responds to the read access, the function returns a
+ * non-zero value. Otherwise the value read is placed in `valuep'.
+ */
+#define        bus_space_peek_1(t, h, o, vp)                                   \
+    (*((t)->bs_peek_1))((t)->bs_cookie, (h), (o), (vp))
+
+#define        bus_space_peek_2(t, h, o, vp)                                   \
+    (*((t)->bs_peek_2))((t)->bs_cookie, (h), (o), (vp))
+
+#define        bus_space_peek_4(t, h, o, vp)                                   \
+    (*((t)->bs_peek_4))((t)->bs_cookie, (h), (o), (vp))
+
+#if 0  /* Cause a link error for bus_space_peek_8 */
+#define        bus_space_peek_8(t, h, o, vp)                                   \
+    (*((t)->bs_peek_8))((t)->bs_cookie, (h), (o), (vp))
+#endif
+
+/*
+ *     int bus_space_poke_N(bus_space_tag_t tag,
+ *         bus_space_handle_t bsh, bus_size_t offset, u_intN_t value);
+ *
+ * Cautiously write 1, 2, 4 or 8 byte quantity to bus space described
+ * by tag/handle/offset.
+ * If no hardware responds to the write access, the function returns a
+ * non-zero value.
+ */
+#define        bus_space_poke_1(t, h, o, v)                                    \
+    (*((t)->bs_poke_1))((t)->bs_cookie, (h), (o), (v))
+
+#define        bus_space_poke_2(t, h, o, v)                                    \
+    (*((t)->bs_poke_2))((t)->bs_cookie, (h), (o), (v))
+
+#define        bus_space_poke_4(t, h, o, v)                                    \
+    (*((t)->bs_poke_4))((t)->bs_cookie, (h), (o), (v))
+
+#if 0  /* Cause a link error for bus_space_poke_8 */
+#define        bus_space_poke_8(t, h, o, v)                                    \
+    (*((t)->bs_poke_8))((t)->bs_cookie, (h), (o), (v))
+#endif
+
+/*
+ *     u_intN_t bus_space_read_N(bus_space_tag_t tag,
+ *         bus_space_handle_t bsh, bus_size_t offset);
  *
  * Read a 1, 2, 4, or 8 byte quantity from bus space
  * described by tag/handle/offset.
  */
+static __inline u_int8_t
+bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+       u_int8_t rv;
 
-#define        bus_space_read_1(t, h, o)                                       \
-    ((void) t, (*(volatile u_int8_t *)((h) + (o))))
+       __asm __volatile("movb %1,%0" : "=dm" (rv) :
+                                       "g"   (*((u_int8_t *)(h + o))));
 
-#define        bus_space_read_2(t, h, o)                                       \
-    ((void) t, (*(volatile u_int16_t *)((h) + (o))))
+       return (rv);
+}
+
+static __inline u_int16_t
+bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+       u_int16_t rv;
 
-#define        bus_space_read_4(t, h, o)                                       \
-    ((void) t, (*(volatile u_int32_t *)((h) + (o))))
+       __asm __volatile("movw %1,%0" : "=dm" (rv) :
+                                       "g"   (*((u_int16_t *)(h + o))));
+
+       return (rv);
+}
 
-#if 0  /* Cause a link error for bus_space_read_8 */
-#define        bus_space_read_8(t, h, o)       !!! bus_space_read_8 unimplemented !!!
-#endif
+static __inline u_int32_t
+bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+       u_int32_t rv;
+
+       __asm __volatile("movl %1,%0" : "=rm" (rv) :
+                                       "g"   (*((u_int32_t *)(h + o))));
+
+       return (rv);
+}
 
 /*
- *     void bus_space_read_multi_N __P((bus_space_tag_t tag,
+ *     void bus_space_read_multi_N(bus_space_tag_t tag,
  *         bus_space_handle_t bsh, bus_size_t offset,
- *         u_intN_t *addr, size_t count));
+ *         u_intN_t *addr, size_t count);
  *
  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
  * described by tag/handle/offset and copy into buffer provided.
@@ -203,9 +299,9 @@
 #endif
 
 /*
- *     void bus_space_read_region_N __P((bus_space_tag_t tag,
+ *     void bus_space_read_region_N(bus_space_tag_t tag,
  *         bus_space_handle_t bsh, bus_size_t offset,
- *         u_intN_t *addr, size_t count));
+ *         u_intN_t *addr, size_t count);
  *
  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
  * described by tag/handle and starting at `offset' and copy into
@@ -259,31 +355,41 @@
 #endif
 
 /*
- *     void bus_space_write_N __P((bus_space_tag_t tag,
+ *     void bus_space_write_N(bus_space_tag_t tag,
  *         bus_space_handle_t bsh, bus_size_t offset,
- *         u_intN_t value));
+ *         u_intN_t value);
  *
  * Write the 1, 2, 4, or 8 byte value `value' to bus space
  * described by tag/handle/offset.
  */
-
-#define        bus_space_write_1(t, h, o, v)                                   \
-    ((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
-
-#define        bus_space_write_2(t, h, o, v)                                   \
-    ((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
+static __inline void
+bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h,
+    bus_size_t o, u_int8_t v)
+{
+       __asm __volatile("movb %0,%1" ::
+           "dim" (v), "g" (*((u_int8_t *)(h + o))));
+}
 
-#define        bus_space_write_4(t, h, o, v)                                   \
-    ((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
+static __inline void
+bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h,
+    bus_size_t o, u_int16_t v)
+{
+       __asm __volatile("movw %0,%1" ::
+           "dim" (v), "g" (*((u_int16_t *)(h + o))));
+}
 
-#if 0  /* Cause a link error for bus_space_write_8 */
-#define        bus_space_write_8       !!! bus_space_write_8 not implemented !!!
-#endif
+static __inline void
+bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h,
+    bus_size_t o, u_int32_t v)
+{
+       __asm __volatile("movl %0,%1" ::
+           "g" (v), "g" (*((u_int32_t *)(h + o))));
+}
 
 /*
- *     void bus_space_write_multi_N __P((bus_space_tag_t tag,
+ *     void bus_space_write_multi_N(bus_space_tag_t tag,
  *         bus_space_handle_t bsh, bus_size_t offset,
- *         const u_intN_t *addr, size_t count));
+ *         const u_intN_t *addr, size_t count);
  *
  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
  * provided to bus space described by tag/handle/offset.
@@ -337,9 +443,9 @@
 #endif
 
 /*
- *     void bus_space_write_region_N __P((bus_space_tag_t tag,
+ *     void bus_space_write_region_N(bus_space_tag_t tag,
  *         bus_space_handle_t bsh, bus_size_t offset,
- *         const u_intN_t *addr, size_t count));
+ *         const u_intN_t *addr, size_t count);
  *
  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
  * to bus space described by tag/handle starting at `offset'.
@@ -393,9 +499,9 @@
 #endif
 
 /*
- *     void bus_space_set_multi_N __P((bus_space_tag_t tag,
+ *     void bus_space_set_multi_N(bus_space_tag_t tag,
  *         bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
- *         size_t count));



Home | Main Index | Thread Index | Old Index