Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Sprinkle a few bus_space_read*/bus_space_write* ...



details:   https://anonhg.NetBSD.org/src/rev/896f419a1962
branches:  trunk
changeset: 538680:896f419a1962
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Oct 25 18:03:03 2002 +0000

description:
Sprinkle a few bus_space_read*/bus_space_write* calls and simplify register
offset calculation. Mostly from Bang Jun Young.

Don't call wsdisplay_cnattach unconditionally.

On sparc use OF to decide whether we are console output.

This makes it actually work on my U5 - if only we had a keyboard driver
to produce wskbd events (coming soon).

diffstat:

 sys/dev/pci/machfb.c |  68 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 46 insertions(+), 22 deletions(-)

diffs (172 lines):

diff -r 554f84e4f4a0 -r 896f419a1962 sys/dev/pci/machfb.c
--- a/sys/dev/pci/machfb.c      Fri Oct 25 15:58:03 2002 +0000
+++ b/sys/dev/pci/machfb.c      Fri Oct 25 18:03:03 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machfb.c,v 1.2 2002/10/24 20:41:59 martin Exp $        */
+/*     $NetBSD: machfb.c,v 1.3 2002/10/25 18:03:03 martin Exp $        */
 
 /*
  * Copyright (c) 2002 Bang Jun-Young
@@ -40,6 +40,10 @@
 #include <sys/malloc.h>
 #include <sys/callout.h>
 
+#ifdef __sparc__
+#include <machine/openfirm.h>
+#endif
+
 #include <dev/ic/videomode.h>
 
 #include <dev/pci/pcivar.h>
@@ -54,9 +58,14 @@
 #include <dev/rasops/rasops.h>
 
 #define MACH64_REG_SIZE                1024
+#define MACH64_REG_OFF         0x7ffc00
 
 #define        NBARS           3       /* number of Mach64 PCI BARs */
 
+#ifdef __sparc__
+int sparc_screen_is_console(struct pci_attach_args *);
+#endif
+
 struct vga_bar {
        bus_addr_t vb_base;
        bus_size_t vb_size;
@@ -81,13 +90,11 @@
 #define sc_regbase     sc_bars[2].vb_base
 #define sc_regsize     sc_bars[2].vb_size
 
-       bus_space_handle_t sc_regh;
+       bus_space_tag_t sc_memt;
        bus_space_handle_t sc_memh;
 
        u_long aperbase;
        size_t apersize;
-       u_long regbase;
-       size_t regsize;
        size_t memsize;
        int memtype;
 
@@ -229,7 +236,7 @@
 CFATTACH_DECL(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
     NULL, NULL);
 
-void   mach64_init(struct mach64_softc *, bus_space_tag_t);
+void   mach64_init(struct mach64_softc *);
 int    mach64_get_memsize(struct mach64_softc *);
 int    mach64_get_max_ramdac(struct mach64_softc *);
 void   mach64_get_mode(struct mach64_softc *, struct videomode *);
@@ -376,28 +383,28 @@
 regr(struct mach64_softc *sc, u_int32_t index)
 {
 
-       return (*(u_int32_t *)(sc->regbase + index));
+       return bus_space_read_4(sc->sc_memt, sc->sc_memh, MACH64_REG_OFF + index);
 }
 
 static inline u_int8_t
 regrb(struct mach64_softc *sc, u_int32_t index)
 {
        
-       return (*(u_int8_t *)(sc->regbase + index));
+       return bus_space_read_1(sc->sc_memt, sc->sc_memh, MACH64_REG_OFF + index);
 }
 
 static inline void
 regw(struct mach64_softc *sc, u_int32_t index, u_int32_t data)
 {
 
-       *(u_int32_t *)(sc->regbase + index) = data;
+       bus_space_write_4(sc->sc_memt, sc->sc_memh, MACH64_REG_OFF + index, data);
 }
 
 static inline void
 regwb(struct mach64_softc *sc, u_int32_t index, u_int8_t data)
 {
 
-       *(u_int8_t *)(sc->regbase + index) = data;
+       bus_space_write_1(sc->sc_memt, sc->sc_memh, MACH64_REG_OFF + index, data);
 }
 
 static inline void
@@ -471,14 +478,12 @@
                    sc->sc_bars[bar].vb_type, &sc->sc_bars[bar].vb_base,
                    &sc->sc_bars[bar].vb_size, &sc->sc_bars[bar].vb_flags);
        }
-
-       mach64_init(sc, pa->pa_memt);
+       sc->sc_memt = pa->pa_memt;
 
-       sc->aperbase = (vaddr_t)bus_space_vaddr(pa->pa_memt, sc->sc_memh);
-       sc->apersize = sc->sc_apersize;
+       mach64_init(sc);
 
-       sc->regbase = sc->aperbase + 0x7ffc00;
-       sc->regsize = MACH64_REG_SIZE;
+       sc->aperbase = (vaddr_t)bus_space_vaddr(sc->sc_memt, sc->sc_memh);
+       sc->apersize = sc->sc_apersize;
 
 #if _BYTE_ORDER == _BIG_ENDIAN
        sc->aperbase += 0x800000;
@@ -487,8 +492,8 @@
 
        printf("%s: %d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
            sc->sc_dev.dv_xname, (u_int)(sc->apersize / (1024 * 1024)),
-           (u_int)sc->aperbase, (u_int)(sc->regsize / 1024), 
-           (u_int)sc->regbase);
+           (u_int)sc->aperbase, (u_int)(MACH64_REG_SIZE / 1024), 
+           (u_int)MACH64_REG_OFF);
 
        if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_CT ||
            ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT || 
@@ -577,10 +582,16 @@
 
        mach64_rasops_info.ri_ops.allocattr(&mach64_rasops_info, 0, 0, 0,
            &defattr);
-       wsdisplay_cnattach(&mach64_defaultscreen, &mach64_rasops_info, 
-           0, 0, defattr);
 
+#ifdef __sparc__
+       console = sparc_screen_is_console(pa);
+#else
        console = 1;
+#endif
+
+       if (console)
+               wsdisplay_cnattach(&mach64_defaultscreen, &mach64_rasops_info, 
+                   0, 0, defattr);
        
        aa.console = console;
        aa.scrdata = &mach64_screenlist;
@@ -629,10 +640,9 @@
 }
 
 void
-mach64_init(struct mach64_softc *sc, bus_space_tag_t memt)
+mach64_init(struct mach64_softc *sc)
 {
-
-       if (bus_space_map(memt, sc->sc_aperbase, sc->sc_apersize,
+       if (bus_space_map(sc->sc_memt, sc->sc_aperbase, sc->sc_apersize,
                BUS_SPACE_MAP_LINEAR, &sc->sc_memh)) {
                panic("%s: failed to map aperture", sc->sc_dev.dv_xname);
        }
@@ -1267,3 +1277,17 @@
 
        return 0;
 }
+
+#ifdef __sparc__
+int
+sparc_screen_is_console(struct pci_attach_args *pa)
+{
+       int node;
+
+       node = PCITAG_NODE(pa->pa_tag);
+       if (node == -1)
+               return 0;
+
+       return (node == OF_instance_to_package(OF_stdout()));
+}
+#endif



Home | Main Index | Thread Index | Old Index