From 5eaea4c893599bf5f55886960e35fad167db1145 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Sun, 16 Apr 2006 21:03:46 +0000 Subject: Introduce sti_rom_size() which will compute the size of a card's rom, and use it instead of duplicating the same logic in 3 places. ok mickey@ --- sys/dev/ic/sti.c | 37 +++++++++++++++++++++++-------------- sys/dev/ic/stivar.h | 3 ++- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/ic/sti.c b/sys/dev/ic/sti.c index 8fbbddccc8f..a6d00a3f0fa 100644 --- a/sys/dev/ic/sti.c +++ b/sys/dev/ic/sti.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sti.c,v 1.42 2005/02/27 22:10:57 miod Exp $ */ +/* $OpenBSD: sti.c,v 1.43 2006/04/16 21:03:45 miod Exp $ */ /* * Copyright (c) 2000-2003 Michael Shalayeff @@ -481,6 +481,26 @@ sti_end_attach(void *v) config_found(&sc->sc_dev, &waa, wsemuldisplaydevprint); } +u_int +sti_rom_size(bus_space_tag_t iot, bus_space_handle_t ioh) +{ + int devtype; + u_int romend; + + devtype = bus_space_read_1(iot, ioh, 3); + if (devtype == STI_DEVTYPE4) { + romend = bus_space_read_4(iot, ioh, 0x18); + } else { + romend = + (bus_space_read_1(iot, ioh, 0x50 + 3) << 24) | + (bus_space_read_1(iot, ioh, 0x50 + 7) << 16) | + (bus_space_read_1(iot, ioh, 0x50 + 11) << 8) | + (bus_space_read_1(iot, ioh, 0x50 + 15)); + } + + return (round_page(romend)); +} + int sti_fetchfonts(struct sti_screen *scr, struct sti_inqconfout *cfg, u_int32_t addr) @@ -1023,8 +1043,7 @@ sti_cnattach(struct sti_screen *scr, bus_space_tag_t iot, bus_addr_t base, u_int codebase) { bus_space_handle_t ioh; - int devtype; - u_int32_t romend; + u_int romend; int error; long defattr; @@ -1034,20 +1053,10 @@ sti_cnattach(struct sti_screen *scr, bus_space_tag_t iot, bus_addr_t base, /* * Compute real PROM size */ - devtype = bus_space_read_1(iot, ioh, 3); - if (devtype == STI_DEVTYPE4) { - romend = bus_space_read_4(iot, ioh, 0x18); - } else { - romend = - (bus_space_read_1(iot, ioh, 0x50 + 3) << 24) | - (bus_space_read_1(iot, ioh, 0x50 + 7) << 16) | - (bus_space_read_1(iot, ioh, 0x50 + 11) << 8) | - (bus_space_read_1(iot, ioh, 0x50 + 15)); - } + romend = sti_rom_size(iot, ioh); bus_space_unmap(iot, ioh, PAGE_SIZE); - romend = round_page(romend); if ((error = bus_space_map(iot, base, romend, 0, &ioh)) != 0) return (error); diff --git a/sys/dev/ic/stivar.h b/sys/dev/ic/stivar.h index 335aab4519e..30fae98c4f6 100644 --- a/sys/dev/ic/stivar.h +++ b/sys/dev/ic/stivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stivar.h,v 1.17 2005/02/27 22:10:58 miod Exp $ */ +/* $OpenBSD: stivar.h,v 1.18 2006/04/16 21:03:45 miod Exp $ */ /* * Copyright (c) 2000-2003 Michael Shalayeff @@ -94,5 +94,6 @@ void sti_attach_common(struct sti_softc *sc, u_int codebase); int sti_cnattach(struct sti_screen *, bus_space_tag_t, bus_addr_t, u_int); void sti_describe(struct sti_softc *); void sti_end_attach(void *); +u_int sti_rom_size(bus_space_tag_t, bus_space_handle_t); #endif /* _IC_STIVAR_H_ */ -- cgit v1.2.3