diff options
author | Christopher Pascoe <pascoe@cvs.openbsd.org> | 2007-03-04 12:20:18 +0000 |
---|---|---|
committer | Christopher Pascoe <pascoe@cvs.openbsd.org> | 2007-03-04 12:20:18 +0000 |
commit | 8a3b9c6c99efe8d4eaa569dcf5f245607732f5d4 (patch) | |
tree | 4ee1cfe849e5a96f89d24ef1964deb48f7b02aa7 /sys/dev | |
parent | 25a690cf834273e5fc802686267d49c6a06ea9f9 (diff) |
Add functions to wait for bit changes in port registers.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/pci/ahci.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/sys/dev/pci/ahci.c b/sys/dev/pci/ahci.c index abf3f532a1f..926c2e044be 100644 --- a/sys/dev/pci/ahci.c +++ b/sys/dev/pci/ahci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ahci.c,v 1.51 2007/03/04 12:01:46 pascoe Exp $ */ +/* $OpenBSD: ahci.c,v 1.52 2007/03/04 12:20:17 pascoe Exp $ */ /* * Copyright (c) 2006 David Gwynne <dlg@openbsd.org> @@ -387,13 +387,26 @@ void ahci_dmamem_free(struct ahci_softc *, u_int32_t ahci_read(struct ahci_softc *, bus_size_t); void ahci_write(struct ahci_softc *, bus_size_t, u_int32_t); -u_int32_t ahci_pread(struct ahci_port *, bus_size_t); -void ahci_pwrite(struct ahci_port *, bus_size_t, u_int32_t); int ahci_wait_eq(struct ahci_softc *, bus_size_t, u_int32_t, u_int32_t); int ahci_wait_ne(struct ahci_softc *, bus_size_t, u_int32_t, u_int32_t); +u_int32_t ahci_pread(struct ahci_port *, bus_size_t); +void ahci_pwrite(struct ahci_port *, bus_size_t, u_int32_t); +u_int32_t ahci_pread(struct ahci_port *, bus_size_t); +void ahci_pwrite(struct ahci_port *, bus_size_t, u_int32_t); +int ahci_pwait_eq(struct ahci_port *, bus_size_t, + u_int32_t, u_int32_t); +int ahci_pwait_ne(struct ahci_port *, bus_size_t, + u_int32_t, u_int32_t); + +/* Wait for all bits in _b to be cleared */ +#define ahci_pwait_clr(_ap, _r, _b) ahci_pwait_eq((_ap), (_r), (_b), 0) + +/* Wait for all bits in _b to be set */ +#define ahci_pwait_set(_ap, _r, _b) ahci_pwait_eq((_ap), (_r), (_b), (_b)) + /* provide methods for atascsi to call */ int ahci_ata_probe(void *, int); int ahci_ata_cmd(void *, struct ata_xfer *); @@ -836,6 +849,36 @@ ahci_write(struct ahci_softc *sc, bus_size_t r, u_int32_t v) BUS_SPACE_BARRIER_WRITE); } +int +ahci_wait_eq(struct ahci_softc *sc, bus_size_t r, u_int32_t mask, + u_int32_t target) +{ + int i; + + for (i = 0; i < 1000; i++) { + if ((ahci_read(sc, r) & mask) == target) + return (0); + delay(1000); + } + + return (1); +} + +int +ahci_wait_ne(struct ahci_softc *sc, bus_size_t r, u_int32_t mask, + u_int32_t target) +{ + int i; + + for (i = 0; i < 1000; i++) { + if ((ahci_read(sc, r) & mask) != target) + return (0); + delay(1000); + } + + return (1); +} + u_int32_t ahci_pread(struct ahci_port *ap, bus_size_t r) { @@ -853,13 +896,13 @@ ahci_pwrite(struct ahci_port *ap, bus_size_t r, u_int32_t v) } int -ahci_wait_eq(struct ahci_softc *sc, bus_size_t r, u_int32_t mask, +ahci_pwait_eq(struct ahci_port *ap, bus_size_t r, u_int32_t mask, u_int32_t target) { int i; for (i = 0; i < 1000; i++) { - if ((ahci_read(sc, r) & mask) == target) + if ((ahci_pread(ap, r) & mask) == target) return (0); delay(1000); } @@ -868,13 +911,13 @@ ahci_wait_eq(struct ahci_softc *sc, bus_size_t r, u_int32_t mask, } int -ahci_wait_ne(struct ahci_softc *sc, bus_size_t r, u_int32_t mask, +ahci_pwait_ne(struct ahci_port *ap, bus_size_t r, u_int32_t mask, u_int32_t target) { int i; for (i = 0; i < 1000; i++) { - if ((ahci_read(sc, r) & mask) != target) + if ((ahci_pread(ap, r) & mask) != target) return (0); delay(1000); } |