Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci this has been sitting in my tree too long:



details:   https://anonhg.NetBSD.org/src/rev/a8dcb99ec95e
branches:  trunk
changeset: 754558:a8dcb99ec95e
user:      macallan <macallan%NetBSD.org@localhost>
date:      Tue May 04 05:07:14 2010 +0000

description:
this has been sitting in my tree too long:
- device_t-ify
- sanitize debugging #ifdefs
- deal with firmwares setting up modes using other clocks than #0
- get rid of sparc and macppc-specific code, use device properties instead
- while there, use alternate box drawing font if needed

diffstat:

 sys/dev/pci/machfb.c |  378 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 233 insertions(+), 145 deletions(-)

diffs (truncated from 833 to 300 lines):

diff -r 0aeb952418e1 -r a8dcb99ec95e sys/dev/pci/machfb.c
--- a/sys/dev/pci/machfb.c      Tue May 04 05:00:33 2010 +0000
+++ b/sys/dev/pci/machfb.c      Tue May 04 05:07:14 2010 +0000
@@ -1,7 +1,8 @@
-/*     $NetBSD: machfb.c,v 1.58 2010/03/11 04:00:36 mrg Exp $  */
+/*     $NetBSD: machfb.c,v 1.59 2010/05/04 05:07:14 macallan Exp $     */
 
 /*
  * Copyright (c) 2002 Bang Jun-Young
+ * Copyright (c) 2005, 2006, 2007 Michael Lorenz
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,7 +34,7 @@
 
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, 
-       "$NetBSD: machfb.c,v 1.58 2010/03/11 04:00:36 mrg Exp $");
+       "$NetBSD: machfb.c,v 1.59 2010/05/04 05:07:14 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,18 +42,11 @@
 #include <sys/device.h>
 #include <sys/malloc.h>
 #include <sys/callout.h>
+#include <sys/lwp.h>
 #include <sys/kauth.h>
 
-#ifdef __sparc__
-#include <machine/promlib.h>
-#endif
-
-#ifdef __powerpc__
-#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
-#endif
-
 #include <dev/videomode/videomode.h>
+#include <dev/videomode/edidvar.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
@@ -74,6 +68,9 @@
 
 #include <dev/wscons/wsdisplay_vconsvar.h>
 
+#include "opt_wsemul.h"
+#include "opt_machfb.h"
+
 #define MACH64_REG_SIZE                1024
 #define MACH64_REG_OFF         0x7ffc00
 
@@ -88,7 +85,7 @@
 };
 
 struct mach64_softc {
-       struct device sc_dev;
+       device_t sc_dev;
 #ifdef __sparc__
        struct fbdevice sc_fb;
 #endif
@@ -111,6 +108,7 @@
 
        bus_space_tag_t sc_regt;
        bus_space_tag_t sc_memt;
+       bus_space_tag_t sc_iot;
        bus_space_handle_t sc_regh;
        bus_space_handle_t sc_memh;
        void *sc_aperture;              /* mapped aperture vaddr */
@@ -142,8 +140,12 @@
        int vclk_fb_div;
        int mclk_post_div;
        int mclk_fb_div;
+       int sc_clock;   /* which clock to use */
 
        struct videomode *sc_my_mode;
+       int sc_edid_size;
+       uint8_t sc_edid_data[1024];
+
        u_char sc_cmap_red[256];
        u_char sc_cmap_green[256];
        u_char sc_cmap_blue[256];
@@ -174,6 +176,7 @@
        { PCI_PRODUCT_ATI_RAGE_PRO_PCI_P, 230000 },
        { PCI_PRODUCT_ATI_RAGE_PRO_PCI_L, 230000 },
        { PCI_PRODUCT_ATI_RAGE_XL_PCI, 230000 },
+       { PCI_PRODUCT_ATI_RAGE_XL_PCI66, 230000 },
        { PCI_PRODUCT_ATI_RAGE_II, 135000 },
        { PCI_PRODUCT_ATI_RAGE_IIP, 200000 },
        { PCI_PRODUCT_ATI_RAGE_IIC_PCI, 230000 },
@@ -183,11 +186,12 @@
        { PCI_PRODUCT_ATI_RAGE_LT_PRO_AGP, 230000 },
        { PCI_PRODUCT_ATI_RAGE_MOB_M3_PCI, 230000 },
        { PCI_PRODUCT_ATI_RAGE_MOB_M3_AGP, 230000 },
-       { PCI_PRODUCT_ATI_RAGE_LT, 230000 },
-       { PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI, 230000 },
        { PCI_PRODUCT_ATI_RAGE_MOBILITY, 230000 },
        { PCI_PRODUCT_ATI_RAGE_LT_PRO, 230000 },
 #endif
+       { PCI_PRODUCT_ATI_RAGE_LT_PRO, 230000 },
+       { PCI_PRODUCT_ATI_RAGE_LT, 230000 },
+       { PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI, 230000 },
        { PCI_PRODUCT_ATI_MACH64_VT, 170000 },
        { PCI_PRODUCT_ATI_MACH64_VTB, 200000 },
        { PCI_PRODUCT_ATI_MACH64_VT4, 230000 }
@@ -224,7 +228,7 @@
 static int     mach64_match(device_t, cfdata_t, void *);
 static void    mach64_attach(device_t, device_t, void *);
 
-CFATTACH_DECL(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
+CFATTACH_DECL_NEW(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
     NULL, NULL);
 
 static void    mach64_init(struct mach64_softc *);
@@ -254,7 +258,7 @@
 static void    mach64_init_screen(void *, struct vcons_screen *, int, long *);
 static int     mach64_set_screentype(struct mach64_softc *,
                                      const struct wsscreen_descr *);
-static int     mach64_is_console(struct pci_attach_args *);
+static int     mach64_is_console(struct mach64_softc *);
 
 static void    mach64_cursor(void *, int, int, int);
 #if 0
@@ -265,7 +269,6 @@
 static void    mach64_erasecols(void *, int, int, int, long);
 static void    mach64_copyrows(void *, int, int, int);
 static void    mach64_eraserows(void *, int, int, long);
-static int     mach64_allocattr(void *, int, int, int, long *);
 static void    mach64_clearscreen(struct mach64_softc *);
 
 static int     mach64_putcmap(struct mach64_softc *, struct wsdisplay_cmap *);
@@ -284,19 +287,7 @@
 
 static void    set_address(struct rasops_info *, void *);
 static void    machfb_blank(struct mach64_softc *, int);
-
-#if 0
-static const struct wsdisplay_emulops mach64_emulops = {
-       mach64_cursor,
-       mach64_mapchar,
-       mach64_putchar,
-       mach64_copycols,
-       mach64_erasecols,
-       mach64_copyrows,
-       mach64_eraserows,
-       mach64_allocattr,
-};
-#endif
+static int     machfb_drm_print(void *, const char *);
 
 static struct wsscreen_descr mach64_defaultscreen = {
        "default",
@@ -449,9 +440,26 @@
 static inline void
 regwb_pll(struct mach64_softc *sc, uint32_t index, uint8_t data)
 {
-       regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
-       regwb(sc, CLOCK_CNTL + 2, data);
-       regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
+       uint32_t reg;
+
+       reg = regr(sc, CLOCK_CNTL);
+       reg |= PLL_WR_EN;
+       regw(sc, CLOCK_CNTL, reg);
+       reg &= ~(PLL_ADDR | PLL_DATA);
+       reg |= (index & 0x3f) << PLL_ADDR_SHIFT;
+       reg |= data << PLL_DATA_SHIFT;
+       reg |= CLOCK_STROBE;
+       regw(sc, CLOCK_CNTL, reg);
+       reg &= ~PLL_WR_EN;
+       regw(sc, CLOCK_CNTL, reg);
+}
+
+static inline uint8_t
+regrb_pll(struct mach64_softc *sc, uint32_t index)
+{
+
+       regwb(sc, CLOCK_CNTL + 1, index << 2);
+       return regrb(sc, CLOCK_CNTL + 2);
 }
 
 static inline void
@@ -495,13 +503,17 @@
        struct mach64_softc *sc = device_private(self);
        struct pci_attach_args *pa = aux;
        struct rasops_info *ri;
+       prop_data_t edid_data;
+       const struct videomode *mode = NULL;
        char devinfo[256];
-       int bar, reg, id;
+       int bar, id;
        struct wsemuldisplaydev_attach_args aa;
        long defattr;
-       int setmode;
+       int setmode, width, height;
        pcireg_t screg;
+       uint32_t reg;
 
+       sc->sc_dev = self;
        sc->sc_pc = pa->pa_pc;
        sc->sc_pcitag = pa->pa_tag;
        sc->sc_dacw = -1;
@@ -510,16 +522,24 @@
        sc->sc_ndev = pa->pa_device;
        sc->sc_nfunc = pa->pa_function;
        sc->sc_locked = 0;
+       sc->sc_iot = pa->pa_iot;
 
        pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
-       aprint_normal(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
+       aprint_normal(": %s (rev. 0x%02x)\n", devinfo, 
+           PCI_REVISION(pa->pa_class));
        aprint_naive(": Graphics processor\n");
+#ifdef DEBUG
+       printf(prop_dictionary_externalize(device_properties(self)));
+#endif
        
-       /* enable memory and IO access */
+       /* enable memory and disable IO access */
        screg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, PCI_COMMAND_STATUS_REG);
-       screg |= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
-       pci_conf_write(sc->sc_pc, sc->sc_pcitag,PCI_COMMAND_STATUS_REG,screg);
-
+       if ((screg & PCI_FLAGS_MEM_ENABLED) == 0) {
+               screg |= PCI_FLAGS_IO_ENABLED;
+               screg |= PCI_FLAGS_MEM_ENABLED;
+               pci_conf_write(sc->sc_pc, sc->sc_pcitag,
+                   PCI_COMMAND_STATUS_REG, screg);
+       }
        for (bar = 0; bar < NBARS; bar++) {
                reg = PCI_MAPREG_START + (bar * 4);
                sc->sc_bars[bar].vb_type = pci_mapreg_type(sc->sc_pc,
@@ -528,18 +548,65 @@
                    sc->sc_bars[bar].vb_type, &sc->sc_bars[bar].vb_base,
                    &sc->sc_bars[bar].vb_size, &sc->sc_bars[bar].vb_flags);
                sc->sc_bars[bar].vb_busaddr = pci_conf_read(sc->sc_pc,
-                   sc->sc_pcitag, reg)&0xfffffff0;
+                   sc->sc_pcitag, reg) & 0xfffffff0;
        }
+       printf("%s: aperture size %08x\n", device_xname(sc->sc_dev), 
+           (uint32_t)sc->sc_apersize);
+
+       sc->sc_rom.vb_type = PCI_MAPREG_TYPE_ROM;       
+       pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, PCI_MAPREG_ROM,
+                   sc->sc_rom.vb_type, &sc->sc_rom.vb_base,
+                   &sc->sc_rom.vb_size, &sc->sc_rom.vb_flags);
        sc->sc_memt = pa->pa_memt;
 
+       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", device_xname(sc->sc_dev));
+       }
+       sc->sc_aperture = (void *)bus_space_vaddr(sc->sc_memt, sc->sc_memh);
+
+       sc->sc_regt = sc->sc_memt;
+       bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
+           sc->sc_regsize, &sc->sc_regh);
+       sc->sc_registers = (char *)sc->sc_aperture + 0x7ffc00;
+
        mach64_init(sc);
 
-       aprint_normal_dev(&sc->sc_dev,
+       aprint_normal_dev(sc->sc_dev,
            "%d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
            (u_int)(sc->sc_apersize / (1024 * 1024)),
            (u_int)sc->sc_aperphys, (u_int)(sc->sc_regsize / 1024),
            (u_int)sc->sc_regphys);
 
+       printf("%s: %d KB ROM at 0x%08x\n", device_xname(sc->sc_dev),
+           (int)sc->sc_rom.vb_size >> 10, (uint32_t)sc->sc_rom.vb_base);
+
+       prop_dictionary_get_uint32(device_properties(self), "width", &width);
+       prop_dictionary_get_uint32(device_properties(self), "height", &height);
+
+       if ((edid_data = prop_dictionary_get(device_properties(self), "EDIDDD"))
+           != NULL) {
+               struct edid_info ei;
+
+               sc->sc_edid_size = min(1024, prop_data_size(edid_data));
+               memset(sc->sc_edid_data, 0, sizeof(sc->sc_edid_data));
+               memcpy(sc->sc_edid_data, prop_data_data_nocopy(edid_data),
+                   sc->sc_edid_size);
+
+               edid_parse(sc->sc_edid_data, &ei);
+
+#ifdef DEBUG
+               edid_print(&ei);
+#endif
+               if (ei.edid_have_range) {
+
+                       /* ei has dotclock in MHz, struct videomode in kHz */
+                       mode = pick_mode_by_dotclock(width, height,
+                           ei.edid_range.er_max_clock * 1000);
+                       if (mode != NULL)
+                               printf("mode: %s\n", mode->name);
+               }
+       }
        if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_CT ||
            ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||



Home | Main Index | Thread Index | Old Index