From 8c967acc0e8a0433a9436bf0460349f3d37aa74a Mon Sep 17 00:00:00 2001 From: Alexander Yurchenko Date: Fri, 29 Sep 2006 19:38:53 +0000 Subject: Extend bus master interface so that block read/write operations can be offloaded to hardware. --- sys/dev/onewire/onewire.c | 48 ++++++++++++++++++++++++++------------------ sys/dev/onewire/onewirevar.h | 6 ++++-- 2 files changed, 33 insertions(+), 21 deletions(-) (limited to 'sys') diff --git a/sys/dev/onewire/onewire.c b/sys/dev/onewire/onewire.c index 9860dfb1301..0873c4b97d9 100644 --- a/sys/dev/onewire/onewire.c +++ b/sys/dev/onewire/onewire.c @@ -1,4 +1,4 @@ -/* $OpenBSD: onewire.c,v 1.2 2006/08/03 18:48:13 grange Exp $ */ +/* $OpenBSD: onewire.c,v 1.3 2006/09/29 19:38:52 grange Exp $ */ /* * Copyright (c) 2006 Alexander Yurchenko @@ -240,6 +240,34 @@ onewire_write_byte(void *arg, int value) bus->bus_bit(bus->bus_cookie, (value >> i) & 0x1); } +void +onewire_read_block(void *arg, void *buf, int len) +{ + struct onewire_softc *sc = arg; + struct onewire_bus *bus = sc->sc_bus; + u_int8_t *p = buf; + + if (bus->bus_read_block != NULL) + return (bus->bus_read_block(bus->bus_cookie, buf, len)); + + while (len--) + *p++ = onewire_read_byte(arg); +} + +void +onewire_write_block(void *arg, const void *buf, int len) +{ + struct onewire_softc *sc = arg; + struct onewire_bus *bus = sc->sc_bus; + const u_int8_t *p = buf; + + if (bus->bus_write_block != NULL) + return (bus->bus_write_block(bus->bus_cookie, buf, len)); + + while (len--) + onewire_write_byte(arg, *p++); +} + int onewire_triplet(void *arg, int dir) { @@ -268,24 +296,6 @@ onewire_triplet(void *arg, int dir) return (rv); } -void -onewire_read_block(void *arg, void *buf, int len) -{ - u_int8_t *p = buf; - - while (len--) - *p++ = onewire_read_byte(arg); -} - -void -onewire_write_block(void *arg, const void *buf, int len) -{ - const u_int8_t *p = buf; - - while (len--) - onewire_write_byte(arg, *p++); -} - void onewire_matchrom(void *arg, u_int64_t rom) { diff --git a/sys/dev/onewire/onewirevar.h b/sys/dev/onewire/onewirevar.h index 51b7ea4a434..9da8c335bff 100644 --- a/sys/dev/onewire/onewirevar.h +++ b/sys/dev/onewire/onewirevar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: onewirevar.h,v 1.1 2006/03/04 16:27:03 grange Exp $ */ +/* $OpenBSD: onewirevar.h,v 1.2 2006/09/29 19:38:52 grange Exp $ */ /* * Copyright (c) 2006 Alexander Yurchenko @@ -31,6 +31,8 @@ struct onewire_bus { int (*bus_bit)(void *, int); int (*bus_read_byte)(void *); void (*bus_write_byte)(void *, int); + void (*bus_read_block)(void *, void *, int); + void (*bus_write_block)(void *, const void *, int); int (*bus_triplet)(void *, int); }; @@ -41,9 +43,9 @@ int onewire_reset(void *); int onewire_bit(void *, int); int onewire_read_byte(void *); void onewire_write_byte(void *, int); -int onewire_triplet(void *, int); void onewire_read_block(void *, void *, int); void onewire_write_block(void *, const void *, int); +int onewire_triplet(void *, int); void onewire_matchrom(void *, u_int64_t); #define ONEWIRE_NOWAIT 0x0001 -- cgit v1.2.3