2007-03-04 08:59:00 +03:00
|
|
|
/* $NetBSD: machfb.c,v 1.49 2007/03/04 06:02:24 christos Exp $ */
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Bang Jun-Young
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2002-12-11 08:49:34 +03:00
|
|
|
* derived from this software without specific prior written permission.
|
2002-10-24 22:15:57 +04:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some code is derived from ATI Rage Pro and Derivatives Programmer's Guide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2005-05-02 18:49:08 +04:00
|
|
|
__KERNEL_RCSID(0,
|
2007-03-04 08:59:00 +03:00
|
|
|
"$NetBSD: machfb.c,v 1.49 2007/03/04 06:02:24 christos Exp $");
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
|
2002-10-25 22:03:03 +04:00
|
|
|
#ifdef __sparc__
|
2004-03-22 11:36:28 +03:00
|
|
|
#include <machine/promlib.h>
|
2002-10-25 22:03:03 +04:00
|
|
|
#endif
|
|
|
|
|
2005-01-18 01:52:46 +03:00
|
|
|
#ifdef __powerpc__
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
#include <dev/ofw/ofw_pci.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#include <dev/videomode/videomode.h>
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#include <dev/pci/pciio.h>
|
|
|
|
#include <dev/pci/machfbreg.h>
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef __sparc__
|
|
|
|
#include <dev/sun/fbio.h>
|
|
|
|
#include <dev/sun/fbvar.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#else
|
2002-10-24 22:15:57 +04:00
|
|
|
#include <dev/wscons/wsdisplayvar.h>
|
2006-04-13 00:35:42 +04:00
|
|
|
#endif
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wsfont/wsfont.h>
|
|
|
|
#include <dev/rasops/rasops.h>
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#include <dev/wscons/wsdisplay_vconsvar.h>
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
#define MACH64_REG_SIZE 1024
|
2002-10-25 22:03:03 +04:00
|
|
|
#define MACH64_REG_OFF 0x7ffc00
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
#define NBARS 3 /* number of Mach64 PCI BARs */
|
|
|
|
|
|
|
|
struct vga_bar {
|
|
|
|
bus_addr_t vb_base;
|
2005-01-18 01:52:46 +03:00
|
|
|
pcireg_t vb_busaddr;
|
2002-10-24 22:15:57 +04:00
|
|
|
bus_size_t vb_size;
|
|
|
|
pcireg_t vb_type;
|
|
|
|
int vb_flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mach64_softc {
|
|
|
|
struct device sc_dev;
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef __sparc__
|
|
|
|
struct fbdevice sc_fb;
|
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
pci_chipset_tag_t sc_pc;
|
|
|
|
pcitag_t sc_pcitag;
|
|
|
|
|
|
|
|
struct vga_bar sc_bars[NBARS];
|
|
|
|
struct vga_bar sc_rom;
|
|
|
|
|
|
|
|
#define sc_aperbase sc_bars[0].vb_base
|
|
|
|
#define sc_apersize sc_bars[0].vb_size
|
2005-01-18 01:52:46 +03:00
|
|
|
#define sc_aperphys sc_bars[0].vb_busaddr
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
#define sc_iobase sc_bars[1].vb_base
|
|
|
|
#define sc_iosize sc_bars[1].vb_size
|
|
|
|
|
|
|
|
#define sc_regbase sc_bars[2].vb_base
|
|
|
|
#define sc_regsize sc_bars[2].vb_size
|
2005-01-18 01:52:46 +03:00
|
|
|
#define sc_regphys sc_bars[2].vb_busaddr
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2002-10-25 22:57:06 +04:00
|
|
|
bus_space_tag_t sc_regt;
|
2002-10-25 22:03:03 +04:00
|
|
|
bus_space_tag_t sc_memt;
|
2002-10-25 22:57:06 +04:00
|
|
|
bus_space_handle_t sc_regh;
|
2002-10-24 22:15:57 +04:00
|
|
|
bus_space_handle_t sc_memh;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *sc_aperture; /* mapped aperture vaddr */
|
|
|
|
void *sc_registers; /* mapped registers vaddr */
|
2006-04-19 21:41:24 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
uint32_t sc_nbus, sc_ndev, sc_nfunc;
|
2002-10-24 22:15:57 +04:00
|
|
|
size_t memsize;
|
|
|
|
int memtype;
|
2005-05-02 15:22:31 +04:00
|
|
|
|
2005-02-25 19:00:58 +03:00
|
|
|
int sc_mode;
|
|
|
|
int sc_bg;
|
2006-04-13 00:35:42 +04:00
|
|
|
int sc_locked;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
int has_dsp;
|
|
|
|
int bits_per_pixel;
|
2005-05-02 18:49:08 +04:00
|
|
|
int max_x;
|
|
|
|
int max_y;
|
|
|
|
int virt_x;
|
|
|
|
int virt_y;
|
2002-10-24 22:15:57 +04:00
|
|
|
int color_depth;
|
|
|
|
|
|
|
|
int mem_freq;
|
|
|
|
int ramdac_freq;
|
|
|
|
int ref_freq;
|
|
|
|
|
|
|
|
int ref_div;
|
|
|
|
int log2_vclk_post_div;
|
|
|
|
int vclk_post_div;
|
|
|
|
int vclk_fb_div;
|
|
|
|
int mclk_post_div;
|
|
|
|
int mclk_fb_div;
|
|
|
|
|
2005-09-21 22:49:16 +04:00
|
|
|
struct videomode *sc_my_mode;
|
2005-01-09 19:29:20 +03:00
|
|
|
u_char sc_cmap_red[256];
|
|
|
|
u_char sc_cmap_green[256];
|
2005-02-27 03:26:58 +03:00
|
|
|
u_char sc_cmap_blue[256];
|
2006-04-13 00:35:42 +04:00
|
|
|
int sc_dacw, sc_blanked, sc_console;
|
|
|
|
struct vcons_data vd;
|
2002-10-24 22:15:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mach64_crtcregs {
|
2006-04-13 00:35:42 +04:00
|
|
|
uint32_t h_total_disp;
|
|
|
|
uint32_t h_sync_strt_wid;
|
|
|
|
uint32_t v_total_disp;
|
|
|
|
uint32_t v_sync_strt_wid;
|
|
|
|
uint32_t gen_cntl;
|
|
|
|
uint32_t clock_cntl;
|
|
|
|
uint32_t color_depth;
|
|
|
|
uint32_t dot_clock;
|
2002-10-24 22:15:57 +04:00
|
|
|
};
|
|
|
|
|
2006-09-02 10:56:30 +04:00
|
|
|
static struct {
|
2006-04-13 00:35:42 +04:00
|
|
|
uint16_t chip_id;
|
|
|
|
uint32_t ramdac_freq;
|
2006-09-02 10:56:30 +04:00
|
|
|
} const mach64_info[] = {
|
2002-10-24 22:15:57 +04:00
|
|
|
{ PCI_PRODUCT_ATI_MACH64_CT, 135000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_PRO_AGP, 230000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_PRO_AGP1X, 230000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_PRO_PCI_B, 230000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_XL_AGP, 230000 },
|
|
|
|
{ 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_II, 135000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_IIP, 200000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_IIC_PCI, 230000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_IIC_AGP_B, 230000 },
|
|
|
|
{ PCI_PRODUCT_ATI_RAGE_IIC_AGP_P, 230000 },
|
|
|
|
{ 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 },
|
|
|
|
{ PCI_PRODUCT_ATI_MACH64_VT, 170000 },
|
|
|
|
{ PCI_PRODUCT_ATI_MACH64_VTB, 200000 },
|
|
|
|
{ PCI_PRODUCT_ATI_MACH64_VT4, 230000 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mach64_chip_id, mach64_chip_rev;
|
2006-09-02 10:56:30 +04:00
|
|
|
static struct videomode default_mode = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-05-31 02:18:41 +04:00
|
|
|
static const char *mach64_memtype_names[] = {
|
2002-10-24 22:15:57 +04:00
|
|
|
"(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
|
|
|
|
"(unknown type)"
|
|
|
|
};
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static struct videomode mach64_modes[] = {
|
2002-10-24 22:15:57 +04:00
|
|
|
/* 640x400 @ 70 Hz, 31.5 kHz */
|
2006-09-02 10:56:30 +04:00
|
|
|
{ 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0, NULL, },
|
2002-10-24 22:15:57 +04:00
|
|
|
/* 640x480 @ 72 Hz, 36.5 kHz */
|
2006-09-02 10:56:30 +04:00
|
|
|
{ 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0, NULL, },
|
2002-10-24 22:15:57 +04:00
|
|
|
/* 800x600 @ 72 Hz, 48.0 kHz */
|
|
|
|
{ 50000, 800, 856, 976, 1040, 600, 637, 643, 666,
|
2006-09-02 10:56:30 +04:00
|
|
|
VID_PHSYNC | VID_PVSYNC, NULL, },
|
2002-10-24 22:15:57 +04:00
|
|
|
/* 1024x768 @ 70 Hz, 56.5 kHz */
|
|
|
|
{ 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806,
|
2006-09-02 10:56:30 +04:00
|
|
|
VID_NHSYNC | VID_NVSYNC, NULL, },
|
2002-10-24 22:15:57 +04:00
|
|
|
/* 1152x864 @ 70 Hz, 62.4 kHz */
|
2006-09-02 10:56:30 +04:00
|
|
|
{ 92000, 1152, 1208, 1368, 1474, 864, 865, 875, 895, 0, NULL, },
|
2002-10-24 22:15:57 +04:00
|
|
|
/* 1280x1024 @ 70 Hz, 74.59 kHz */
|
|
|
|
{ 126500, 1280, 1312, 1472, 1696, 1024, 1032, 1040, 1068,
|
2006-09-02 10:56:30 +04:00
|
|
|
VID_NHSYNC | VID_NVSYNC, NULL, }
|
2002-10-24 22:15:57 +04:00
|
|
|
};
|
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
extern const u_char rasops_cmap[768];
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int mach64_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void mach64_attach(struct device *, struct device *, void *);
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
CFATTACH_DECL(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void mach64_init(struct mach64_softc *);
|
|
|
|
static int mach64_get_memsize(struct mach64_softc *);
|
|
|
|
static int mach64_get_max_ramdac(struct mach64_softc *);
|
2005-10-03 15:22:06 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#if defined(__sparc__) || defined(__powerpc__)
|
2005-07-07 22:43:47 +04:00
|
|
|
static void mach64_get_mode(struct mach64_softc *, struct videomode *);
|
2005-10-03 15:22:06 +04:00
|
|
|
#endif
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int mach64_calc_crtcregs(struct mach64_softc *,
|
|
|
|
struct mach64_crtcregs *,
|
|
|
|
struct videomode *);
|
|
|
|
static void mach64_set_crtcregs(struct mach64_softc *,
|
|
|
|
struct mach64_crtcregs *);
|
2005-09-21 22:49:16 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int mach64_modeswitch(struct mach64_softc *, struct videomode *);
|
|
|
|
static void mach64_set_dsp(struct mach64_softc *);
|
|
|
|
static void mach64_set_pll(struct mach64_softc *, int);
|
|
|
|
static void mach64_reset_engine(struct mach64_softc *);
|
|
|
|
static void mach64_init_engine(struct mach64_softc *);
|
|
|
|
#if 0
|
|
|
|
static void mach64_adjust_frame(struct mach64_softc *, int, int);
|
|
|
|
#endif
|
|
|
|
static void mach64_init_lut(struct mach64_softc *);
|
2006-04-13 00:35:42 +04:00
|
|
|
|
|
|
|
static void mach64_init_screen(void *, struct vcons_screen *, int, long *);
|
2005-07-07 22:43:47 +04:00
|
|
|
static int mach64_set_screentype(struct mach64_softc *,
|
|
|
|
const struct wsscreen_descr *);
|
|
|
|
static int mach64_is_console(struct pci_attach_args *);
|
|
|
|
|
|
|
|
static void mach64_cursor(void *, int, int, int);
|
|
|
|
#if 0
|
|
|
|
static int mach64_mapchar(void *, int, u_int *);
|
|
|
|
#endif
|
|
|
|
static void mach64_putchar(void *, int, int, u_int, long);
|
|
|
|
static void mach64_copycols(void *, int, int, int, int);
|
|
|
|
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 *);
|
|
|
|
static int mach64_getcmap(struct mach64_softc *, struct wsdisplay_cmap *);
|
|
|
|
static int mach64_putpalreg(struct mach64_softc *, uint8_t, uint8_t,
|
|
|
|
uint8_t, uint8_t);
|
|
|
|
static void mach64_bitblt(struct mach64_softc *, int, int, int, int, int,
|
|
|
|
int, int, int) ;
|
|
|
|
static void mach64_rectfill(struct mach64_softc *, int, int, int, int, int);
|
|
|
|
static void mach64_setup_mono(struct mach64_softc *, int, int, int, int,
|
|
|
|
uint32_t, uint32_t);
|
|
|
|
static void mach64_feed_bytes(struct mach64_softc *, int, uint8_t *);
|
|
|
|
#if 0
|
|
|
|
static void mach64_showpal(struct mach64_softc *);
|
|
|
|
#endif
|
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
static void set_address(struct rasops_info *, void *);
|
2005-10-01 23:01:01 +04:00
|
|
|
static void machfb_blank(struct mach64_softc *, int);
|
2005-01-09 19:29:20 +03:00
|
|
|
|
2002-10-31 17:10:07 +03:00
|
|
|
#if 0
|
2005-07-07 22:43:47 +04:00
|
|
|
static const struct wsdisplay_emulops mach64_emulops = {
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_cursor,
|
|
|
|
mach64_mapchar,
|
|
|
|
mach64_putchar,
|
|
|
|
mach64_copycols,
|
|
|
|
mach64_erasecols,
|
|
|
|
mach64_copyrows,
|
|
|
|
mach64_eraserows,
|
|
|
|
mach64_allocattr,
|
|
|
|
};
|
2002-10-31 17:10:07 +03:00
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static struct wsscreen_descr mach64_defaultscreen = {
|
2002-10-24 22:15:57 +04:00
|
|
|
"default",
|
2005-09-21 22:49:16 +04:00
|
|
|
80, 30,
|
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&default_mode
|
|
|
|
}, mach64_80x25_screen = {
|
|
|
|
"80x25", 80, 25,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[0]
|
|
|
|
}, mach64_80x30_screen = {
|
|
|
|
"80x30", 80, 30,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[1]
|
|
|
|
}, mach64_80x40_screen = {
|
|
|
|
"80x40", 80, 40,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 10,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[0]
|
|
|
|
}, mach64_80x50_screen = {
|
|
|
|
"80x50", 80, 50,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 8,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[0]
|
|
|
|
}, mach64_100x37_screen = {
|
|
|
|
"100x37", 100, 37,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[2]
|
|
|
|
}, mach64_128x48_screen = {
|
|
|
|
"128x48", 128, 48,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[3]
|
|
|
|
}, mach64_144x54_screen = {
|
|
|
|
"144x54", 144, 54,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[4]
|
|
|
|
}, mach64_160x64_screen = {
|
|
|
|
"160x54", 160, 64,
|
2005-09-21 22:49:16 +04:00
|
|
|
NULL,
|
2002-10-24 22:15:57 +04:00
|
|
|
8, 16,
|
|
|
|
WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
|
|
|
|
&mach64_modes[5]
|
|
|
|
};
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static const struct wsscreen_descr *_mach64_scrlist[] = {
|
2002-10-24 22:15:57 +04:00
|
|
|
&mach64_defaultscreen,
|
|
|
|
&mach64_80x25_screen,
|
|
|
|
&mach64_80x30_screen,
|
|
|
|
&mach64_80x40_screen,
|
|
|
|
&mach64_80x50_screen,
|
|
|
|
&mach64_100x37_screen,
|
|
|
|
&mach64_128x48_screen,
|
|
|
|
&mach64_144x54_screen,
|
|
|
|
&mach64_160x64_screen
|
|
|
|
};
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static struct wsscreen_list mach64_screenlist = {
|
2002-10-24 22:15:57 +04:00
|
|
|
sizeof(_mach64_scrlist) / sizeof(struct wsscreen_descr *),
|
|
|
|
_mach64_scrlist
|
|
|
|
};
|
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
static int mach64_ioctl(void *, void *, u_long, void *, int,
|
2006-04-12 23:38:22 +04:00
|
|
|
struct lwp *);
|
|
|
|
static paddr_t mach64_mmap(void *, void *, off_t, int);
|
2006-04-13 00:35:42 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
#if 0
|
|
|
|
static int mach64_load_font(void *, void *, struct wsdisplay_font *);
|
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static struct wsdisplay_accessops mach64_accessops = {
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_ioctl,
|
|
|
|
mach64_mmap,
|
2006-04-13 00:35:42 +04:00
|
|
|
NULL, /* vcons_alloc_screen */
|
|
|
|
NULL, /* vcons_free_screen */
|
|
|
|
NULL, /* vcons_show_screen */
|
2005-05-02 18:49:08 +04:00
|
|
|
NULL, /* load_font */
|
|
|
|
NULL, /* polls */
|
|
|
|
NULL, /* scroll */
|
2002-10-24 22:15:57 +04:00
|
|
|
};
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
static struct vcons_screen mach64_console_screen;
|
|
|
|
|
|
|
|
/* framebuffer device, SPARC-only so far */
|
|
|
|
#ifdef __sparc__
|
|
|
|
|
|
|
|
static void machfb_unblank(struct device *);
|
|
|
|
static void machfb_fbattach(struct mach64_softc *);
|
|
|
|
|
|
|
|
extern struct cfdriver machfb_cd;
|
|
|
|
|
|
|
|
dev_type_open(machfb_fbopen);
|
|
|
|
dev_type_close(machfb_fbclose);
|
|
|
|
dev_type_ioctl(machfb_fbioctl);
|
|
|
|
dev_type_mmap(machfb_fbmmap);
|
|
|
|
|
|
|
|
/* frame buffer generic driver */
|
|
|
|
static struct fbdriver machfb_fbdriver = {
|
|
|
|
machfb_unblank, machfb_fbopen, machfb_fbclose, machfb_fbioctl, nopoll,
|
|
|
|
machfb_fbmmap, nokqfilter
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __sparc__ */
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
/*
|
|
|
|
* Inline functions for getting access to register aperture.
|
|
|
|
*/
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
static inline uint32_t
|
|
|
|
regr(struct mach64_softc *sc, uint32_t index)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2002-10-25 22:57:06 +04:00
|
|
|
return bus_space_read_4(sc->sc_regt, sc->sc_regh, index);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
static inline uint8_t
|
|
|
|
regrb(struct mach64_softc *sc, uint32_t index)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2002-10-25 22:57:06 +04:00
|
|
|
return bus_space_read_1(sc->sc_regt, sc->sc_regh, index);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2006-04-13 00:35:42 +04:00
|
|
|
regw(struct mach64_softc *sc, uint32_t index, uint32_t data)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2002-10-25 22:57:06 +04:00
|
|
|
bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
|
2005-05-02 18:49:08 +04:00
|
|
|
bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2006-04-13 00:35:42 +04:00
|
|
|
regwb(struct mach64_softc *sc, uint32_t index, uint8_t data)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2002-10-25 22:57:06 +04:00
|
|
|
bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
|
2005-05-02 18:49:08 +04:00
|
|
|
bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2006-04-13 00:35:42 +04:00
|
|
|
regwb_pll(struct mach64_softc *sc, uint32_t index, uint8_t data)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
|
|
|
regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
|
|
|
|
regwb(sc, CLOCK_CNTL + 2, data);
|
2005-02-27 03:26:58 +03:00
|
|
|
regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2006-04-13 00:35:42 +04:00
|
|
|
wait_for_fifo(struct mach64_softc *sc, uint8_t v)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
|
|
|
while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
|
2005-06-01 01:16:06 +04:00
|
|
|
continue;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
wait_for_idle(struct mach64_softc *sc)
|
|
|
|
{
|
|
|
|
wait_for_fifo(sc, 16);
|
|
|
|
while ((regr(sc, GUI_STAT) & 1) != 0)
|
2005-06-01 01:16:06 +04:00
|
|
|
continue;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mach64_match(struct device *parent, struct cfdata *match,
|
2006-10-12 05:30:41 +04:00
|
|
|
void *aux)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = (struct pci_attach_args *)aux;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
|
|
|
|
PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
|
|
|
|
if (PCI_PRODUCT(pa->pa_id) == mach64_info[i].chip_id) {
|
|
|
|
mach64_chip_id = PCI_PRODUCT(pa->pa_id);
|
|
|
|
mach64_chip_rev = PCI_REVISION(pa->pa_class);
|
2005-05-02 15:22:31 +04:00
|
|
|
return 100;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
mach64_attach(struct device *parent, struct device *self, void *aux)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2005-02-27 03:26:58 +03:00
|
|
|
struct mach64_softc *sc = (void *)self;
|
2002-10-24 22:15:57 +04:00
|
|
|
struct pci_attach_args *pa = aux;
|
2006-04-13 00:35:42 +04:00
|
|
|
struct rasops_info *ri;
|
2002-10-24 22:15:57 +04:00
|
|
|
char devinfo[256];
|
|
|
|
int bar, reg, id;
|
|
|
|
struct wsemuldisplaydev_attach_args aa;
|
|
|
|
long defattr;
|
2006-04-13 00:35:42 +04:00
|
|
|
int setmode;
|
2005-02-25 19:00:58 +03:00
|
|
|
pcireg_t screg;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
sc->sc_pc = pa->pa_pc;
|
|
|
|
sc->sc_pcitag = pa->pa_tag;
|
2005-05-02 20:02:43 +04:00
|
|
|
sc->sc_dacw = -1;
|
|
|
|
sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
|
2006-04-13 00:35:42 +04:00
|
|
|
sc->sc_nbus = pa->pa_bus;
|
|
|
|
sc->sc_ndev = pa->pa_device;
|
|
|
|
sc->sc_nfunc = pa->pa_function;
|
|
|
|
sc->sc_locked = 0;
|
2005-05-02 15:22:31 +04:00
|
|
|
|
2004-04-24 01:13:05 +04:00
|
|
|
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
|
2002-10-24 22:15:57 +04:00
|
|
|
printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
|
2005-05-02 15:22:31 +04:00
|
|
|
|
|
|
|
/* enable memory and IO access */
|
2005-05-02 20:02:43 +04:00
|
|
|
screg = pci_conf_read(sc->sc_pc, sc->sc_pcitag, PCI_COMMAND_STATUS_REG);
|
|
|
|
screg |= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
|
2005-02-25 19:00:58 +03:00
|
|
|
pci_conf_write(sc->sc_pc, sc->sc_pcitag,PCI_COMMAND_STATUS_REG,screg);
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
for (bar = 0; bar < NBARS; bar++) {
|
|
|
|
reg = PCI_MAPREG_START + (bar * 4);
|
|
|
|
sc->sc_bars[bar].vb_type = pci_mapreg_type(sc->sc_pc,
|
|
|
|
sc->sc_pcitag, reg);
|
|
|
|
(void)pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, reg,
|
|
|
|
sc->sc_bars[bar].vb_type, &sc->sc_bars[bar].vb_base,
|
|
|
|
&sc->sc_bars[bar].vb_size, &sc->sc_bars[bar].vb_flags);
|
2005-05-02 20:02:43 +04:00
|
|
|
sc->sc_bars[bar].vb_busaddr = pci_conf_read(sc->sc_pc,
|
2005-05-02 18:49:08 +04:00
|
|
|
sc->sc_pcitag, reg)&0xfffffff0;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
2002-10-25 22:03:03 +04:00
|
|
|
sc->sc_memt = pa->pa_memt;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2002-10-25 22:03:03 +04:00
|
|
|
mach64_init(sc);
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
printf("%s: %d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
|
2002-10-25 22:57:06 +04:00
|
|
|
sc->sc_dev.dv_xname, (u_int)(sc->sc_apersize / (1024 * 1024)),
|
2005-02-27 03:26:58 +03:00
|
|
|
(u_int)sc->sc_aperphys, (u_int)(sc->sc_regsize / 1024),
|
2005-01-18 01:52:46 +03:00
|
|
|
(u_int)sc->sc_regphys);
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_CT ||
|
2005-02-27 03:26:58 +03:00
|
|
|
((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
|
2005-05-02 18:49:08 +04:00
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
|
|
|
|
(mach64_chip_rev & 0x07) == 0))
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->has_dsp = 0;
|
|
|
|
else
|
|
|
|
sc->has_dsp = 1;
|
|
|
|
|
|
|
|
sc->memsize = mach64_get_memsize(sc);
|
|
|
|
if (sc->memsize == 8192)
|
|
|
|
/* The last page is used as register aperture. */
|
|
|
|
sc->memsize -= 4;
|
|
|
|
sc->memtype = regr(sc, CONFIG_STAT0) & 0x07;
|
|
|
|
|
|
|
|
/* XXX is there any way to calculate reference frequency from
|
|
|
|
known values? */
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((mach64_chip_id == PCI_PRODUCT_ATI_RAGE_XL_PCI) ||
|
2005-05-02 20:02:43 +04:00
|
|
|
((mach64_chip_id >= PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI) &&
|
|
|
|
(mach64_chip_id <= PCI_PRODUCT_ATI_RAGE_LT_PRO))) {
|
2005-12-18 22:21:12 +03:00
|
|
|
printf("%s: ref_freq=29.498MHz\n", sc->sc_dev.dv_xname);
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->ref_freq = 29498;
|
2005-02-25 19:00:58 +03:00
|
|
|
} else
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->ref_freq = 14318;
|
|
|
|
|
|
|
|
regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
|
2005-02-27 03:26:58 +03:00
|
|
|
sc->ref_div = regrb(sc, CLOCK_CNTL + 2);
|
2002-10-24 22:15:57 +04:00
|
|
|
regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
|
|
|
|
sc->mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
|
2005-02-27 03:26:58 +03:00
|
|
|
sc->mem_freq = (2 * sc->ref_freq * sc->mclk_fb_div) /
|
2002-10-24 22:15:57 +04:00
|
|
|
(sc->ref_div * 2);
|
|
|
|
sc->mclk_post_div = (sc->mclk_fb_div * 2 * sc->ref_freq) /
|
|
|
|
(sc->mem_freq * sc->ref_div);
|
|
|
|
sc->ramdac_freq = mach64_get_max_ramdac(sc);
|
2002-10-25 00:41:59 +04:00
|
|
|
printf("%s: %ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz\n",
|
2005-02-27 03:26:58 +03:00
|
|
|
sc->sc_dev.dv_xname, (u_long)sc->memsize,
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_memtype_names[sc->memtype],
|
|
|
|
sc->mem_freq / 1000, sc->mem_freq % 1000,
|
|
|
|
sc->ramdac_freq / 1000);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
id = regr(sc, CONFIG_CHIP_ID) & 0xffff;
|
|
|
|
if (id != mach64_chip_id) {
|
|
|
|
printf("%s: chip ID mismatch, 0x%x != 0x%x\n",
|
|
|
|
sc->sc_dev.dv_xname, id, mach64_chip_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
sc->sc_console = mach64_is_console(pa);
|
2005-10-01 23:01:01 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("gen_cntl: %08x\n", regr(sc, CRTC_GEN_CNTL));
|
|
|
|
#endif
|
2005-01-18 01:52:46 +03:00
|
|
|
#if defined(__sparc__) || defined(__powerpc__)
|
2006-04-13 00:35:42 +04:00
|
|
|
if (sc->sc_console) {
|
2002-10-31 17:10:07 +03:00
|
|
|
mach64_get_mode(sc, &default_mode);
|
|
|
|
setmode = 0;
|
2005-09-21 22:49:16 +04:00
|
|
|
sc->sc_my_mode = &default_mode;
|
2002-10-31 17:10:07 +03:00
|
|
|
} else {
|
2005-09-21 22:49:16 +04:00
|
|
|
/* fill in default_mode if it's empty */
|
2006-04-13 00:35:42 +04:00
|
|
|
mach64_get_mode(sc, &default_mode);
|
2005-09-21 22:49:16 +04:00
|
|
|
if (default_mode.dot_clock == 0) {
|
|
|
|
memcpy(&default_mode, &mach64_modes[4],
|
|
|
|
sizeof(default_mode));
|
|
|
|
}
|
2005-10-01 23:01:01 +04:00
|
|
|
sc->sc_my_mode = &default_mode;
|
2002-10-31 17:10:07 +03:00
|
|
|
setmode = 1;
|
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
#else
|
2005-10-03 15:22:06 +04:00
|
|
|
if (default_mode.dot_clock == 0) {
|
|
|
|
memcpy(&default_mode, &mach64_modes[0],
|
|
|
|
sizeof(default_mode));
|
|
|
|
}
|
|
|
|
sc->sc_my_mode = &mach64_modes[0];
|
|
|
|
setmode = 1;
|
2002-10-24 22:15:57 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->bits_per_pixel = 8;
|
2005-09-21 22:49:16 +04:00
|
|
|
sc->virt_x = sc->sc_my_mode->hdisplay;
|
|
|
|
sc->virt_y = sc->sc_my_mode->vdisplay;
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->max_x = sc->virt_x - 1;
|
|
|
|
sc->max_y = (sc->memsize * 1024) /
|
|
|
|
(sc->virt_x * (sc->bits_per_pixel / 8)) - 1;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->color_depth = CRTC_PIX_WIDTH_8BPP;
|
|
|
|
|
|
|
|
mach64_init_engine(sc);
|
|
|
|
#if 0
|
|
|
|
mach64_adjust_frame(0, 0);
|
|
|
|
if (sc->bits_per_pixel == 8)
|
|
|
|
mach64_init_lut(sc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("%s: initial resolution %dx%d at %d bpp\n", sc->sc_dev.dv_xname,
|
2005-09-21 22:49:16 +04:00
|
|
|
sc->sc_my_mode->hdisplay, sc->sc_my_mode->vdisplay,
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->bits_per_pixel);
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef __sparc__
|
|
|
|
machfb_fbattach(sc);
|
|
|
|
#endif
|
2005-09-21 22:49:16 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
wsfont_init();
|
|
|
|
|
|
|
|
sc->sc_bg = WS_DEFAULT_BG;
|
|
|
|
vcons_init(&sc->vd, sc, &mach64_defaultscreen, &mach64_accessops);
|
|
|
|
sc->vd.init_screen = mach64_init_screen;
|
|
|
|
|
|
|
|
if (sc->sc_console) {
|
|
|
|
vcons_init_screen(&sc->vd, &mach64_console_screen, 1,
|
|
|
|
&defattr);
|
|
|
|
mach64_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
|
|
|
|
|
|
|
|
ri = &mach64_console_screen.scr_ri;
|
|
|
|
mach64_defaultscreen.textops = &ri->ri_ops;
|
|
|
|
mach64_defaultscreen.capabilities = ri->ri_caps;
|
|
|
|
mach64_defaultscreen.nrows = ri->ri_rows;
|
|
|
|
mach64_defaultscreen.ncols = ri->ri_cols;
|
|
|
|
wsdisplay_cnattach(&mach64_defaultscreen, ri, 0, 0, defattr);
|
2005-09-21 22:49:16 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* since we're not the console we can postpone the rest
|
|
|
|
* until someone actually allocates a screen for us
|
|
|
|
*/
|
2005-10-01 23:01:01 +04:00
|
|
|
mach64_modeswitch(sc, sc->sc_my_mode);
|
2002-10-31 17:10:07 +03:00
|
|
|
}
|
2005-09-21 22:49:16 +04:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
mach64_init_lut(sc);
|
2005-02-25 19:00:58 +03:00
|
|
|
mach64_clearscreen(sc);
|
2005-10-01 23:01:01 +04:00
|
|
|
machfb_blank(sc, 0); /* unblank the screen */
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
aa.console = sc->sc_console;
|
2002-10-24 22:15:57 +04:00
|
|
|
aa.scrdata = &mach64_screenlist;
|
|
|
|
aa.accessops = &mach64_accessops;
|
2006-04-13 00:35:42 +04:00
|
|
|
aa.accesscookie = &sc->vd;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
config_found(self, &aa, wsemuldisplaydevprint);
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2006-04-13 00:35:42 +04:00
|
|
|
mach64_init_screen(void *cookie, struct vcons_screen *scr, int existing,
|
2006-11-16 04:32:37 +03:00
|
|
|
long *defattr)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct mach64_softc *sc = cookie;
|
|
|
|
struct rasops_info *ri = &scr->scr_ri;
|
|
|
|
|
|
|
|
/* XXX for now */
|
|
|
|
#define setmode 0
|
|
|
|
|
2005-02-25 19:00:58 +03:00
|
|
|
ri->ri_depth = sc->bits_per_pixel;
|
2005-09-21 22:49:16 +04:00
|
|
|
ri->ri_width = sc->sc_my_mode->hdisplay;
|
|
|
|
ri->ri_height = sc->sc_my_mode->vdisplay;
|
2005-02-25 19:00:58 +03:00
|
|
|
ri->ri_stride = ri->ri_width;
|
|
|
|
ri->ri_flg = RI_CENTER;
|
2006-04-19 21:41:24 +04:00
|
|
|
set_address(ri, sc->sc_aperture);
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
if (existing) {
|
2005-05-02 20:02:43 +04:00
|
|
|
ri->ri_flg |= RI_CLEAR;
|
2006-04-13 00:35:42 +04:00
|
|
|
if (setmode && mach64_set_screentype(sc, scr->scr_type)) {
|
2002-10-24 22:15:57 +04:00
|
|
|
panic("%s: failed to switch video mode",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
}
|
2006-04-13 00:35:42 +04:00
|
|
|
|
|
|
|
rasops_init(ri, sc->sc_my_mode->vdisplay/8,
|
|
|
|
sc->sc_my_mode->hdisplay/8);
|
|
|
|
ri->ri_caps = WSSCREEN_WSCOLORS;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
rasops_reconfig(ri, sc->sc_my_mode->vdisplay / ri->ri_font->fontheight,
|
|
|
|
sc->sc_my_mode->hdisplay / ri->ri_font->fontwidth);
|
|
|
|
|
|
|
|
/* enable acceleration */
|
|
|
|
ri->ri_hw = scr;
|
|
|
|
ri->ri_ops.copyrows = mach64_copyrows;
|
|
|
|
ri->ri_ops.copycols = mach64_copycols;
|
|
|
|
ri->ri_ops.eraserows = mach64_eraserows;
|
|
|
|
ri->ri_ops.erasecols = mach64_erasecols;
|
|
|
|
ri->ri_ops.cursor = mach64_cursor;
|
|
|
|
ri->ri_ops.putchar = mach64_putchar;
|
|
|
|
ri->ri_ops.allocattr = mach64_allocattr;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-25 22:03:03 +04:00
|
|
|
mach64_init(struct mach64_softc *sc)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
uint32_t *p32, saved_value;
|
|
|
|
uint8_t *p;
|
2002-11-26 00:24:28 +03:00
|
|
|
int need_swap;
|
2002-10-25 22:57:06 +04:00
|
|
|
|
2002-10-25 22:03:03 +04:00
|
|
|
if (bus_space_map(sc->sc_memt, sc->sc_aperbase, sc->sc_apersize,
|
2002-10-24 22:15:57 +04:00
|
|
|
BUS_SPACE_MAP_LINEAR, &sc->sc_memh)) {
|
|
|
|
panic("%s: failed to map aperture", sc->sc_dev.dv_xname);
|
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
sc->sc_aperture = (void *)bus_space_vaddr(sc->sc_memt, sc->sc_memh);
|
2002-10-25 22:57:06 +04:00
|
|
|
|
|
|
|
sc->sc_regt = sc->sc_memt;
|
|
|
|
bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
|
|
|
|
sc->sc_regsize, &sc->sc_regh);
|
2007-03-04 08:59:00 +03:00
|
|
|
sc->sc_registers = (char *)sc->sc_aperture + 0x7ffc00;
|
2002-10-25 22:57:06 +04:00
|
|
|
|
2002-11-26 00:24:28 +03:00
|
|
|
/*
|
|
|
|
* Test wether the aperture is byte swapped or not
|
|
|
|
*/
|
2006-04-19 21:41:24 +04:00
|
|
|
p32 = (uint32_t*)sc->sc_aperture;
|
2002-11-26 00:24:28 +03:00
|
|
|
saved_value = *p32;
|
2006-04-19 21:41:24 +04:00
|
|
|
p = (uint8_t*)(u_long)sc->sc_aperture;
|
2002-11-26 00:24:28 +03:00
|
|
|
*p32 = 0x12345678;
|
|
|
|
if (p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)
|
|
|
|
need_swap = 0;
|
|
|
|
else
|
|
|
|
need_swap = 1;
|
|
|
|
if (need_swap) {
|
2007-03-04 08:59:00 +03:00
|
|
|
sc->sc_aperture = (char *)sc->sc_aperture + 0x800000;
|
2002-11-26 00:24:28 +03:00
|
|
|
sc->sc_aperbase += 0x800000;
|
|
|
|
sc->sc_apersize -= 0x800000;
|
|
|
|
}
|
|
|
|
*p32 = saved_value;
|
2006-04-13 00:35:42 +04:00
|
|
|
|
|
|
|
sc->sc_blanked = 0;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_get_memsize(struct mach64_softc *sc)
|
|
|
|
{
|
|
|
|
int tmp, memsize;
|
|
|
|
int mem_tab[] = {
|
|
|
|
512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
|
|
|
|
};
|
|
|
|
tmp = regr(sc, MEM_CNTL);
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2005-12-18 22:21:12 +03:00
|
|
|
printf("%s: memctl %08x\n", sc->sc_dev.dv_xname, tmp);
|
2006-04-13 00:35:42 +04:00
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
if (sc->has_dsp) {
|
|
|
|
tmp &= 0x0000000f;
|
|
|
|
if (tmp < 8)
|
|
|
|
memsize = (tmp + 1) * 512;
|
|
|
|
else if (tmp < 12)
|
|
|
|
memsize = (tmp - 3) * 1024;
|
|
|
|
else
|
|
|
|
memsize = (tmp - 7) * 2048;
|
|
|
|
} else {
|
|
|
|
memsize = mem_tab[tmp & 0x07];
|
|
|
|
}
|
|
|
|
|
|
|
|
return memsize;
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_get_max_ramdac(struct mach64_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
|
|
|
|
(mach64_chip_rev & 0x07))
|
|
|
|
return 170000;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
|
|
|
|
if (mach64_chip_id == mach64_info[i].chip_id)
|
|
|
|
return mach64_info[i].ramdac_freq;
|
|
|
|
|
|
|
|
if (sc->bits_per_pixel == 8)
|
|
|
|
return 135000;
|
|
|
|
else
|
|
|
|
return 80000;
|
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#if defined(__sparc__) || defined(__powerpc__)
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_get_mode(struct mach64_softc *sc, struct videomode *mode)
|
|
|
|
{
|
|
|
|
struct mach64_crtcregs crtc;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
crtc.h_total_disp = regr(sc, CRTC_H_TOTAL_DISP);
|
|
|
|
crtc.h_sync_strt_wid = regr(sc, CRTC_H_SYNC_STRT_WID);
|
|
|
|
crtc.v_total_disp = regr(sc, CRTC_V_TOTAL_DISP);
|
|
|
|
crtc.v_sync_strt_wid = regr(sc, CRTC_V_SYNC_STRT_WID);
|
|
|
|
|
|
|
|
mode->htotal = ((crtc.h_total_disp & 0xffff) + 1) << 3;
|
|
|
|
mode->hdisplay = ((crtc.h_total_disp >> 16) + 1) << 3;
|
|
|
|
mode->hsync_start = ((crtc.h_sync_strt_wid & 0xffff) + 1) << 3;
|
|
|
|
mode->hsync_end = ((crtc.h_sync_strt_wid >> 16) << 3) +
|
|
|
|
mode->hsync_start;
|
|
|
|
mode->vtotal = (crtc.v_total_disp & 0xffff) + 1;
|
|
|
|
mode->vdisplay = (crtc.v_total_disp >> 16) + 1;
|
|
|
|
mode->vsync_start = (crtc.v_sync_strt_wid & 0xffff) + 1;
|
|
|
|
mode->vsync_end = (crtc.v_sync_strt_wid >> 16) + mode->vsync_start;
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifndef DEBUG_MACHFB
|
2002-10-24 22:15:57 +04:00
|
|
|
printf("mach64_get_mode: %d %d %d %d %d %d %d %d\n",
|
|
|
|
mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
|
|
|
|
mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal);
|
|
|
|
#endif
|
|
|
|
}
|
2005-10-03 15:22:06 +04:00
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_calc_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc,
|
|
|
|
struct videomode *mode)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mode->dot_clock > sc->ramdac_freq)
|
|
|
|
/* Clock too high. */
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
crtc->h_total_disp = (((mode->hdisplay >> 3) - 1) << 16) |
|
|
|
|
((mode->htotal >> 3) - 1);
|
2005-02-27 03:26:58 +03:00
|
|
|
crtc->h_sync_strt_wid =
|
2002-10-24 22:15:57 +04:00
|
|
|
(((mode->hsync_end - mode->hsync_start) >> 3) << 16) |
|
|
|
|
((mode->hsync_start >> 3) - 1);
|
|
|
|
|
|
|
|
crtc->v_total_disp = ((mode->vdisplay - 1) << 16) |
|
|
|
|
(mode->vtotal - 1);
|
|
|
|
crtc->v_sync_strt_wid =
|
|
|
|
((mode->vsync_end - mode->vsync_start) << 16) |
|
|
|
|
(mode->vsync_start - 1);
|
|
|
|
|
|
|
|
if (mode->flags & VID_NVSYNC)
|
|
|
|
crtc->v_sync_strt_wid |= CRTC_VSYNC_NEG;
|
|
|
|
|
|
|
|
switch (sc->bits_per_pixel) {
|
|
|
|
case 8:
|
|
|
|
crtc->color_depth = CRTC_PIX_WIDTH_8BPP;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
crtc->color_depth = CRTC_PIX_WIDTH_16BPP;
|
2005-02-27 03:26:58 +03:00
|
|
|
break;
|
2002-10-24 22:15:57 +04:00
|
|
|
case 32:
|
|
|
|
crtc->color_depth = CRTC_PIX_WIDTH_32BPP;
|
2005-02-27 03:26:58 +03:00
|
|
|
break;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
crtc->gen_cntl = 0;
|
|
|
|
if (mode->flags & VID_INTERLACE)
|
|
|
|
crtc->gen_cntl |= CRTC_INTERLACE_EN;
|
2006-04-13 00:35:42 +04:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
if (mode->flags & VID_CSYNC)
|
|
|
|
crtc->gen_cntl |= CRTC_CSYNC_EN;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
crtc->dot_clock = mode->dot_clock;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_set_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc)
|
|
|
|
{
|
|
|
|
|
|
|
|
mach64_set_pll(sc, crtc->dot_clock);
|
|
|
|
|
|
|
|
if (sc->has_dsp)
|
|
|
|
mach64_set_dsp(sc);
|
|
|
|
|
|
|
|
regw(sc, CRTC_H_TOTAL_DISP, crtc->h_total_disp);
|
|
|
|
regw(sc, CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid);
|
|
|
|
regw(sc, CRTC_V_TOTAL_DISP, crtc->v_total_disp);
|
|
|
|
regw(sc, CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
regw(sc, CRTC_VLINE_CRNT_VLINE, 0);
|
|
|
|
|
|
|
|
regw(sc, CRTC_OFF_PITCH, (sc->virt_x >> 3) << 22);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
regw(sc, CRTC_GEN_CNTL, crtc->gen_cntl | crtc->color_depth |
|
2006-04-13 00:35:42 +04:00
|
|
|
/* XXX this unconditionally enables composite sync on SPARC */
|
|
|
|
#ifdef __sparc__
|
|
|
|
CRTC_CSYNC_EN |
|
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
CRTC_EXT_DISP_EN | CRTC_EXT_EN);
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_modeswitch(struct mach64_softc *sc, struct videomode *mode)
|
|
|
|
{
|
|
|
|
struct mach64_crtcregs crtc;
|
|
|
|
|
2006-05-11 01:53:14 +04:00
|
|
|
memset(&crtc, 0, sizeof crtc); /* XXX gcc */
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
if (mach64_calc_crtcregs(sc, &crtc, mode))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
mach64_set_crtcregs(sc, &crtc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_reset_engine(struct mach64_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Reset engine.*/
|
|
|
|
regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
|
|
|
|
|
|
|
|
/* Enable engine. */
|
|
|
|
regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
|
|
|
|
|
|
|
|
/* Ensure engine is not locked up by clearing any FIFO or
|
|
|
|
host errors. */
|
|
|
|
regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
|
|
|
|
BUS_FIFO_ERR_ACK);
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_init_engine(struct mach64_softc *sc)
|
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
uint32_t pitch_value;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
pitch_value = sc->virt_x;
|
|
|
|
|
|
|
|
if (sc->bits_per_pixel == 24)
|
|
|
|
pitch_value *= 3;
|
|
|
|
|
|
|
|
mach64_reset_engine(sc);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
wait_for_fifo(sc, 14);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
regw(sc, CONTEXT_MASK, 0xffffffff);
|
|
|
|
|
|
|
|
regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
|
|
|
|
|
|
|
|
regw(sc, DST_Y_X, 0);
|
|
|
|
regw(sc, DST_HEIGHT, 0);
|
|
|
|
regw(sc, DST_BRES_ERR, 0);
|
|
|
|
regw(sc, DST_BRES_INC, 0);
|
|
|
|
regw(sc, DST_BRES_DEC, 0);
|
|
|
|
|
|
|
|
regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
|
|
|
|
DST_Y_TOP_TO_BOTTOM);
|
|
|
|
|
|
|
|
regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
|
|
|
|
|
|
|
|
regw(sc, SRC_Y_X, 0);
|
|
|
|
regw(sc, SRC_HEIGHT1_WIDTH1, 1);
|
|
|
|
regw(sc, SRC_Y_X_START, 0);
|
|
|
|
regw(sc, SRC_HEIGHT2_WIDTH2, 1);
|
|
|
|
|
|
|
|
regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
|
|
|
|
|
|
|
|
wait_for_fifo(sc, 13);
|
|
|
|
regw(sc, HOST_CNTL, 0);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
regw(sc, PAT_REG0, 0);
|
|
|
|
regw(sc, PAT_REG1, 0);
|
|
|
|
regw(sc, PAT_CNTL, 0);
|
|
|
|
|
|
|
|
regw(sc, SC_LEFT, 0);
|
|
|
|
regw(sc, SC_TOP, 0);
|
2005-09-21 22:49:16 +04:00
|
|
|
regw(sc, SC_BOTTOM, sc->sc_my_mode->vdisplay - 1);
|
2002-10-24 22:15:57 +04:00
|
|
|
regw(sc, SC_RIGHT, pitch_value - 1);
|
|
|
|
|
|
|
|
regw(sc, DP_BKGD_CLR, 0);
|
|
|
|
regw(sc, DP_FRGD_CLR, 0xffffffff);
|
|
|
|
regw(sc, DP_WRITE_MASK, 0xffffffff);
|
|
|
|
regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
|
|
|
|
|
|
|
|
regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
|
|
|
|
|
|
|
|
wait_for_fifo(sc, 3);
|
|
|
|
regw(sc, CLR_CMP_CLR, 0);
|
|
|
|
regw(sc, CLR_CMP_MASK, 0xffffffff);
|
|
|
|
regw(sc, CLR_CMP_CNTL, 0);
|
|
|
|
|
|
|
|
wait_for_fifo(sc, 2);
|
|
|
|
switch (sc->bits_per_pixel) {
|
|
|
|
case 8:
|
|
|
|
regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
|
|
|
|
regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
|
2005-05-02 18:49:08 +04:00
|
|
|
/* We want 8 bit per channel */
|
2005-01-09 19:29:20 +03:00
|
|
|
regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
|
2002-10-24 22:15:57 +04:00
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case 32:
|
|
|
|
regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
|
|
|
|
regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
|
|
|
|
regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_fifo(sc, 5);
|
|
|
|
regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
|
|
|
|
regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
|
|
|
|
|
|
|
|
wait_for_idle(sc);
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
#if 0
|
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_adjust_frame(struct mach64_softc *sc, int x, int y)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
offset = ((x + y * sc->virt_x) * (sc->bits_per_pixel >> 3)) >> 3;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
|
|
|
|
offset);
|
|
|
|
}
|
2005-07-07 22:43:47 +04:00
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_set_dsp(struct mach64_softc *sc)
|
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
uint32_t fifo_depth, page_size, dsp_precision, dsp_loop_latency;
|
|
|
|
uint32_t dsp_off, dsp_on, dsp_xclks_per_qw;
|
|
|
|
uint32_t xclks_per_qw, y;
|
|
|
|
uint32_t fifo_off, fifo_on;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-12-18 22:21:12 +03:00
|
|
|
printf("%s: initializing the DSP\n", sc->sc_dev.dv_xname);
|
2002-10-24 22:15:57 +04:00
|
|
|
if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
|
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II ||
|
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIP ||
|
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_PCI ||
|
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_B ||
|
|
|
|
mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_P) {
|
|
|
|
dsp_loop_latency = 0;
|
|
|
|
fifo_depth = 24;
|
|
|
|
} else {
|
|
|
|
dsp_loop_latency = 2;
|
|
|
|
fifo_depth = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsp_precision = 0;
|
|
|
|
xclks_per_qw = (sc->mclk_fb_div * sc->vclk_post_div * 64 << 11) /
|
|
|
|
(sc->vclk_fb_div * sc->mclk_post_div * sc->bits_per_pixel);
|
|
|
|
y = (xclks_per_qw * fifo_depth) >> 11;
|
|
|
|
while (y) {
|
|
|
|
y >>= 1;
|
|
|
|
dsp_precision++;
|
|
|
|
}
|
|
|
|
dsp_precision -= 5;
|
|
|
|
fifo_off = ((xclks_per_qw * (fifo_depth - 1)) >> 5) + (3 << 6);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
switch (sc->memtype) {
|
|
|
|
case DRAM:
|
|
|
|
case EDO_DRAM:
|
|
|
|
case PSEUDO_EDO:
|
|
|
|
if (sc->memsize > 1024) {
|
|
|
|
page_size = 9;
|
|
|
|
dsp_loop_latency += 6;
|
|
|
|
} else {
|
|
|
|
page_size = 10;
|
|
|
|
if (sc->memtype == DRAM)
|
|
|
|
dsp_loop_latency += 8;
|
|
|
|
else
|
|
|
|
dsp_loop_latency += 7;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDRAM:
|
|
|
|
case SGRAM:
|
|
|
|
if (sc->memsize > 1024) {
|
|
|
|
page_size = 8;
|
|
|
|
dsp_loop_latency += 8;
|
|
|
|
} else {
|
2005-02-27 03:26:58 +03:00
|
|
|
page_size = 10;
|
2002-10-24 22:15:57 +04:00
|
|
|
dsp_loop_latency += 9;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
page_size = 10;
|
|
|
|
dsp_loop_latency += 9;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xclks_per_qw >= (page_size << 11))
|
|
|
|
fifo_on = ((2 * page_size + 1) << 6) + (xclks_per_qw >> 5);
|
|
|
|
else
|
|
|
|
fifo_on = (3 * page_size + 2) << 6;
|
|
|
|
|
|
|
|
dsp_xclks_per_qw = xclks_per_qw >> dsp_precision;
|
|
|
|
dsp_on = fifo_on >> dsp_precision;
|
|
|
|
dsp_off = fifo_off >> dsp_precision;
|
|
|
|
|
2005-02-25 19:00:58 +03:00
|
|
|
#ifdef DEBUG_MACHFB
|
2002-10-24 22:15:57 +04:00
|
|
|
printf("dsp_xclks_per_qw = %d, dsp_on = %d, dsp_off = %d,\n"
|
|
|
|
"dsp_precision = %d, dsp_loop_latency = %d,\n"
|
|
|
|
"mclk_fb_div = %d, vclk_fb_div = %d,\n"
|
|
|
|
"mclk_post_div = %d, vclk_post_div = %d\n",
|
|
|
|
dsp_xclks_per_qw, dsp_on, dsp_off, dsp_precision, dsp_loop_latency,
|
|
|
|
sc->mclk_fb_div, sc->vclk_fb_div,
|
|
|
|
sc->mclk_post_div, sc->vclk_post_div);
|
2005-02-27 03:26:58 +03:00
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
|
|
|
|
regw(sc, DSP_ON_OFF, ((dsp_on << 16) & DSP_ON) | (dsp_off & DSP_OFF));
|
|
|
|
regw(sc, DSP_CONFIG, ((dsp_precision << 20) & DSP_PRECISION) |
|
2005-02-27 03:26:58 +03:00
|
|
|
((dsp_loop_latency << 16) & DSP_LOOP_LATENCY) |
|
2002-10-24 22:15:57 +04:00
|
|
|
(dsp_xclks_per_qw & DSP_XCLKS_PER_QW));
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_set_pll(struct mach64_softc *sc, int clock)
|
|
|
|
{
|
|
|
|
int q;
|
|
|
|
|
|
|
|
q = (clock * sc->ref_div * 100) / (2 * sc->ref_freq);
|
2005-02-25 19:00:58 +03:00
|
|
|
#ifdef DEBUG_MACHFB
|
2002-10-24 22:15:57 +04:00
|
|
|
printf("q = %d\n", q);
|
|
|
|
#endif
|
|
|
|
if (q > 25500) {
|
|
|
|
printf("Warning: q > 25500\n");
|
|
|
|
q = 25500;
|
|
|
|
sc->vclk_post_div = 1;
|
|
|
|
sc->log2_vclk_post_div = 0;
|
|
|
|
} else if (q > 12750) {
|
|
|
|
sc->vclk_post_div = 1;
|
|
|
|
sc->log2_vclk_post_div = 0;
|
|
|
|
} else if (q > 6350) {
|
|
|
|
sc->vclk_post_div = 2;
|
|
|
|
sc->log2_vclk_post_div = 1;
|
|
|
|
} else if (q > 3150) {
|
|
|
|
sc->vclk_post_div = 4;
|
|
|
|
sc->log2_vclk_post_div = 2;
|
|
|
|
} else if (q >= 1600) {
|
|
|
|
sc->vclk_post_div = 8;
|
|
|
|
sc->log2_vclk_post_div = 3;
|
|
|
|
} else {
|
2005-02-27 03:26:58 +03:00
|
|
|
printf("Warning: q < 1600\n");
|
2002-10-24 22:15:57 +04:00
|
|
|
sc->vclk_post_div = 8;
|
|
|
|
sc->log2_vclk_post_div = 3;
|
|
|
|
}
|
|
|
|
sc->vclk_fb_div = q * sc->vclk_post_div / 100;
|
|
|
|
|
|
|
|
regwb_pll(sc, MCLK_FB_DIV, sc->mclk_fb_div);
|
|
|
|
regwb_pll(sc, VCLK_POST_DIV, sc->log2_vclk_post_div);
|
|
|
|
regwb_pll(sc, VCLK0_FB_DIV, sc->vclk_fb_div);
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_init_lut(struct mach64_softc *sc)
|
|
|
|
{
|
2005-06-01 01:16:06 +04:00
|
|
|
int i, idx;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
mach64_putpalreg(sc, i, rasops_cmap[idx], rasops_cmap[idx + 1],
|
|
|
|
rasops_cmap[idx + 2]);
|
|
|
|
idx += 3;
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
2005-05-02 15:22:31 +04:00
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_putpalreg(struct mach64_softc *sc, uint8_t index, uint8_t r, uint8_t g,
|
|
|
|
uint8_t b)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
sc->sc_cmap_red[index] = r;
|
|
|
|
sc->sc_cmap_green[index] = g;
|
|
|
|
sc->sc_cmap_blue[index] = b;
|
2005-05-02 18:49:08 +04:00
|
|
|
/*
|
|
|
|
* writing the dac index takes a while, in theory we can poll some
|
|
|
|
* register to see when it's ready - but we better avoid writing it
|
|
|
|
* unnecessarily
|
|
|
|
*/
|
2005-06-01 01:16:06 +04:00
|
|
|
if (index != sc->sc_dacw) {
|
2005-01-09 19:29:20 +03:00
|
|
|
regwb(sc, DAC_MASK, 0xff);
|
|
|
|
regwb(sc, DAC_WINDEX, index);
|
|
|
|
}
|
2005-05-02 20:02:43 +04:00
|
|
|
sc->sc_dacw = index + 1;
|
2005-01-09 19:29:20 +03:00
|
|
|
regwb(sc, DAC_DATA, r);
|
|
|
|
regwb(sc, DAC_DATA, g);
|
|
|
|
regwb(sc, DAC_DATA, b);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2005-02-25 19:00:58 +03:00
|
|
|
mach64_putcmap(struct mach64_softc *sc, struct wsdisplay_cmap *cm)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
uint index = cm->index;
|
|
|
|
uint count = cm->count;
|
2005-01-09 19:29:20 +03:00
|
|
|
int i, error;
|
2006-04-13 00:35:42 +04:00
|
|
|
uint8_t rbuf[256], gbuf[256], bbuf[256];
|
|
|
|
uint8_t *r, *g, *b;
|
2005-01-09 19:29:20 +03:00
|
|
|
|
|
|
|
if (cm->index >= 256 || cm->count > 256 ||
|
|
|
|
(cm->index + cm->count) > 256)
|
|
|
|
return EINVAL;
|
|
|
|
error = copyin(cm->red, &rbuf[index], count);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = copyin(cm->green, &gbuf[index], count);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = copyin(cm->blue, &bbuf[index], count);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
|
|
|
|
memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
|
|
|
|
memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
|
|
|
|
|
|
|
|
r = &sc->sc_cmap_red[index];
|
|
|
|
g = &sc->sc_cmap_green[index];
|
|
|
|
b = &sc->sc_cmap_blue[index];
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
for (i = 0; i < count; i++) {
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_putpalreg(sc, index, *r, *g, *b);
|
2005-01-09 19:29:20 +03:00
|
|
|
index++;
|
|
|
|
r++, g++, b++;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
2005-01-09 19:29:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2005-02-25 19:00:58 +03:00
|
|
|
mach64_getcmap(struct mach64_softc *sc, struct wsdisplay_cmap *cm)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
|
|
|
u_int index = cm->index;
|
|
|
|
u_int count = cm->count;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (index >= 255 || count > 256 || index + count > 256)
|
|
|
|
return EINVAL;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
error = copyout(&sc->sc_cmap_red[index], cm->red, count);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = copyout(&sc->sc_cmap_green[index], cm->green, count);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return 0;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_set_screentype(struct mach64_softc *sc, const struct wsscreen_descr *des)
|
|
|
|
{
|
2002-10-29 20:54:40 +03:00
|
|
|
struct mach64_crtcregs regs;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2002-10-29 20:54:40 +03:00
|
|
|
if (mach64_calc_crtcregs(sc, ®s,
|
|
|
|
(struct videomode *)des->modecookie))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
mach64_set_crtcregs(sc, ®s);
|
|
|
|
return 0;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mach64_is_console(struct pci_attach_args *pa)
|
2002-10-29 16:50:11 +03:00
|
|
|
{
|
|
|
|
#ifdef __sparc__
|
|
|
|
int node;
|
|
|
|
|
|
|
|
node = PCITAG_NODE(pa->pa_tag);
|
|
|
|
if (node == -1)
|
|
|
|
return 0;
|
|
|
|
|
2004-03-22 13:06:31 +03:00
|
|
|
return (node == prom_instance_to_package(prom_stdout()));
|
2005-01-18 01:52:46 +03:00
|
|
|
#elif defined(__powerpc__)
|
|
|
|
/* check if we're the /chosen console device */
|
|
|
|
int chosen, stdout, node, us;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
|
|
|
us = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
|
2005-01-18 01:52:46 +03:00
|
|
|
chosen = OF_finddevice("/chosen");
|
|
|
|
OF_getprop(chosen, "stdout", &stdout, 4);
|
|
|
|
node = OF_instance_to_package(stdout);
|
2005-05-02 20:02:43 +04:00
|
|
|
return (us == node);
|
2002-10-29 16:50:11 +03:00
|
|
|
#else
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
/*
|
|
|
|
* wsdisplay_emulops
|
|
|
|
*/
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_cursor(void *cookie, int on, int row, int col)
|
|
|
|
{
|
2005-06-01 01:16:06 +04:00
|
|
|
struct rasops_info *ri = cookie;
|
2006-04-13 00:35:42 +04:00
|
|
|
struct vcons_screen *scr = ri->ri_hw;
|
|
|
|
struct mach64_softc *sc = scr->scr_cookie;
|
|
|
|
int x, y, wi, he;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
|
|
|
wi = ri->ri_font->fontwidth;
|
|
|
|
he = ri->ri_font->fontheight;
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
if ((!sc->sc_locked) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
|
|
|
|
x = ri->ri_ccol * wi + ri->ri_xorigin;
|
|
|
|
y = ri->ri_crow * he + ri->ri_yorigin;
|
|
|
|
if (ri->ri_flg & RI_CURSOR) {
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_bitblt(sc, x, y, x, y, wi, he, MIX_NOT_SRC,
|
|
|
|
0xff);
|
2006-04-13 00:35:42 +04:00
|
|
|
ri->ri_flg &= ~RI_CURSOR;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2006-04-13 00:35:42 +04:00
|
|
|
ri->ri_crow = row;
|
|
|
|
ri->ri_ccol = col;
|
|
|
|
if (on) {
|
|
|
|
x = ri->ri_ccol * wi + ri->ri_xorigin;
|
|
|
|
y = ri->ri_crow * he + ri->ri_yorigin;
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_bitblt(sc, x, y, x, y, wi, he, MIX_NOT_SRC,
|
|
|
|
0xff);
|
2006-04-13 00:35:42 +04:00
|
|
|
ri->ri_flg |= RI_CURSOR;;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
} else {
|
2006-04-13 00:35:42 +04:00
|
|
|
scr->scr_ri.ri_crow = row;
|
|
|
|
scr->scr_ri.ri_ccol = col;
|
|
|
|
scr->scr_ri.ri_flg &= ~RI_CURSOR;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2002-10-31 17:10:07 +03:00
|
|
|
#if 0
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_mapchar(void *cookie, int uni, u_int *index)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
#endif
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_putchar(void *cookie, int row, int col, u_int c, long attr)
|
|
|
|
{
|
2005-06-01 01:16:06 +04:00
|
|
|
struct rasops_info *ri = cookie;
|
2006-04-13 00:35:42 +04:00
|
|
|
struct vcons_screen *scr = ri->ri_hw;
|
|
|
|
struct mach64_softc *sc = scr->scr_cookie;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
|
2005-05-02 20:02:43 +04:00
|
|
|
int fg, bg, uc;
|
2005-02-25 19:00:58 +03:00
|
|
|
uint8_t *data;
|
2005-05-02 20:02:43 +04:00
|
|
|
int x, y, wi, he;
|
|
|
|
wi = ri->ri_font->fontwidth;
|
|
|
|
he = ri->ri_font->fontheight;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-02-25 19:00:58 +03:00
|
|
|
if (!CHAR_IN_FONT(c, ri->ri_font))
|
|
|
|
return;
|
|
|
|
bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
|
|
|
|
fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
|
2005-05-02 20:02:43 +04:00
|
|
|
x = ri->ri_xorigin + col * wi;
|
|
|
|
y = ri->ri_yorigin + row * he;
|
|
|
|
if (c == 0x20) {
|
|
|
|
mach64_rectfill(sc, x, y, wi, he, bg);
|
2005-02-25 19:00:58 +03:00
|
|
|
} else {
|
|
|
|
uc = c-ri->ri_font->firstchar;
|
2005-05-02 18:49:08 +04:00
|
|
|
data = (uint8_t *)ri->ri_font->data + uc *
|
|
|
|
ri->ri_fontscale;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_setup_mono(sc, x, y, wi, he, fg, bg);
|
|
|
|
mach64_feed_bytes(sc, ri->ri_fontscale, data);
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
|
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct rasops_info *ri = cookie;
|
|
|
|
struct vcons_screen *scr = ri->ri_hw;
|
|
|
|
struct mach64_softc *sc = scr->scr_cookie;
|
|
|
|
int32_t xs, xd, y, width, height;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
|
2005-05-02 20:02:43 +04:00
|
|
|
xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
|
|
|
|
xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
|
|
|
|
y = ri->ri_yorigin + ri->ri_font->fontheight * row;
|
|
|
|
width = ri->ri_font->fontwidth * ncols;
|
|
|
|
height = ri->ri_font->fontheight;
|
|
|
|
mach64_bitblt(sc, xs, y, xd, y, width, height, MIX_SRC, 0xff);
|
2005-05-02 15:22:31 +04:00
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
|
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct rasops_info *ri = cookie;
|
|
|
|
struct vcons_screen *scr = ri->ri_hw;
|
|
|
|
struct mach64_softc *sc = scr->scr_cookie;
|
2005-05-02 20:02:43 +04:00
|
|
|
int32_t x, y, width, height, fg, bg, ul;
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
|
2005-05-02 20:02:43 +04:00
|
|
|
x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
|
|
|
|
y = ri->ri_yorigin + ri->ri_font->fontheight * row;
|
|
|
|
width = ri->ri_font->fontwidth * ncols;
|
|
|
|
height = ri->ri_font->fontheight;
|
|
|
|
rasops_unpack_attr(fillattr, &fg, &bg, &ul);
|
|
|
|
|
|
|
|
mach64_rectfill(sc, x, y, width, height, bg);
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2002-10-24 22:15:57 +04:00
|
|
|
mach64_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
|
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct rasops_info *ri = cookie;
|
|
|
|
struct vcons_screen *scr = ri->ri_hw;
|
|
|
|
struct mach64_softc *sc = scr->scr_cookie;
|
2005-05-02 18:49:08 +04:00
|
|
|
int32_t x, ys, yd, width, height;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
|
2005-05-02 20:02:43 +04:00
|
|
|
x = ri->ri_xorigin;
|
|
|
|
ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
|
|
|
|
yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
|
|
|
|
width = ri->ri_emuwidth;
|
|
|
|
height = ri->ri_font->fontheight*nrows;
|
|
|
|
mach64_bitblt(sc, x, ys, x, yd, width, height, MIX_SRC, 0xff);
|
2005-05-02 15:22:31 +04:00
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2005-02-25 19:00:58 +03:00
|
|
|
mach64_eraserows(void *cookie, int row, int nrows, long fillattr)
|
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct rasops_info *ri = cookie;
|
|
|
|
struct vcons_screen *scr = ri->ri_hw;
|
|
|
|
struct mach64_softc *sc = scr->scr_cookie;
|
2005-10-01 23:01:01 +04:00
|
|
|
int32_t x, y, width, height, fg, bg, ul;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
|
2005-05-02 20:02:43 +04:00
|
|
|
x = ri->ri_xorigin;
|
|
|
|
y = ri->ri_yorigin + ri->ri_font->fontheight * row;
|
|
|
|
width = ri->ri_emuwidth;
|
|
|
|
height = ri->ri_font->fontheight * nrows;
|
|
|
|
rasops_unpack_attr(fillattr, &fg, &bg, &ul);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_rectfill(sc, x, y, width, height, bg);
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2005-02-27 03:26:58 +03:00
|
|
|
mach64_bitblt(struct mach64_softc *sc, int xs, int ys, int xd, int yd, int width, int height, int rop, int mask)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
uint32_t dest_ctl = 0;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
wait_for_idle(sc);
|
2005-05-02 20:02:43 +04:00
|
|
|
regw(sc, DP_WRITE_MASK, mask); /* XXX only good for 8 bit */
|
|
|
|
regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
|
|
|
|
regw(sc, DP_SRC, FRGD_SRC_BLIT);
|
|
|
|
regw(sc, DP_MIX, (rop & 0xffff) << 16);
|
|
|
|
regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
|
|
|
|
if (yd < ys) {
|
|
|
|
dest_ctl = DST_Y_TOP_TO_BOTTOM;
|
2005-01-09 19:29:20 +03:00
|
|
|
} else {
|
2005-05-02 20:02:43 +04:00
|
|
|
ys += height - 1;
|
|
|
|
yd += height - 1;
|
|
|
|
dest_ctl = DST_Y_BOTTOM_TO_TOP;
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
2005-05-02 20:02:43 +04:00
|
|
|
if (xd < xs) {
|
|
|
|
dest_ctl |= DST_X_LEFT_TO_RIGHT;
|
|
|
|
regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
|
2005-01-09 19:29:20 +03:00
|
|
|
} else {
|
2005-05-02 20:02:43 +04:00
|
|
|
dest_ctl |= DST_X_RIGHT_TO_LEFT;
|
|
|
|
xs += width - 1;
|
|
|
|
xd += width - 1;
|
|
|
|
regw(sc, SRC_CNTL, SRC_LINE_X_RIGHT_TO_LEFT);
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
2005-05-02 20:02:43 +04:00
|
|
|
regw(sc, DST_CNTL, dest_ctl);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-05-02 20:02:43 +04:00
|
|
|
regw(sc, SRC_Y_X, (xs << 16) | ys);
|
|
|
|
regw(sc, SRC_WIDTH1, width);
|
|
|
|
regw(sc, DST_Y_X, (xd << 16) | yd);
|
|
|
|
regw(sc, DST_HEIGHT_WIDTH, (width << 16) | height);
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2005-05-02 18:49:08 +04:00
|
|
|
mach64_setup_mono(struct mach64_softc *sc, int xd, int yd, int width,
|
|
|
|
int height, uint32_t fg, uint32_t bg)
|
2005-02-25 19:00:58 +03:00
|
|
|
{
|
2005-02-27 03:26:58 +03:00
|
|
|
wait_for_idle(sc);
|
2005-05-02 20:02:43 +04:00
|
|
|
regw(sc, DP_WRITE_MASK, 0xff); /* XXX only good for 8 bit */
|
|
|
|
regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_1BPP | HOST_1BPP);
|
|
|
|
regw(sc, DP_SRC, MONO_SRC_HOST | BKGD_SRC_BKGD_CLR | FRGD_SRC_FRGD_CLR);
|
|
|
|
regw(sc, DP_MIX, ((MIX_SRC & 0xffff) << 16) | MIX_SRC);
|
|
|
|
regw(sc, CLR_CMP_CNTL ,0); /* no transparency */
|
|
|
|
regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
|
|
|
|
regw(sc, DST_CNTL, DST_Y_TOP_TO_BOTTOM | DST_X_LEFT_TO_RIGHT);
|
|
|
|
regw(sc, HOST_CNTL, HOST_BYTE_ALIGN);
|
|
|
|
regw(sc, DP_BKGD_CLR, bg);
|
|
|
|
regw(sc, DP_FRGD_CLR, fg);
|
|
|
|
regw(sc, SRC_Y_X, 0);
|
|
|
|
regw(sc, SRC_WIDTH1, width);
|
|
|
|
regw(sc, DST_Y_X, (xd << 16) | yd);
|
|
|
|
regw(sc, DST_HEIGHT_WIDTH, (width << 16) | height);
|
2005-02-25 19:00:58 +03:00
|
|
|
/* now feed the data into the chip */
|
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2005-02-25 19:00:58 +03:00
|
|
|
mach64_feed_bytes(struct mach64_softc *sc, int count, uint8_t *data)
|
|
|
|
{
|
|
|
|
int i;
|
2005-05-02 20:02:43 +04:00
|
|
|
uint32_t latch = 0, bork;
|
|
|
|
int shift = 0;
|
|
|
|
int reg = 0;
|
|
|
|
|
|
|
|
for (i=0;i<count;i++) {
|
|
|
|
bork = data[i];
|
|
|
|
latch |= (bork << shift);
|
|
|
|
if (shift == 24) {
|
|
|
|
regw(sc, HOST_DATA0 + reg, latch);
|
|
|
|
latch = 0;
|
|
|
|
shift = 0;
|
|
|
|
reg = (reg + 4) & 0x3c;
|
2005-02-25 19:00:58 +03:00
|
|
|
} else
|
2005-05-02 20:02:43 +04:00
|
|
|
shift += 8;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2005-05-02 20:02:43 +04:00
|
|
|
if (shift != 0) /* 24 */
|
|
|
|
regw(sc, HOST_DATA0 + reg, latch);
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2005-05-02 18:49:08 +04:00
|
|
|
mach64_rectfill(struct mach64_softc *sc, int x, int y, int width, int height,
|
|
|
|
int colour)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2005-02-27 03:26:58 +03:00
|
|
|
wait_for_idle(sc);
|
2005-05-02 20:02:43 +04:00
|
|
|
regw(sc, DP_WRITE_MASK, 0xff);
|
|
|
|
regw(sc, DP_FRGD_CLR, colour);
|
|
|
|
regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
|
|
|
|
regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
|
|
|
|
regw(sc, DP_MIX, MIX_SRC << 16);
|
|
|
|
regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
|
|
|
|
regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
|
|
|
|
regw(sc, DST_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
|
|
|
|
|
|
|
|
regw(sc, SRC_Y_X, (x << 16) | y);
|
|
|
|
regw(sc, SRC_WIDTH1, width);
|
|
|
|
regw(sc, DST_Y_X, (x << 16) | y);
|
|
|
|
regw(sc, DST_HEIGHT_WIDTH, (width << 16) | height);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2005-02-25 19:00:58 +03:00
|
|
|
mach64_clearscreen(struct mach64_softc *sc)
|
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
mach64_rectfill(sc, 0, 0, sc->virt_x, sc->virt_y, sc->sc_bg);
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
#if 0
|
|
|
|
static void
|
2005-02-27 03:26:58 +03:00
|
|
|
mach64_showpal(struct mach64_softc *sc)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
int i, x = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
mach64_rectfill(sc, x, 0, 64, 64, i);
|
|
|
|
x += 64;
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
|
|
|
}
|
2005-07-07 22:43:47 +04:00
|
|
|
#endif
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mach64_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
if ((fg == 0) && (bg == 0))
|
2005-05-02 15:22:31 +04:00
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
fg = WS_DEFAULT_FG;
|
|
|
|
bg = WS_DEFAULT_BG;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2005-05-02 20:02:43 +04:00
|
|
|
*attrp = (fg & 0xf) << 24 | (bg & 0xf) << 16 | (flags & 0xff) << 8;
|
2005-02-25 19:00:58 +03:00
|
|
|
return 0;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wsdisplay_accessops
|
|
|
|
*/
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
mach64_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
|
2006-04-12 23:38:22 +04:00
|
|
|
struct lwp *l)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct vcons_data *vd = v;
|
|
|
|
struct mach64_softc *sc = vd->cookie;
|
2005-01-09 19:29:20 +03:00
|
|
|
struct wsdisplay_fbinfo *wdf;
|
2006-04-13 00:35:42 +04:00
|
|
|
struct vcons_screen *ms = vd->active;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case WSDISPLAYIO_GTYPE:
|
2005-05-02 18:49:08 +04:00
|
|
|
/* XXX is this the right type to return? */
|
|
|
|
*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
|
2005-01-09 19:29:20 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WSDISPLAYIO_GINFO:
|
|
|
|
wdf = (void *)data;
|
2006-04-13 00:35:42 +04:00
|
|
|
wdf->height = sc->virt_y;
|
|
|
|
wdf->width = sc->virt_x;
|
|
|
|
wdf->depth = sc->color_depth;
|
2005-01-09 19:29:20 +03:00
|
|
|
wdf->cmsize = 256;
|
|
|
|
return 0;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
case WSDISPLAYIO_GETCMAP:
|
2005-05-02 18:49:08 +04:00
|
|
|
return mach64_getcmap(sc,
|
|
|
|
(struct wsdisplay_cmap *)data);
|
2005-01-09 19:29:20 +03:00
|
|
|
|
|
|
|
case WSDISPLAYIO_PUTCMAP:
|
2005-05-02 18:49:08 +04:00
|
|
|
return mach64_putcmap(sc,
|
|
|
|
(struct wsdisplay_cmap *)data);
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
/* PCI config read/write passthrough. */
|
|
|
|
case PCI_IOC_CFGREAD:
|
|
|
|
case PCI_IOC_CFGWRITE:
|
|
|
|
return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
|
2005-12-12 05:44:09 +03:00
|
|
|
cmd, data, flag, l));
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
case WSDISPLAYIO_SMODE:
|
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
int new_mode = *(int*)data;
|
|
|
|
|
|
|
|
if (new_mode != sc->sc_mode)
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2005-05-02 20:02:43 +04:00
|
|
|
sc->sc_mode = new_mode;
|
2006-04-13 00:35:42 +04:00
|
|
|
if ((new_mode == WSDISPLAYIO_MODE_EMUL)
|
|
|
|
&& (ms != NULL))
|
2005-01-09 19:29:20 +03:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
vcons_redraw_screen(ms);
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
return 0;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2005-01-09 19:29:20 +03:00
|
|
|
}
|
|
|
|
return EPASSTHROUGH;
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static paddr_t
|
2006-11-16 04:32:37 +03:00
|
|
|
mach64_mmap(void *v, void *vs, off_t offset, int prot)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct vcons_data *vd = v;
|
|
|
|
struct mach64_softc *sc = vd->cookie;
|
2005-01-09 19:29:20 +03:00
|
|
|
paddr_t pa;
|
2005-09-21 22:49:16 +04:00
|
|
|
pcireg_t reg;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2005-08-02 05:35:05 +04:00
|
|
|
#ifndef __sparc64__
|
2005-08-02 05:32:13 +04:00
|
|
|
/*
|
|
|
|
*'regular' framebuffer mmap()ing
|
|
|
|
* disabled on sparc64 because some ATI firmware likes to map some PCI
|
|
|
|
* resources to addresses that would collide with this ( like some Rage
|
|
|
|
* IIc which uses 0x2000 for the 2nd register block )
|
|
|
|
* Other 64bit architectures might run into similar problems.
|
|
|
|
*/
|
2005-05-02 20:02:43 +04:00
|
|
|
if (offset<sc->sc_apersize) {
|
2006-04-19 21:41:24 +04:00
|
|
|
pa = bus_space_mmap(sc->sc_memt, sc->sc_aperbase, offset,
|
2005-05-02 18:49:08 +04:00
|
|
|
prot, BUS_SPACE_MAP_LINEAR);
|
2005-01-09 19:29:20 +03:00
|
|
|
return pa;
|
|
|
|
}
|
2005-08-02 05:32:13 +04:00
|
|
|
#endif
|
2005-09-21 22:49:16 +04:00
|
|
|
reg = (pci_conf_read(sc->sc_pc, sc->sc_pcitag, 0x18) & 0xffffff00);
|
|
|
|
if (reg != sc->sc_regphys) {
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2005-09-21 22:49:16 +04:00
|
|
|
printf("%s: BAR 0x18 changed! (%x %x)\n",
|
|
|
|
sc->sc_dev.dv_xname, (uint32_t)sc->sc_regphys,
|
|
|
|
(uint32_t)reg);
|
2006-04-13 00:35:42 +04:00
|
|
|
#endif
|
2005-09-21 22:49:16 +04:00
|
|
|
sc->sc_regphys = reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = (pci_conf_read(sc->sc_pc, sc->sc_pcitag, 0x10) & 0xffffff00);
|
|
|
|
if (reg != sc->sc_aperphys) {
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2005-09-21 22:49:16 +04:00
|
|
|
printf("%s: BAR 0x10 changed! (%x %x)\n",
|
|
|
|
sc->sc_dev.dv_xname, (uint32_t)sc->sc_aperphys,
|
|
|
|
(uint32_t)reg);
|
2006-04-13 00:35:42 +04:00
|
|
|
#endif
|
2005-09-21 22:49:16 +04:00
|
|
|
sc->sc_aperphys = reg;
|
|
|
|
}
|
2005-08-02 05:32:13 +04:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
#if 0
|
2005-05-02 18:49:08 +04:00
|
|
|
/* evil hack to allow mmap()ing other devices as well */
|
2005-05-02 20:02:43 +04:00
|
|
|
if ((offset > 0x80000000) && (offset <= 0xffffffff)) {
|
2005-05-02 18:49:08 +04:00
|
|
|
pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
|
|
|
|
BUS_SPACE_MAP_LINEAR);
|
2005-01-09 19:29:20 +03:00
|
|
|
return pa;
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
#endif
|
2005-01-18 01:52:46 +03:00
|
|
|
|
2005-05-02 20:02:43 +04:00
|
|
|
if ((offset >= sc->sc_aperphys) &&
|
|
|
|
(offset < (sc->sc_aperphys + sc->sc_apersize))) {
|
2005-05-02 18:49:08 +04:00
|
|
|
pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
|
|
|
|
BUS_SPACE_MAP_LINEAR);
|
2005-01-18 01:52:46 +03:00
|
|
|
return pa;
|
|
|
|
}
|
|
|
|
|
2005-05-02 20:02:43 +04:00
|
|
|
if ((offset >= sc->sc_regphys) &&
|
|
|
|
(offset < (sc->sc_regphys + sc->sc_regsize))) {
|
2005-05-02 18:49:08 +04:00
|
|
|
pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
|
|
|
|
BUS_SPACE_MAP_LINEAR);
|
2005-01-18 01:52:46 +03:00
|
|
|
return pa;
|
|
|
|
}
|
|
|
|
|
2002-10-24 22:15:57 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
/* set ri->ri_bits according to fb, ri_xorigin and ri_yorigin */
|
|
|
|
static void
|
2007-03-04 08:59:00 +03:00
|
|
|
set_address(struct rasops_info *ri, void *fb)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
2005-06-01 01:16:06 +04:00
|
|
|
#ifdef notdef
|
2006-04-13 00:35:42 +04:00
|
|
|
printf(" %d %d %d\n", ri->ri_xorigin, ri->ri_yorigin, ri->ri_stride);
|
2005-06-01 01:16:06 +04:00
|
|
|
#endif
|
2007-03-04 08:59:00 +03:00
|
|
|
ri->ri_bits = (void *)((char *)fb + ri->ri_stride * ri->ri_yorigin +
|
2006-04-13 00:35:42 +04:00
|
|
|
ri->ri_xorigin);
|
2002-10-24 22:15:57 +04:00
|
|
|
}
|
|
|
|
|
2005-10-01 23:01:01 +04:00
|
|
|
#if 0
|
2005-07-07 22:43:47 +04:00
|
|
|
static int
|
2006-04-13 00:35:42 +04:00
|
|
|
mach64_load_font(void *v, void *cookie, struct wsdisplay_font *data)
|
2002-10-24 22:15:57 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
#endif
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
void
|
|
|
|
machfb_blank(struct mach64_softc *sc, int blank)
|
|
|
|
{
|
|
|
|
uint32_t reg;
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#define MACH64_BLANK (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS | CRTC_VSYNC_DIS)
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
switch (blank)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
reg = regr(sc, CRTC_GEN_CNTL);
|
|
|
|
regw(sc, CRTC_GEN_CNTL, reg & ~(MACH64_BLANK));
|
|
|
|
sc->sc_blanked = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
reg = regr(sc, CRTC_GEN_CNTL);
|
|
|
|
regw(sc, CRTC_GEN_CNTL, reg | (MACH64_BLANK));
|
|
|
|
sc->sc_blanked = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
2006-04-13 00:35:42 +04:00
|
|
|
}
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
/* framebuffer device support */
|
|
|
|
#ifdef __sparc__
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
static void
|
|
|
|
machfb_unblank(struct device *dev)
|
|
|
|
{
|
|
|
|
struct mach64_softc *sc = (struct mach64_softc *)dev;
|
|
|
|
|
|
|
|
machfb_blank(sc, 0);
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
|
2005-07-07 22:43:47 +04:00
|
|
|
static void
|
2006-04-13 00:35:42 +04:00
|
|
|
machfb_fbattach(struct mach64_softc *sc)
|
2005-02-25 19:00:58 +03:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct fbdevice *fb = &sc->sc_fb;
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
fb->fb_device = &sc->sc_dev;
|
|
|
|
fb->fb_driver = &machfb_fbdriver;
|
|
|
|
|
|
|
|
fb->fb_type.fb_cmsize = 256;
|
|
|
|
fb->fb_type.fb_size = sc->memsize;
|
|
|
|
|
|
|
|
fb->fb_type.fb_type = FBTYPE_GENERIC_PCI;
|
|
|
|
fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
|
|
|
|
fb->fb_type.fb_depth = sc->bits_per_pixel;
|
|
|
|
fb->fb_type.fb_width = sc->virt_x;
|
|
|
|
fb->fb_type.fb_height = sc->virt_y;
|
|
|
|
|
2006-04-19 21:41:24 +04:00
|
|
|
fb->fb_pixels = sc->sc_aperture;
|
2006-04-13 00:35:42 +04:00
|
|
|
fb_attach(fb, sc->sc_console);
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
int
|
|
|
|
machfb_fbopen(dev_t dev, int flags, int mode, struct lwp *l)
|
2005-02-25 19:00:58 +03:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct mach64_softc *sc;
|
|
|
|
int unit = minor(dev);
|
|
|
|
|
|
|
|
sc = machfb_cd.cd_devs[unit];
|
|
|
|
sc->sc_locked = 1;
|
|
|
|
|
|
|
|
#ifdef DEBUG_MACHFB
|
|
|
|
printf("machfb_fbopen(%d)\n", unit);
|
2005-06-01 01:16:06 +04:00
|
|
|
#endif
|
2006-04-13 00:35:42 +04:00
|
|
|
if (unit > machfb_cd.cd_ndevs || machfb_cd.cd_devs[unit] == NULL)
|
|
|
|
return ENXIO;
|
|
|
|
return 0;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
int
|
|
|
|
machfb_fbclose(dev_t dev, int flags, int mode, struct lwp *l)
|
2005-02-25 19:00:58 +03:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct mach64_softc *sc = machfb_cd.cd_devs[minor(dev)];
|
2005-05-02 20:02:43 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DEBUG_MACHFB
|
|
|
|
printf("machfb_fbclose()\n");
|
|
|
|
#endif
|
|
|
|
mach64_init_engine(sc);
|
|
|
|
mach64_init_lut(sc);
|
|
|
|
sc->sc_locked = 0;
|
|
|
|
return 0;
|
2005-02-25 19:00:58 +03:00
|
|
|
}
|
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
machfb_fbioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
|
2005-02-25 19:00:58 +03:00
|
|
|
{
|
2006-04-13 00:35:42 +04:00
|
|
|
struct mach64_softc *sc = machfb_cd.cd_devs[minor(dev)];
|
2005-02-25 19:00:58 +03:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DEBUG_MACHFB
|
|
|
|
printf("machfb_fbioctl(%d, %lx)\n", minor(dev), cmd);
|
|
|
|
#endif
|
|
|
|
switch (cmd) {
|
|
|
|
case FBIOGTYPE:
|
|
|
|
*(struct fbtype *)data = sc->sc_fb.fb_type;
|
|
|
|
break;
|
2002-10-24 22:15:57 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
case FBIOGATTR:
|
|
|
|
#define fba ((struct fbgattr *)data)
|
|
|
|
fba->real_type = sc->sc_fb.fb_type.fb_type;
|
|
|
|
fba->owner = 0; /* XXX ??? */
|
|
|
|
fba->fbtype = sc->sc_fb.fb_type;
|
|
|
|
fba->sattr.flags = 0;
|
|
|
|
fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
|
|
|
|
fba->sattr.dev_specific[0] = sc->sc_nbus;
|
|
|
|
fba->sattr.dev_specific[1] = sc->sc_ndev;
|
|
|
|
fba->sattr.dev_specific[2] = sc->sc_nfunc;
|
|
|
|
fba->sattr.dev_specific[3] = -1;
|
|
|
|
fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
|
|
|
|
fba->emu_types[1] = -1;
|
|
|
|
#undef fba
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
case FBIOGETCMAP:
|
|
|
|
#define p ((struct fbcmap *)data)
|
|
|
|
return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
|
|
|
|
|
|
|
|
case FBIOPUTCMAP:
|
|
|
|
/* copy to software map */
|
|
|
|
error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
/* now blast them into the chip */
|
|
|
|
/* XXX should use retrace interrupt */
|
|
|
|
cg6_loadcmap(sc, p->index, p->count);
|
|
|
|
#undef p
|
|
|
|
break;
|
2002-10-31 17:10:07 +03:00
|
|
|
#endif
|
2006-04-13 00:35:42 +04:00
|
|
|
case FBIOGVIDEO:
|
|
|
|
*(int *)data = sc->sc_blanked;
|
|
|
|
break;
|
2005-10-01 23:01:01 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
case FBIOSVIDEO:
|
|
|
|
machfb_blank(sc, *(int *)data);
|
|
|
|
break;
|
2005-10-01 23:01:01 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
#if 0
|
|
|
|
case FBIOGCURSOR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSCURSOR:
|
|
|
|
break;
|
2005-10-01 23:01:01 +04:00
|
|
|
|
2006-04-13 00:35:42 +04:00
|
|
|
case FBIOGCURPOS:
|
|
|
|
*(struct fbcurpos *)data = sc->sc_cursor.cc_pos;
|
2005-10-01 23:01:01 +04:00
|
|
|
break;
|
2006-04-13 00:35:42 +04:00
|
|
|
|
|
|
|
case FBIOSCURPOS:
|
|
|
|
sc->sc_cursor.cc_pos = *(struct fbcurpos *)data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOGCURMAX:
|
|
|
|
/* max cursor size is 32x32 */
|
|
|
|
((struct fbcurpos *)data)->x = 32;
|
|
|
|
((struct fbcurpos *)data)->y = 32;
|
2005-10-01 23:01:01 +04:00
|
|
|
break;
|
2006-04-13 00:35:42 +04:00
|
|
|
#endif
|
|
|
|
case PCI_IOC_CFGREAD:
|
|
|
|
case PCI_IOC_CFGWRITE:
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pci_devioctl(sc->sc_pc, sc->sc_pcitag,
|
|
|
|
cmd, data, flags, l);
|
|
|
|
|
|
|
|
#ifdef DEBUG_MACHFB
|
|
|
|
printf("pci_devioctl: %d\n", ret);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2005-10-01 23:01:01 +04:00
|
|
|
default:
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DEBUG_MACHFB
|
|
|
|
log(LOG_NOTICE, "machfb_fbioctl(0x%lx) (%s[%d])\n", cmd,
|
|
|
|
p->p_comm, p->p_pid);
|
|
|
|
#endif
|
|
|
|
return ENOTTY;
|
2005-10-01 23:01:01 +04:00
|
|
|
}
|
2006-04-13 00:35:42 +04:00
|
|
|
#ifdef DEBUG_MACHFB
|
|
|
|
printf("machfb_fbioctl done\n");
|
|
|
|
#endif
|
|
|
|
return 0;
|
2005-10-01 23:01:01 +04:00
|
|
|
}
|
2006-04-13 00:35:42 +04:00
|
|
|
|
|
|
|
paddr_t
|
|
|
|
machfb_fbmmap(dev_t dev, off_t off, int prot)
|
|
|
|
{
|
|
|
|
struct mach64_softc *sc = machfb_cd.cd_devs[minor(dev)];
|
|
|
|
|
|
|
|
if (sc != NULL)
|
|
|
|
return mach64_mmap(&sc->vd, NULL, off, prot);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __sparc__ */
|