diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2006-04-16 21:03:46 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2006-04-16 21:03:46 +0000 |
commit | 5eaea4c893599bf5f55886960e35fad167db1145 (patch) | |
tree | 45f145e462f9caa87c2e92a5cbce0376738b58a9 | |
parent | 557fd68d34fa0134badbde0239bfeccc70301a61 (diff) |
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@
-rw-r--r-- | sys/arch/hp300/dev/sti_sgc.c | 22 | ||||
-rw-r--r-- | sys/arch/hppa/dev/sti_sgc.c | 13 | ||||
-rw-r--r-- | sys/dev/ic/sti.c | 37 | ||||
-rw-r--r-- | sys/dev/ic/stivar.h | 3 |
4 files changed, 34 insertions, 41 deletions
diff --git a/sys/arch/hp300/dev/sti_sgc.c b/sys/arch/hp300/dev/sti_sgc.c index 06302a79196..7805549f2c6 100644 --- a/sys/arch/hp300/dev/sti_sgc.c +++ b/sys/arch/hp300/dev/sti_sgc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sti_sgc.c,v 1.6 2005/12/31 18:13:41 miod Exp $ */ +/* $OpenBSD: sti_sgc.c,v 1.7 2006/04/16 21:03:43 miod Exp $ */ /* * Copyright (c) 2005, Miodrag Vallat @@ -79,8 +79,7 @@ sti_sgc_attach(struct device *parent, struct device *self, void *aux) struct sgc_attach_args *saa = aux; bus_space_tag_t iot; bus_space_handle_t ioh; - int devtype; - u_int32_t romend; + u_int romend; /* * If we already probed it succesfully as a console device, go ahead, @@ -105,21 +104,11 @@ sti_sgc_attach(struct device *parent, struct device *self, void *aux) /* * 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); - if (bus_space_map(iot, sc->base, round_page(romend), 0, - &ioh)) { + if (bus_space_map(iot, sc->base, romend, 0, &ioh)) { printf(": can't map frame buffer"); return; } @@ -127,7 +116,8 @@ sti_sgc_attach(struct device *parent, struct device *self, void *aux) sc->memt = sc->iot = iot; sc->romh = ioh; - sti_attach_common(sc, STI_CODEBASE_M68K); + if (sti_attach_common(sc, STI_CODEBASE_M68K) != 0) + return; } sti_end_attach(sc); diff --git a/sys/arch/hppa/dev/sti_sgc.c b/sys/arch/hppa/dev/sti_sgc.c index 8b8bbd5abd9..67ea930de98 100644 --- a/sys/arch/hppa/dev/sti_sgc.c +++ b/sys/arch/hppa/dev/sti_sgc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sti_sgc.c,v 1.31 2006/04/01 22:50:29 miod Exp $ */ +/* $OpenBSD: sti_sgc.c,v 1.32 2006/04/16 21:03:45 miod Exp $ */ /* * Copyright (c) 2000-2003 Michael Shalayeff @@ -116,7 +116,7 @@ sti_sgc_probe(parent, match, aux) struct confargs *ca = aux; bus_space_handle_t romh; paddr_t rom; - u_int32_t id, romend; + u_int32_t id; u_char devtype; int rv = 0, romunmapped = 0; @@ -160,25 +160,18 @@ sti_sgc_probe(parent, match, aux) switch (devtype) { case STI_DEVTYPE4: id = bus_space_read_4(ca->ca_iot, romh, 0x8); - romend = bus_space_read_4(ca->ca_iot, romh, 0x18); break; case STI_DEVTYPE1: id = (bus_space_read_1(ca->ca_iot, romh, 0x10 + 3) << 24) | (bus_space_read_1(ca->ca_iot, romh, 0x10 + 7) << 16) | (bus_space_read_1(ca->ca_iot, romh, 0x10 + 11) << 8) | (bus_space_read_1(ca->ca_iot, romh, 0x10 + 15)); - romend = - (bus_space_read_1(ca->ca_iot, romh, 0x50 + 3) << 24) | - (bus_space_read_1(ca->ca_iot, romh, 0x50 + 7) << 16) | - (bus_space_read_1(ca->ca_iot, romh, 0x50 + 11) << 8) | - (bus_space_read_1(ca->ca_iot, romh, 0x50 + 15)); break; default: #ifdef STIDEBUG printf("sti: unknown type (%x)\n", devtype); #endif rv = 0; - romend = 0; } if (rv && @@ -195,7 +188,7 @@ sti_sgc_probe(parent, match, aux) } ca->ca_addrs[ca->ca_naddrs].addr = rom; - ca->ca_addrs[ca->ca_naddrs].size = round_page(romend); + ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh); ca->ca_naddrs++; if (!romunmapped) 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_ */ |