Module Name: src
Committed By: jdolecek
Date: Wed Jun 24 19:24:44 UTC 2020
Modified Files:
src/sys/dev/ic: ug.c ugvar.h
src/sys/dev/isa: ug_isa.c
Log Message:
rearrange to avoid allocating softc on stack in ug_isa_match()
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/ic/ug.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/ic/ugvar.h
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/isa/ug_isa.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/ic/ug.c
diff -u src/sys/dev/ic/ug.c:1.13 src/sys/dev/ic/ug.c:1.14
--- src/sys/dev/ic/ug.c:1.13 Sun Jun 3 10:04:40 2018
+++ src/sys/dev/ic/ug.c Wed Jun 24 19:24:44 2020
@@ -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 <[email protected]>
@@ -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 @@ ug2_refresh(struct sysmon_envsys *sme, e
#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 @@ ug2_wait_ready(struct ug_softc *sc)
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 @@ ug2_wait_readable(struct ug_softc *sc)
}
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 @@ ug2_read(struct ug_softc *sc, uint8_t ba
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);
}
Index: src/sys/dev/ic/ugvar.h
diff -u src/sys/dev/ic/ugvar.h:1.5 src/sys/dev/ic/ugvar.h:1.6
--- src/sys/dev/ic/ugvar.h:1.5 Sun Jun 3 10:04:40 2018
+++ src/sys/dev/ic/ugvar.h Wed Jun 24 19:24:44 2020
@@ -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 <[email protected]>
@@ -59,9 +59,7 @@ uint8_t ug_read(struct ug_softc *, unsig
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 */
Index: src/sys/dev/isa/ug_isa.c
diff -u src/sys/dev/isa/ug_isa.c:1.7 src/sys/dev/isa/ug_isa.c:1.8
--- src/sys/dev/isa/ug_isa.c:1.7 Fri Apr 4 09:30:55 2008
+++ src/sys/dev/isa/ug_isa.c Wed Jun 24 19:24:44 2020
@@ -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 <[email protected]>
@@ -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 @@ static int
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_isa_match(device_t parent, cfdata_t m
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 */