Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev rearrange to avoid allocating softc on stack in ug_i...
details: https://anonhg.NetBSD.org/src/rev/bdb77e146814
branches: trunk
changeset: 935105:bdb77e146814
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Wed Jun 24 19:24:44 2020 +0000
description:
rearrange to avoid allocating softc on stack in ug_isa_match()
diffstat:
sys/dev/ic/ug.c | 48 +++++++++++++++++++++++++-----------------------
sys/dev/ic/ugvar.h | 6 ++----
sys/dev/isa/ug_isa.c | 11 +++--------
3 files changed, 30 insertions(+), 35 deletions(-)
diffs (181 lines):
diff -r 870e016468da -r bdb77e146814 sys/dev/ic/ug.c
--- a/sys/dev/ic/ug.c Wed Jun 24 19:11:49 2020 +0000
+++ b/sys/dev/ic/ug.c Wed Jun 24 19:24:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ug.c,v 1.13 2018/06/03 10:04:40 maxv Exp $ */
+/* $NetBSD: ug.c,v 1.14 2020/06/24 19:24:44 jdolecek Exp $ */
/*
* Copyright (c) 2007 Mihai Chelaru <kefren%netbsd.ro@localhost>
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ug.c,v 1.13 2018/06/03 10:04:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ug.c,v 1.14 2020/06/24 19:24:44 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -580,13 +580,13 @@
#undef SENSOR_VALUE
}
-int
-ug2_wait_ready(struct ug_softc *sc)
+static int
+ug2_wait_ready(bus_space_tag_t iot, bus_space_handle_t ioh)
{
int cnt = 0;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_DATA, 0x1a);
- while (bus_space_read_1(sc->sc_iot, sc->sc_ioh, UG_DATA) &
+ bus_space_write_1(iot, ioh, UG_DATA, 0x1a);
+ while (bus_space_read_1(iot, ioh, UG_DATA) &
UG2_STATUS_BUSY) {
if (cnt++ > UG_DELAY_CYCLES)
return 0;
@@ -594,12 +594,12 @@
return 1;
}
-int
-ug2_wait_readable(struct ug_softc *sc)
+static int
+ug2_wait_readable(bus_space_tag_t iot, bus_space_handle_t ioh)
{
int cnt = 0;
- while (!(bus_space_read_1(sc->sc_iot, sc->sc_ioh, UG_DATA) &
+ while (!(bus_space_read_1(iot, ioh, UG_DATA) &
UG2_STATUS_READY_FOR_READ)) {
if (cnt++ > UG_DELAY_CYCLES)
return 0;
@@ -608,28 +608,28 @@
}
int
-ug2_sync(struct ug_softc *sc)
+ug2_sync(bus_space_tag_t iot, bus_space_handle_t ioh)
{
int cnt = 0;
-#define UG2_WAIT_READY if(ug2_wait_ready(sc) == 0) return 0;
+#define UG2_WAIT_READY if(ug2_wait_ready(iot, ioh) == 0) return 0;
/* Don't sync two times in a row */
- if(ug_ver != 0) {
+ if (ug_ver != 0) {
ug_ver = 0;
return 1;
}
UG2_WAIT_READY;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_DATA, 0x20);
+ bus_space_write_1(iot, ioh, UG_DATA, 0x20);
UG2_WAIT_READY;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_CMD, 0x10);
+ bus_space_write_1(iot, ioh, UG_CMD, 0x10);
UG2_WAIT_READY;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_CMD, 0x00);
+ bus_space_write_1(iot, ioh, UG_CMD, 0x00);
UG2_WAIT_READY;
- if (ug2_wait_readable(sc) == 0)
+ if (ug2_wait_readable(iot, ioh) == 0)
return 0;
- while (bus_space_read_1(sc->sc_iot, sc->sc_ioh, UG_CMD) != 0xAC)
+ while (bus_space_read_1(iot, ioh, UG_CMD) != 0xAC)
if (cnt++ > UG_DELAY_CYCLES)
return 0;
return 1;
@@ -640,24 +640,26 @@
uint8_t *ret)
{
int i;
+ bus_space_tag_t iot = sc->sc_iot;
+ bus_space_handle_t ioh = sc->sc_ioh;
- if (ug2_sync(sc) == 0)
+ if (ug2_sync(iot, ioh) == 0)
return 0;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_DATA, 0x1A);
+ bus_space_write_1(iot, ioh, UG_DATA, 0x1A);
UG2_WAIT_READY;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_CMD, bank);
+ bus_space_write_1(iot, ioh, UG_CMD, bank);
UG2_WAIT_READY;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_CMD, offset);
+ bus_space_write_1(iot, ioh, UG_CMD, offset);
UG2_WAIT_READY;
- bus_space_write_1(sc->sc_iot, sc->sc_ioh, UG_CMD, count);
+ bus_space_write_1(iot, ioh, UG_CMD, count);
UG2_WAIT_READY;
#undef UG2_WAIT_READY
/* Now wait for the results */
for (i = 0; i < count; i++) {
- if (ug2_wait_readable(sc) == 0)
+ if (ug2_wait_readable(sc->sc_iot, sc->sc_ioh) == 0)
break;
ret[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh, UG_CMD);
}
diff -r 870e016468da -r bdb77e146814 sys/dev/ic/ugvar.h
--- a/sys/dev/ic/ugvar.h Wed Jun 24 19:11:49 2020 +0000
+++ b/sys/dev/ic/ugvar.h Wed Jun 24 19:24:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ugvar.h,v 1.5 2018/06/03 10:04:40 maxv Exp $ */
+/* $NetBSD: ugvar.h,v 1.6 2020/06/24 19:24:44 jdolecek Exp $ */
/*
* Copyright (c) 2007 Mihai Chelaru <kefren%netbsd.ro@localhost>
@@ -59,9 +59,7 @@
int ug_waitfor(struct ug_softc *, uint16_t, uint8_t);
void ug_setup_sensors(struct ug_softc *);
void ug2_attach(device_t);
-int ug2_wait_ready(struct ug_softc *);
-int ug2_wait_readable(struct ug_softc *);
-int ug2_sync(struct ug_softc *);
+int ug2_sync(bus_space_tag_t, bus_space_handle_t);
int ug2_read(struct ug_softc *, uint8_t, uint8_t, uint8_t, uint8_t*);
/* Envsys */
diff -r 870e016468da -r bdb77e146814 sys/dev/isa/ug_isa.c
--- a/sys/dev/isa/ug_isa.c Wed Jun 24 19:11:49 2020 +0000
+++ b/sys/dev/isa/ug_isa.c Wed Jun 24 19:24:44 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ug_isa.c,v 1.7 2008/04/04 09:30:55 xtraeme Exp $ */
+/* $NetBSD: ug_isa.c,v 1.8 2020/06/24 19:24:44 jdolecek Exp $ */
/*
* Copyright (c) 2007 Mihai Chelaru <kefren%netbsd.ro@localhost>
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.7 2008/04/04 09:30:55 xtraeme Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ug_isa.c,v 1.8 2020/06/24 19:24:44 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -70,7 +70,6 @@
ug_isa_match(device_t parent, cfdata_t match, void *aux)
{
struct isa_attach_args *ia = aux;
- struct ug_softc wrap_sc;
bus_space_handle_t bsh;
uint8_t valc, vald;
@@ -97,11 +96,7 @@
ug_ver = 1;
/* Check for uGuru 2005 */
-
- wrap_sc.sc_iot = ia->ia_iot;
- wrap_sc.sc_ioh = bsh;
-
- if (ug2_sync(&wrap_sc) == 1)
+ if (ug2_sync(ia->ia_iot, bsh) == 1)
ug_ver = 2;
/* unmap, prepare ia and bye */
Home |
Main Index |
Thread Index |
Old Index