Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic cosmetic fixes
details: https://anonhg.NetBSD.org/src/rev/83287021be0c
branches: trunk
changeset: 772978:83287021be0c
user: christos <christos%NetBSD.org@localhost>
date: Sun Jan 22 20:41:25 2012 +0000
description:
cosmetic fixes
diffstat:
sys/dev/ic/tpm.c | 180 ++++++++++++++++++++++++++-------------------------
sys/dev/ic/tpmreg.h | 6 +-
sys/dev/ic/tpmvar.h | 14 ++--
3 files changed, 102 insertions(+), 98 deletions(-)
diffs (truncated from 574 to 300 lines):
diff -r a1d1b8501653 -r 83287021be0c sys/dev/ic/tpm.c
--- a/sys/dev/ic/tpm.c Sun Jan 22 20:38:56 2012 +0000
+++ b/sys/dev/ic/tpm.c Sun Jan 22 20:41:25 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tpm.c,v 1.2 2012/01/22 16:35:39 christos Exp $ */
+/* $NetBSD: tpm.c,v 1.3 2012/01/22 20:41:25 christos Exp $ */
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Jörg Höxer
@@ -18,9 +18,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.2 2012/01/22 16:35:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.3 2012/01/22 20:41:25 christos Exp $");
-/* #define TPM_DEBUG */
+#if 0
+#define TPM_DEBUG
+#define aprint_debug_dev aprint_error_dev
+#endif
#include <sys/param.h>
#include <sys/systm.h>
@@ -93,12 +96,12 @@
#ifdef TPM_DEBUG
char buf[128];
snprintb(buf, sizeof(buf), TPM_CAPBITS, r);
- printf("tpm: caps=%s\n", buf);
+ printf("%s: caps=%s\n", __func__, buf);
#endif
if ((r & TPM_CAPSREQ) != TPM_CAPSREQ ||
!(r & (TPM_INTF_INT_EDGE_RISING | TPM_INTF_INT_LEVEL_LOW))) {
#ifdef TPM_DEBUG
- printf("tpm: caps too low (caps=%s)\n", buf);
+ printf("%s: caps too low (caps=%s)\n", __func__, buf);
#endif
return 0;
}
@@ -162,7 +165,7 @@
#ifdef TPM_DEBUG
char cbuf[128];
snprintb(cbuf, sizeof(cbuf), TPM_CAPBITS, r);
- aprint_debug_dev(sc->sc_dev, " caps=%s ", cbuf);
+ aprint_debug_dev(sc->sc_dev, "%s: caps=%s ", __func__, cbuf);
#endif
if ((r & TPM_CAPSREQ) != TPM_CAPSREQ ||
!(r & (TPM_INTF_INT_EDGE_RISING | TPM_INTF_INT_LEVEL_LOW))) {
@@ -225,8 +228,8 @@
rv = tsleep(sc->sc_init, PRIBIO | PCATCH, "tpm_locality", 1);
if (rv && rv != EWOULDBLOCK) {
#ifdef TPM_DEBUG
- aprint_debug_dev(sc->sc_dev,
- "tpm_request_locality: interrupted %d\n", rv);
+ aprint_debug_dev(sc->sc_dev, "%s: interrupted %d\n",
+ __func__, rv);
#endif
return rv;
}
@@ -236,9 +239,8 @@
(TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) {
#ifdef TPM_DEBUG
char buf[128];
- snprintb(buf, sizeof(buf), TPM_CAPBITS, r);
- aprint_debug_dev(sc->sc_dev,
- "tpm_request_locality: access %s\n", buf);
+ snprintb(buf, sizeof(buf), TPM_ACCESS_BITS, r);
+ aprint_debug_dev(sc->sc_dev, "%s: access %s\n", __func__, buf);
#endif
return EBUSY;
}
@@ -264,7 +266,7 @@
burst |= bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS + 2)
<< 8;
#ifdef TPM_DEBUG
- aprint_debug_dev(sc->sc_dev, "tpm_getburst: read %d\n", burst);
+ aprint_debug_dev(sc->sc_dev, "%s: read %d\n", __func__, burst);
#endif
if (burst)
return burst;
@@ -281,12 +283,7 @@
uint8_t
tpm_status(struct tpm_softc *sc)
{
- uint8_t status;
-
- status = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS) &
- TPM_STS_MASK;
-
- return status;
+ return bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_STS) & TPM_STS_MASK;
}
int
@@ -305,7 +302,7 @@
tpm_suspend(device_t dev, const pmf_qual_t *qual)
{
struct tpm_softc *sc = device_private(dev);
- uint8_t command[] = {
+ static const uint8_t command[] = {
0, 193, /* TPM_TAG_RQU_COMMAND */
0, 0, 0, 10, /* Length in bytes */
0, 0, 0, 156 /* TPM_ORD_SaveStates */
@@ -314,10 +311,10 @@
/*
* Power down: We have to issue the SaveStates command.
*/
- sc->sc_write(sc, &command, sizeof(command));
- sc->sc_read(sc, &command, sizeof(command), NULL, TPM_HDRSIZE);
+ (*sc->sc_write)(sc, &command, sizeof(command));
+ (*sc->sc_read)(sc, &command, sizeof(command), NULL, TPM_HDRSIZE);
#ifdef TPM_DEBUG
- aprint_debug_dev(sc->sc_dev, "tpm_suspend: power down\n");
+ aprint_debug_dev(sc->sc_dev, "%s: power down\n", __func__);
#endif
return 0;
}
@@ -331,7 +328,7 @@
{
#ifdef TPM_DEBUG
struct tpm_softc *sc = device_private(dev);
- aprint_debug_dev(sc->sc_dev, "tpm_resume: resume\n");
+ aprint_debug_dev(sc->sc_dev, "%s: resume\n", __func__);
#endif
return 0;
}
@@ -351,7 +348,7 @@
if (rv && rv != EWOULDBLOCK) {
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_waitfor_poll: interrupted %d\n", rv);
+ "%s: interrupted %d\n", __func__, rv);
#endif
return rv;
}
@@ -397,7 +394,7 @@
to = tpm_tmotohz(tmo);
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_waitfor_int: sleeping for %d ticks on %p\n", to, c);
+ "%s: sleeping for %d ticks on %p\n", __func__, to, c);
#endif
/*
* tsleep(9) enables interrupts on the cpu and returns after
@@ -405,14 +402,14 @@
* generated by the tpm chip while being at SPL_TTY are not lost
* but held and delivered as soon as the cpu goes below SPL_TTY.
*/
- rv = tsleep(c, PRIBIO | PCATCH, "tpm_intr", to);
+ rv = tsleep(c, PRIBIO | PCATCH, "tpm_wait", to);
sc->sc_stat = tpm_status(sc);
#ifdef TPM_DEBUG
char buf[128];
snprintb(buf, sizeof(buf), TPM_STS_BITS, sc->sc_stat);
aprint_debug_dev(sc->sc_dev,
- "tpm_waitfor_int: woke up with rv %d stat %s\n", rv, buf);
+ "%s: woke up with rv %d stat %s\n", __func__, rv, buf);
#endif
if ((sc->sc_stat & mask) == mask)
rv = 0;
@@ -440,7 +437,7 @@
#ifdef TPM_DEBUG
char buf[128];
snprintb(buf, sizeof(buf), TPM_STS_BITS, sc->sc_stat);
- aprint_debug_dev(sc->sc_dev, "tpm_waitfor: b0 %s\n", buf);
+ aprint_debug_dev(sc->sc_dev, "%s: b0 %s\n", __func__, buf);
#endif
/*
@@ -515,7 +512,7 @@
snprintb(bbuf, sizeof(bbuf), TPM_STS_BITS, b);
snprintb(cbuf, sizeof(cbuf), TPM_STS_BITS, sc->sc_stat);
aprint_debug_dev(sc->sc_dev,
- "tpm_waitfor: timeout: stat=%s b=%s\n", cbuf, bbuf);
+ "%s: timeout: stat=%s b=%s\n", __func__, cbuf, bbuf);
#endif
if (re-- && (b0 & TPM_STS_VALID)) {
bus_space_write_1(sc->sc_bt, sc->sc_bh, TPM_STS,
@@ -549,15 +546,15 @@
#ifdef TPM_DEBUG
char buf[128];
snprintb(buf, sizeof(buf), TPM_STS_BITS, sc->sc_stat);
- aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_start: UIO_WRITE status %s\n", buf);
+ aprint_debug_dev(sc->sc_dev, "%s: UIO_WRITE status %s\n",
+ __func__, buf);
#endif
return 0;
}
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_start: UIO_WRITE readying chip\n");
+ "%s: UIO_WRITE readying chip\n", __func__);
#endif
/* Abort previous and restart. */
@@ -566,21 +563,21 @@
sc->sc_write))) {
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_start: UIO_WRITE readying failed %d\n", rv);
+ "%s: UIO_WRITE readying failed %d\n", __func__, rv);
#endif
return rv;
}
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_start: UIO_WRITE readying done\n");
+ "%s: UIO_WRITE readying done\n", __func__);
#endif
return 0;
}
int
-tpm_tis12_read(struct tpm_softc *sc, void *buf, int len, size_t *count,
+tpm_tis12_read(struct tpm_softc *sc, void *buf, size_t len, size_t *count,
int flags)
{
uint8_t *p = buf;
@@ -588,8 +585,7 @@
int rv, n, bcnt;
#ifdef TPM_DEBUG
- aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_read: len %d\n", len);
+ aprint_debug_dev(sc->sc_dev, "%s: len %zu\n", __func__, len);
#endif
cnt = 0;
while (len > 0) {
@@ -601,7 +597,7 @@
n = MIN(len, bcnt);
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_read: fetching %d, burst is %d\n", n, bcnt);
+ "%s: fetching %d, burst is %d\n", __func__, n, bcnt);
#endif
for (; n--; len--) {
*p++ = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_DATA);
@@ -613,7 +609,7 @@
}
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_read: read %zd bytes, len %d\n", cnt, len);
+ "%s: read %zu bytes, len %zu\n", __func__, cnt, len);
#endif
if (count)
@@ -623,16 +619,18 @@
}
int
-tpm_tis12_write(struct tpm_softc *sc, void *buf, int len)
+tpm_tis12_write(struct tpm_softc *sc, const void *buf, size_t len)
{
- uint8_t *p = buf;
+ const uint8_t *p = buf;
size_t cnt;
int rv, r;
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_write: sc %p buf %p len %d\n", sc, buf, len);
+ "%s: sc %p buf %p len %zu\n", __func__, sc, buf, len);
#endif
+ if (len == 0)
+ return 0;
if ((rv = tpm_request_locality(sc, 0)) != 0)
return rv;
@@ -646,7 +644,7 @@
if ((rv = tpm_waitfor(sc, TPM_STS_VALID, TPM_READ_TMO, sc))) {
#ifdef TPM_DEBUG
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_write: failed burst rv %d\n", rv);
+ "%s: failed burst rv %d\n", __func__, rv);
#endif
return rv;
}
@@ -656,8 +654,7 @@
char sbuf[128];
snprintb(sbuf, sizeof(sbuf), TPM_STS_BITS, sc->sc_stat);
aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_write: failed rv %d stat=%s\n", rv,
- sbuf);
+ "%s: failed rv %d stat=%s\n", __func__, rv, sbuf);
#endif
return EIO;
}
@@ -668,8 +665,8 @@
if ((rv = tpm_waitfor(sc, TPM_STS_VALID, TPM_READ_TMO, sc))) {
#ifdef TPM_DEBUG
- aprint_debug_dev(sc->sc_dev,
- "tpm_tis12_write: failed last byte rv %d\n", rv);
+ aprint_debug_dev(sc->sc_dev, "%s: failed last byte rv %d\n",
+ __func__, rv);
Home |
Main Index |
Thread Index |
Old Index