From owner-freebsd-new-bus Tue Oct 3 1:34: 4 2000 Delivered-To: freebsd-new-bus@freebsd.org Received: from mail.rdc1.va.home.com (ha1.rdc1.va.home.com [24.2.32.66]) by hub.freebsd.org (Postfix) with ESMTP id 8C26637B502; Tue, 3 Oct 2000 01:34:00 -0700 (PDT) Received: from laptop.baldwin.cx ([24.6.244.187]) by mail.rdc1.va.home.com (InterMail vM.4.01.03.00 201-229-121) with ESMTP id <20001003083358.NKOO26082.mail.rdc1.va.home.com@laptop.baldwin.cx>; Tue, 3 Oct 2000 01:33:58 -0700 Content-Length: 3917 Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Tue, 03 Oct 2000 01:34:02 -0700 (PDT) From: John Baldwin To: new-bus@FreeBSD.org Subject: Generic memory barrier helper functions Cc: msmith@FreeBSD.org Sender: owner-freebsd-new-bus@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG After talking with Mike, I whipped up some quick and dirty helper functions for a MI memory barrier API. Basically, you have the following four functions: barrier_acquire() - a read barrier barrier_release() - a write barrier barrier_fence() - a read/write barrier barrier_flush() - a barrier that flushes the CPU's cache I have a simple patch to implement all of these on both x86 and alpha with the exception of barrier_flush() on the alpha at http://www.FreeBSD.org/~jhb/patches/barrier.patch and inlined here: Index: alpha/include/bus.h =================================================================== RCS file: /usr/cvs/src/sys/alpha/include/bus.h,v retrieving revision 1.6 diff -u -r1.6 bus.h --- alpha/include/bus.h 2000/08/28 21:48:01 1.6 +++ alpha/include/bus.h 2000/10/03 06:26:09 @@ -364,6 +364,21 @@ #define bus_space_barrier(t, h, o, l, f) \ (t)->ab_ops->abo_barrier(t, (h)+(o), l, f) +#define barrier_acquire \ + bus_space_barrier(busspace_isa_mem, 0, BUS_SPACE_UNRESTRICTED, \ + BUS_SPACE_BARRIER_READ) + +#define barrier_release \ + bus_space_barrier(busspace_isa_mem, 0, BUS_SPACE_UNRESTRICTED, \ + BUS_SPACE_BARRIER_WRITE) + +#define barrier_fence \ + bus_space_barrier(busspace_isa_mem, 0, BUS_SPACE_UNRESTRICTED, \ + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE) + +#define barrier_flush \ + :w + /* * Flags used in various bus DMA methods. */ Index: i386/include/bus_at386.h =================================================================== RCS file: /usr/cvs/src/sys/i386/include/bus_at386.h,v retrieving revision 1.10 diff -u -r1.10 bus_at386.h --- i386/include/bus_at386.h 2000/06/14 18:48:39 1.10 +++ i386/include/bus_at386.h 2000/10/03 07:04:55 @@ -1154,6 +1154,35 @@ /* + * Generic memory barrier functions. + */ +static __inline void +barrier_acquire(void) +{ + bus_space_barrier(I386_BUS_SPACE_MEM, 0, 0, ~0, BUS_SPACE_BARRIER_READ); +} + +static __inline void +barrier_release(void) +{ + bus_space_barrier(I386_BUS_SPACE_MEM, 0, 0, ~0, + BUS_SPACE_BARRIER_WRITE); +} + +static __inline void +barrier_fence(void) +{ + bus_space_barrier(I386_BUS_SPACE_MEM, 0, 0, ~0, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); +} + +static __inline void +barrier_flush(void) +{ + __asm __volatile("wbinvd" : : : "memory"); +} + +/* * Flags used in various bus DMA methods. */ #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ Index: i386/include/bus_pc98.h =================================================================== RCS file: /usr/cvs/src/sys/i386/include/bus_pc98.h,v retrieving revision 1.11 diff -u -r1.11 bus_pc98.h --- i386/include/bus_pc98.h 2000/06/14 18:48:39 1.11 +++ i386/include/bus_pc98.h 2000/10/03 07:05:04 @@ -1456,6 +1456,35 @@ /* + * Generic memory barrier functions. + */ +static __inline void +barrier_acquire(void) +{ + bus_space_barrier(I386_BUS_SPACE_MEM, 0, 0, ~0, BUS_SPACE_BARRIER_READ); +} + +static __inline void +barrier_release(void) +{ + bus_space_barrier(I386_BUS_SPACE_MEM, 0, 0, ~0, + BUS_SPACE_BARRIER_WRITE); +} + +static __inline void +barrier_fence(void) +{ + bus_space_barrier(I386_BUS_SPACE_MEM, 0, 0, ~0, + BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); +} + +static __inline void +barrier_flush(void) +{ + __asm __volatile("wbinvd" : : : "memory"); +} + +/* * Flags used in various bus DMA methods. */ #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ In my mind at least, I associate bus_space with new-bus, hence my posting to this list. Comments, questions? -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-new-bus" in the body of the message