10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51106Smrj * Common Development and Distribution License (the "License"). 61106Smrj * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211106Smrj 220Sstevel@tonic-gate /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ 230Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */ 240Sstevel@tonic-gate /* All Rights Reserved */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 27*1661Sms148562 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 280Sstevel@tonic-gate * Use is subject to license terms. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/errno.h> 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/conf.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/visual_io.h> 380Sstevel@tonic-gate #include <sys/font.h> 390Sstevel@tonic-gate #include <sys/fbio.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #include <sys/ddi.h> 420Sstevel@tonic-gate #include <sys/stat.h> 430Sstevel@tonic-gate #include <sys/sunddi.h> 440Sstevel@tonic-gate #include <sys/file.h> 450Sstevel@tonic-gate #include <sys/open.h> 460Sstevel@tonic-gate #include <sys/modctl.h> 470Sstevel@tonic-gate #include <sys/vgareg.h> 480Sstevel@tonic-gate #include <sys/vgasubr.h> 490Sstevel@tonic-gate #include <sys/pci.h> 500Sstevel@tonic-gate #include <sys/kd.h> 510Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 520Sstevel@tonic-gate #include <sys/sunldi.h> 530Sstevel@tonic-gate #include <sys/agpgart.h> 540Sstevel@tonic-gate #include <sys/agp/agpdefs.h> 550Sstevel@tonic-gate #include <sys/agp/agpmaster_io.h> 560Sstevel@tonic-gate 570Sstevel@tonic-gate #define MYNAME "vgatext" 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * agp support macros 610Sstevel@tonic-gate */ 620Sstevel@tonic-gate #define I8XX_MMIO_REGSET 2 630Sstevel@tonic-gate #define I8XX_FB_REGSET 1 640Sstevel@tonic-gate #define I8XX_PTE_OFFSET 0x10000 650Sstevel@tonic-gate #define I8XX_PGTBL_CTL 0x2020 66*1661Sms148562 #define I915_GTTADDR_BAR 4 67*1661Sms148562 #define I915_FB_REGSET 3 68*1661Sms148562 69*1661Sms148562 #define IS_IGD(agp_master) ((agp_master->agpm_dev_type == DEVICE_IS_I810) || \ 70*1661Sms148562 (agp_master->agpm_dev_type == DEVICE_IS_I830)) 71*1661Sms148562 720Sstevel@tonic-gate #define DEV2INST(dev) (getminor(dev) >> 1) 730Sstevel@tonic-gate #define INST2NODE1(inst) ((inst) << 1) 740Sstevel@tonic-gate #define INST2NODE2(inst) (((inst) << 1) + 1) 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* I don't know exactly where these should be defined, but this is a */ 770Sstevel@tonic-gate /* heck of a lot better than constants in the code. */ 780Sstevel@tonic-gate #define TEXT_ROWS 25 790Sstevel@tonic-gate #define TEXT_COLS 80 800Sstevel@tonic-gate 810Sstevel@tonic-gate #define VGA_BRIGHT_WHITE 0x0f 820Sstevel@tonic-gate #define VGA_BLACK 0x00 830Sstevel@tonic-gate 840Sstevel@tonic-gate #define VGA_REG_ADDR 0x3c0 850Sstevel@tonic-gate #define VGA_REG_SIZE 0x20 860Sstevel@tonic-gate 870Sstevel@tonic-gate #define VGA_MEM_ADDR 0xa0000 880Sstevel@tonic-gate #define VGA_MEM_SIZE 0x20000 890Sstevel@tonic-gate 900Sstevel@tonic-gate #define VGA_MMAP_FB_BASE VGA_MEM_ADDR 910Sstevel@tonic-gate 920Sstevel@tonic-gate static int vgatext_open(dev_t *, int, int, cred_t *); 930Sstevel@tonic-gate static int vgatext_close(dev_t, int, int, cred_t *); 940Sstevel@tonic-gate static int vgatext_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 950Sstevel@tonic-gate static int vgatext_devmap(dev_t, devmap_cookie_t, offset_t, size_t, 960Sstevel@tonic-gate size_t *, uint_t); 970Sstevel@tonic-gate 980Sstevel@tonic-gate static struct cb_ops cb_vgatext_ops = { 990Sstevel@tonic-gate vgatext_open, /* cb_open */ 1000Sstevel@tonic-gate vgatext_close, /* cb_close */ 1010Sstevel@tonic-gate nodev, /* cb_strategy */ 1020Sstevel@tonic-gate nodev, /* cb_print */ 1030Sstevel@tonic-gate nodev, /* cb_dump */ 1040Sstevel@tonic-gate nodev, /* cb_read */ 1050Sstevel@tonic-gate nodev, /* cb_write */ 1060Sstevel@tonic-gate vgatext_ioctl, /* cb_ioctl */ 1070Sstevel@tonic-gate vgatext_devmap, /* cb_devmap */ 1080Sstevel@tonic-gate nodev, /* cb_mmap */ 1090Sstevel@tonic-gate ddi_devmap_segmap, /* cb_segmap */ 1100Sstevel@tonic-gate nochpoll, /* cb_chpoll */ 1110Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 1120Sstevel@tonic-gate 0, /* cb_stream */ 1130Sstevel@tonic-gate D_NEW | D_MTSAFE /* cb_flag */ 1140Sstevel@tonic-gate }; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate static int vgatext_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 1180Sstevel@tonic-gate void **result); 1190Sstevel@tonic-gate static int vgatext_attach(dev_info_t *, ddi_attach_cmd_t); 1200Sstevel@tonic-gate static int vgatext_detach(dev_info_t *, ddi_detach_cmd_t); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate static struct vis_identifier text_ident = { "SUNWtext" }; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate static struct dev_ops vgatext_ops = { 1250Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 1260Sstevel@tonic-gate 0, /* devo_refcnt */ 1270Sstevel@tonic-gate vgatext_info, /* devo_getinfo */ 1280Sstevel@tonic-gate nulldev, /* devo_identify */ 1290Sstevel@tonic-gate nulldev, /* devo_probe */ 1300Sstevel@tonic-gate vgatext_attach, /* devo_attach */ 1310Sstevel@tonic-gate vgatext_detach, /* devo_detach */ 1320Sstevel@tonic-gate nodev, /* devo_reset */ 1330Sstevel@tonic-gate &cb_vgatext_ops, /* devo_cb_ops */ 1340Sstevel@tonic-gate (struct bus_ops *)NULL, /* devo_bus_ops */ 1350Sstevel@tonic-gate NULL /* power */ 1360Sstevel@tonic-gate }; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate /* 1400Sstevel@tonic-gate * agp support data structures 1410Sstevel@tonic-gate */ 1420Sstevel@tonic-gate typedef struct gtt_impl { 1430Sstevel@tonic-gate ddi_acc_handle_t gtt_mmio_handle; /* mmaped graph registers */ 1440Sstevel@tonic-gate caddr_t gtt_mmio_base; /* pointer to register base */ 1450Sstevel@tonic-gate caddr_t gtt_addr; /* pointer to gtt */ 1460Sstevel@tonic-gate igd_info_t gtt_info; /* for I8XX_GET_INFO ioctl */ 1470Sstevel@tonic-gate } gtt_impl_t; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate typedef struct agp_master_softc { 1500Sstevel@tonic-gate uint32_t agpm_id; /* agp master device id */ 1510Sstevel@tonic-gate ddi_acc_handle_t agpm_acc_hdl; /* agp master pci conf handle */ 1520Sstevel@tonic-gate int agpm_dev_type; /* which agp device type */ 1530Sstevel@tonic-gate union { 1540Sstevel@tonic-gate off_t agpm_acaptr; /* AGP capability reg pointer */ 1550Sstevel@tonic-gate gtt_impl_t agpm_gtt; /* for gtt table */ 1560Sstevel@tonic-gate } agpm_data; 1570Sstevel@tonic-gate } agp_master_softc_t; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate struct vgatext_softc { 1620Sstevel@tonic-gate struct vgaregmap regs; 1630Sstevel@tonic-gate struct vgaregmap fb; 1640Sstevel@tonic-gate off_t fb_size; 1650Sstevel@tonic-gate int fb_regno; 1660Sstevel@tonic-gate dev_info_t *devi; 1670Sstevel@tonic-gate int mode; /* KD_TEXT or KD_GRAPHICS */ 1680Sstevel@tonic-gate caddr_t text_base; /* hardware text base */ 1690Sstevel@tonic-gate char shadow[TEXT_ROWS*TEXT_COLS*2]; 1700Sstevel@tonic-gate caddr_t current_base; /* hardware or shadow */ 1710Sstevel@tonic-gate struct { 1720Sstevel@tonic-gate boolean_t visible; 1730Sstevel@tonic-gate int row; 1740Sstevel@tonic-gate int col; 1750Sstevel@tonic-gate } cursor; 1760Sstevel@tonic-gate struct vis_polledio polledio; 1770Sstevel@tonic-gate struct { 1780Sstevel@tonic-gate unsigned char red; 1790Sstevel@tonic-gate unsigned char green; 1800Sstevel@tonic-gate unsigned char blue; 1810Sstevel@tonic-gate } colormap[VGA8_CMAP_ENTRIES]; 1820Sstevel@tonic-gate unsigned char attrib_palette[VGA_ATR_NUM_PLT]; 1830Sstevel@tonic-gate agp_master_softc_t *agp_master; /* NULL mean not PCI, for AGP */ 1840Sstevel@tonic-gate }; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate static int vgatext_devinit(struct vgatext_softc *, struct vis_devinit *data); 1870Sstevel@tonic-gate static void vgatext_cons_copy(struct vgatext_softc *, 1880Sstevel@tonic-gate struct vis_conscopy *); 1890Sstevel@tonic-gate static void vgatext_cons_display(struct vgatext_softc *, 1900Sstevel@tonic-gate struct vis_consdisplay *); 1910Sstevel@tonic-gate static void vgatext_cons_cursor(struct vgatext_softc *, 1920Sstevel@tonic-gate struct vis_conscursor *); 1930Sstevel@tonic-gate static void vgatext_polled_copy(struct vis_polledio_arg *, 1940Sstevel@tonic-gate struct vis_conscopy *); 1950Sstevel@tonic-gate static void vgatext_polled_display(struct vis_polledio_arg *, 1960Sstevel@tonic-gate struct vis_consdisplay *); 1970Sstevel@tonic-gate static void vgatext_polled_cursor(struct vis_polledio_arg *, 1980Sstevel@tonic-gate struct vis_conscursor *); 1990Sstevel@tonic-gate static void vgatext_init(struct vgatext_softc *); 2000Sstevel@tonic-gate static void vgatext_set_text(struct vgatext_softc *); 2010Sstevel@tonic-gate #if defined(USE_BORDERS) 2020Sstevel@tonic-gate static void vgatext_init_graphics(struct vgatext_softc *); 2030Sstevel@tonic-gate #endif 2040Sstevel@tonic-gate static int vgatext_kdsetmode(struct vgatext_softc *softc, int mode); 2050Sstevel@tonic-gate static void vgatext_setfont(struct vgatext_softc *softc); 2060Sstevel@tonic-gate static void vgatext_get_cursor(struct vgatext_softc *softc, 2070Sstevel@tonic-gate screen_pos_t *row, screen_pos_t *col); 2080Sstevel@tonic-gate static void vgatext_set_cursor(struct vgatext_softc *softc, int row, int col); 2090Sstevel@tonic-gate static void vgatext_hide_cursor(struct vgatext_softc *softc); 2100Sstevel@tonic-gate static void vgatext_save_colormap(struct vgatext_softc *softc); 2110Sstevel@tonic-gate static void vgatext_restore_colormap(struct vgatext_softc *softc); 2120Sstevel@tonic-gate static int vgatext_get_pci_reg_index(dev_info_t *const devi, 2130Sstevel@tonic-gate unsigned long himask, unsigned long hival, unsigned long addr, 2140Sstevel@tonic-gate off_t *offset); 2150Sstevel@tonic-gate static int vgatext_get_isa_reg_index(dev_info_t *const devi, 2160Sstevel@tonic-gate unsigned long hival, unsigned long addr, off_t *offset); 2170Sstevel@tonic-gate /* 2180Sstevel@tonic-gate * agp support functions prototype 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate static off_t agp_master_cap_find(ddi_acc_handle_t); 2210Sstevel@tonic-gate static int detect_i8xx_device(agp_master_softc_t *); 2220Sstevel@tonic-gate static int detect_agp_devcice(agp_master_softc_t *); 2230Sstevel@tonic-gate static int agp_master_init(struct vgatext_softc *); 2240Sstevel@tonic-gate static void agp_master_end(agp_master_softc_t *); 2250Sstevel@tonic-gate static int phys2entry(uint32_t, uint32_t, uint32_t *); 2260Sstevel@tonic-gate static int i8xx_add_to_gtt(gtt_impl_t *, igd_gtt_seg_t); 2270Sstevel@tonic-gate static void i8xx_remove_from_gtt(gtt_impl_t *, igd_gtt_seg_t); 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate static void *vgatext_softc_head; 2300Sstevel@tonic-gate static char vgatext_silent; 2310Sstevel@tonic-gate static char happyface_boot; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* Loadable Driver stuff */ 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate static struct modldrv modldrv = { 2360Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 2370Sstevel@tonic-gate "VGA text driver v%I%", /* Name of the module. */ 2380Sstevel@tonic-gate &vgatext_ops, /* driver ops */ 2390Sstevel@tonic-gate }; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate static struct modlinkage modlinkage = { 2420Sstevel@tonic-gate MODREV_1, (void *) &modldrv, NULL 2430Sstevel@tonic-gate }; 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate typedef enum pc_colors { 2460Sstevel@tonic-gate pc_black = 0, 2470Sstevel@tonic-gate pc_blue = 1, 2480Sstevel@tonic-gate pc_green = 2, 2490Sstevel@tonic-gate pc_cyan = 3, 2500Sstevel@tonic-gate pc_red = 4, 2510Sstevel@tonic-gate pc_magenta = 5, 2520Sstevel@tonic-gate pc_brown = 6, 2530Sstevel@tonic-gate pc_white = 7, 2540Sstevel@tonic-gate pc_grey = 8, 2550Sstevel@tonic-gate pc_brt_blue = 9, 2560Sstevel@tonic-gate pc_brt_green = 10, 2570Sstevel@tonic-gate pc_brt_cyan = 11, 2580Sstevel@tonic-gate pc_brt_red = 12, 2590Sstevel@tonic-gate pc_brt_magenta = 13, 2600Sstevel@tonic-gate pc_yellow = 14, 2610Sstevel@tonic-gate pc_brt_white = 15 2620Sstevel@tonic-gate } pc_colors_t; 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate static const unsigned char solaris_color_to_pc_color[16] = { 2650Sstevel@tonic-gate pc_brt_white, /* 0 - brt_white */ 2660Sstevel@tonic-gate pc_black, /* 1 - black */ 2670Sstevel@tonic-gate pc_blue, /* 2 - blue */ 2680Sstevel@tonic-gate pc_green, /* 3 - green */ 2690Sstevel@tonic-gate pc_cyan, /* 4 - cyan */ 2700Sstevel@tonic-gate pc_red, /* 5 - red */ 2710Sstevel@tonic-gate pc_magenta, /* 6 - magenta */ 2720Sstevel@tonic-gate pc_brown, /* 7 - brown */ 2730Sstevel@tonic-gate pc_white, /* 8 - white */ 2740Sstevel@tonic-gate pc_grey, /* 9 - gery */ 2750Sstevel@tonic-gate pc_brt_blue, /* 10 - brt_blue */ 2760Sstevel@tonic-gate pc_brt_green, /* 11 - brt_green */ 2770Sstevel@tonic-gate pc_brt_cyan, /* 12 - brt_cyan */ 2780Sstevel@tonic-gate pc_brt_red, /* 13 - brt_red */ 2790Sstevel@tonic-gate pc_brt_magenta, /* 14 - brt_magenta */ 2800Sstevel@tonic-gate pc_yellow /* 15 - yellow */ 2810Sstevel@tonic-gate }; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate static ddi_device_acc_attr_t i8xx_dev_access = { 2840Sstevel@tonic-gate DDI_DEVICE_ATTR_V0, 2850Sstevel@tonic-gate DDI_NEVERSWAP_ACC, 2860Sstevel@tonic-gate DDI_STRICTORDER_ACC 2870Sstevel@tonic-gate }; 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate static ddi_device_acc_attr_t dev_attr = { 2900Sstevel@tonic-gate DDI_DEVICE_ATTR_V0, 2910Sstevel@tonic-gate DDI_NEVERSWAP_ACC, 2920Sstevel@tonic-gate DDI_STRICTORDER_ACC, 2930Sstevel@tonic-gate }; 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate int 2960Sstevel@tonic-gate _init(void) 2970Sstevel@tonic-gate { 2980Sstevel@tonic-gate int e; 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate if ((e = ddi_soft_state_init(&vgatext_softc_head, 3010Sstevel@tonic-gate sizeof (struct vgatext_softc), 1)) != 0) { 3020Sstevel@tonic-gate return (e); 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate e = mod_install(&modlinkage); 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate if (e) { 3080Sstevel@tonic-gate ddi_soft_state_fini(&vgatext_softc_head); 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate return (e); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate int 3140Sstevel@tonic-gate _fini(void) 3150Sstevel@tonic-gate { 3160Sstevel@tonic-gate int e; 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) != 0) 3190Sstevel@tonic-gate return (e); 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate ddi_soft_state_fini(&vgatext_softc_head); 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate return (0); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate int 3270Sstevel@tonic-gate _info(struct modinfo *modinfop) 3280Sstevel@tonic-gate { 3290Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 3300Sstevel@tonic-gate } 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate /* default structure for FBIOGATTR ioctl */ 3330Sstevel@tonic-gate static struct fbgattr vgatext_attr = { 3340Sstevel@tonic-gate /* real_type owner */ 3350Sstevel@tonic-gate FBTYPE_SUNFAST_COLOR, 0, 3360Sstevel@tonic-gate /* fbtype: type h w depth cms size */ 3370Sstevel@tonic-gate { FBTYPE_SUNFAST_COLOR, TEXT_ROWS, TEXT_COLS, 1, 256, 0 }, 3380Sstevel@tonic-gate /* fbsattr: flags emu_type dev_specific */ 3390Sstevel@tonic-gate { 0, FBTYPE_SUN4COLOR, { 0 } }, 3400Sstevel@tonic-gate /* emu_types */ 3410Sstevel@tonic-gate { -1 } 3420Sstevel@tonic-gate }; 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate /* 3450Sstevel@tonic-gate * handy macros 3460Sstevel@tonic-gate */ 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate #define getsoftc(instance) ((struct vgatext_softc *) \ 3490Sstevel@tonic-gate ddi_get_soft_state(vgatext_softc_head, (instance))) 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate static int 3520Sstevel@tonic-gate vgatext_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 3530Sstevel@tonic-gate { 3540Sstevel@tonic-gate struct vgatext_softc *softc; 3550Sstevel@tonic-gate int unit = ddi_get_instance(devi); 3560Sstevel@tonic-gate int error; 3570Sstevel@tonic-gate char *parent_type = NULL; 3580Sstevel@tonic-gate int reg_rnumber; 3590Sstevel@tonic-gate off_t reg_offset; 3600Sstevel@tonic-gate off_t mem_offset; 3610Sstevel@tonic-gate char buf[80], *cons; 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate switch (cmd) { 3650Sstevel@tonic-gate case DDI_ATTACH: 3660Sstevel@tonic-gate break; 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate case DDI_RESUME: 3690Sstevel@tonic-gate return (DDI_SUCCESS); 3700Sstevel@tonic-gate default: 3710Sstevel@tonic-gate return (DDI_FAILURE); 3720Sstevel@tonic-gate } 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate /* DDI_ATTACH */ 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate /* Allocate softc struct */ 3770Sstevel@tonic-gate if (ddi_soft_state_zalloc(vgatext_softc_head, unit) != DDI_SUCCESS) { 3780Sstevel@tonic-gate return (DDI_FAILURE); 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate softc = getsoftc(unit); 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* link it in */ 3830Sstevel@tonic-gate softc->devi = devi; 3840Sstevel@tonic-gate ddi_set_driver_private(devi, softc); 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate softc->polledio.arg = (struct vis_polledio_arg *)softc; 3870Sstevel@tonic-gate softc->polledio.display = vgatext_polled_display; 3880Sstevel@tonic-gate softc->polledio.copy = vgatext_polled_copy; 3890Sstevel@tonic-gate softc->polledio.cursor = vgatext_polled_cursor; 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate error = ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_get_parent(devi), 3920Sstevel@tonic-gate DDI_PROP_DONTPASS, "device_type", &parent_type); 3930Sstevel@tonic-gate if (error != DDI_SUCCESS) { 3940Sstevel@tonic-gate cmn_err(CE_WARN, MYNAME ": can't determine parent type."); 3950Sstevel@tonic-gate goto fail; 3960Sstevel@tonic-gate } 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate #define STREQ(a, b) (strcmp((a), (b)) == 0) 3990Sstevel@tonic-gate if (STREQ(parent_type, "isa") || STREQ(parent_type, "eisa")) { 4000Sstevel@tonic-gate reg_rnumber = vgatext_get_isa_reg_index(devi, 1, VGA_REG_ADDR, 4010Sstevel@tonic-gate ®_offset); 4020Sstevel@tonic-gate if (reg_rnumber < 0) { 4030Sstevel@tonic-gate cmn_err(CE_WARN, 4040Sstevel@tonic-gate MYNAME ": can't find reg entry for registers"); 4050Sstevel@tonic-gate goto fail; 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate softc->fb_regno = vgatext_get_isa_reg_index(devi, 0, 4080Sstevel@tonic-gate VGA_MEM_ADDR, &mem_offset); 4090Sstevel@tonic-gate if (softc->fb_regno < 0) { 4100Sstevel@tonic-gate cmn_err(CE_WARN, 4110Sstevel@tonic-gate MYNAME ": can't find reg entry for memory"); 4120Sstevel@tonic-gate goto fail; 4130Sstevel@tonic-gate } 414881Sjohnny } else if (STREQ(parent_type, "pci") || STREQ(parent_type, "pciex")) { 4150Sstevel@tonic-gate reg_rnumber = vgatext_get_pci_reg_index(devi, 4160Sstevel@tonic-gate PCI_REG_ADDR_M|PCI_REG_REL_M, 4170Sstevel@tonic-gate PCI_ADDR_IO|PCI_RELOCAT_B, VGA_REG_ADDR, 4180Sstevel@tonic-gate ®_offset); 4190Sstevel@tonic-gate if (reg_rnumber < 0) { 4200Sstevel@tonic-gate cmn_err(CE_WARN, 4210Sstevel@tonic-gate MYNAME ": can't find reg entry for registers"); 4220Sstevel@tonic-gate goto fail; 4230Sstevel@tonic-gate } 4240Sstevel@tonic-gate softc->fb_regno = vgatext_get_pci_reg_index(devi, 4250Sstevel@tonic-gate PCI_REG_ADDR_M|PCI_REG_REL_M, 4260Sstevel@tonic-gate PCI_ADDR_MEM32|PCI_RELOCAT_B, VGA_MEM_ADDR, 4270Sstevel@tonic-gate &mem_offset); 4280Sstevel@tonic-gate if (softc->fb_regno < 0) { 4290Sstevel@tonic-gate cmn_err(CE_WARN, 4300Sstevel@tonic-gate MYNAME ": can't find reg entry for memory"); 4310Sstevel@tonic-gate goto fail; 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate softc->agp_master = (agp_master_softc_t *) 4340Sstevel@tonic-gate kmem_zalloc(sizeof (agp_master_softc_t), KM_SLEEP); 4350Sstevel@tonic-gate } else { 4360Sstevel@tonic-gate cmn_err(CE_WARN, MYNAME ": unknown parent type \"%s\".", 4370Sstevel@tonic-gate parent_type); 4380Sstevel@tonic-gate goto fail; 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate ddi_prop_free(parent_type); 4410Sstevel@tonic-gate parent_type = NULL; 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate error = ddi_regs_map_setup(devi, reg_rnumber, 4440Sstevel@tonic-gate (caddr_t *)&softc->regs.addr, reg_offset, VGA_REG_SIZE, 4450Sstevel@tonic-gate &dev_attr, &softc->regs.handle); 4460Sstevel@tonic-gate if (error != DDI_SUCCESS) 4470Sstevel@tonic-gate goto fail; 4480Sstevel@tonic-gate softc->regs.mapped = B_TRUE; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate softc->fb_size = VGA_MEM_SIZE; 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate error = ddi_regs_map_setup(devi, softc->fb_regno, 4530Sstevel@tonic-gate (caddr_t *)&softc->fb.addr, 4540Sstevel@tonic-gate mem_offset, softc->fb_size, 4550Sstevel@tonic-gate &dev_attr, &softc->fb.handle); 4560Sstevel@tonic-gate if (error != DDI_SUCCESS) 4570Sstevel@tonic-gate goto fail; 4580Sstevel@tonic-gate softc->fb.mapped = B_TRUE; 4590Sstevel@tonic-gate 4601106Smrj if (ddi_get8(softc->regs.handle, 4610Sstevel@tonic-gate softc->regs.addr + VGA_MISC_R) & VGA_MISC_IOA_SEL) 4620Sstevel@tonic-gate softc->text_base = (caddr_t)softc->fb.addr + VGA_COLOR_BASE; 4630Sstevel@tonic-gate else 4640Sstevel@tonic-gate softc->text_base = (caddr_t)softc->fb.addr + VGA_MONO_BASE; 4650Sstevel@tonic-gate softc->current_base = softc->text_base; 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate (void) sprintf(buf, "text-%d", unit); 4680Sstevel@tonic-gate error = ddi_create_minor_node(devi, buf, S_IFCHR, 4690Sstevel@tonic-gate INST2NODE1(unit), DDI_NT_DISPLAY, NULL); 4700Sstevel@tonic-gate if (error != DDI_SUCCESS) 4710Sstevel@tonic-gate goto fail; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate error = ddi_prop_create(makedevice(DDI_MAJOR_T_UNKNOWN, unit), 4740Sstevel@tonic-gate devi, DDI_PROP_CANSLEEP, DDI_KERNEL_IOCTL, NULL, 0); 4750Sstevel@tonic-gate if (error != DDI_SUCCESS) 4760Sstevel@tonic-gate goto fail; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 4790Sstevel@tonic-gate DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) { 4800Sstevel@tonic-gate if (strcmp(cons, "graphics") == 0) { 4810Sstevel@tonic-gate happyface_boot = 1; 4820Sstevel@tonic-gate vgatext_silent = 1; 4830Sstevel@tonic-gate } 4840Sstevel@tonic-gate ddi_prop_free(cons); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /* only do this if not in graphics mode */ 4880Sstevel@tonic-gate if (vgatext_silent == 0) { 4890Sstevel@tonic-gate vgatext_init(softc); 4900Sstevel@tonic-gate vgatext_save_colormap(softc); 4910Sstevel@tonic-gate } 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate if (softc->agp_master != NULL) { /* is PCI */ 4940Sstevel@tonic-gate if (agp_master_init(softc) != 0) { /* unsuccessful */ 4950Sstevel@tonic-gate kmem_free(softc->agp_master, 4960Sstevel@tonic-gate sizeof (agp_master_softc_t)); 4970Sstevel@tonic-gate softc->agp_master = NULL; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate } 5000Sstevel@tonic-gate } 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate return (DDI_SUCCESS); 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate fail: 5050Sstevel@tonic-gate if (parent_type != NULL) 5060Sstevel@tonic-gate ddi_prop_free(parent_type); 5070Sstevel@tonic-gate (void) vgatext_detach(devi, DDI_DETACH); 5080Sstevel@tonic-gate return (error); 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate static int 5120Sstevel@tonic-gate vgatext_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 5130Sstevel@tonic-gate { 5140Sstevel@tonic-gate int instance = ddi_get_instance(devi); 5150Sstevel@tonic-gate struct vgatext_softc *softc = getsoftc(instance); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate switch (cmd) { 5190Sstevel@tonic-gate case DDI_DETACH: 5200Sstevel@tonic-gate if (softc->agp_master != NULL) { /* agp initiated */ 5210Sstevel@tonic-gate agp_master_end(softc->agp_master); 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate kmem_free(softc->agp_master, 5240Sstevel@tonic-gate sizeof (agp_master_softc_t)); 5250Sstevel@tonic-gate softc->agp_master = NULL; 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate if (softc->fb.mapped) 5300Sstevel@tonic-gate ddi_regs_map_free(&softc->fb.handle); 5310Sstevel@tonic-gate if (softc->regs.mapped) 5320Sstevel@tonic-gate ddi_regs_map_free(&softc->regs.handle); 5330Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 5340Sstevel@tonic-gate (void) ddi_soft_state_free(vgatext_softc_head, instance); 5350Sstevel@tonic-gate return (DDI_SUCCESS); 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate default: 5380Sstevel@tonic-gate cmn_err(CE_WARN, "vgatext_detach: unknown cmd 0x%x\n", cmd); 5390Sstevel@tonic-gate return (DDI_FAILURE); 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate /*ARGSUSED*/ 5440Sstevel@tonic-gate static int 5450Sstevel@tonic-gate vgatext_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 5460Sstevel@tonic-gate { 5470Sstevel@tonic-gate dev_t dev; 5480Sstevel@tonic-gate int error; 5490Sstevel@tonic-gate int instance; 5500Sstevel@tonic-gate struct vgatext_softc *softc; 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate error = DDI_SUCCESS; 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate dev = (dev_t)arg; 5550Sstevel@tonic-gate instance = DEV2INST(dev); 5560Sstevel@tonic-gate softc = getsoftc(instance); 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate switch (infocmd) { 5590Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 5600Sstevel@tonic-gate if (softc == NULL || softc->devi == NULL) { 5610Sstevel@tonic-gate error = DDI_FAILURE; 5620Sstevel@tonic-gate } else { 5630Sstevel@tonic-gate *result = (void *) softc->devi; 5640Sstevel@tonic-gate error = DDI_SUCCESS; 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate break; 5670Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 5680Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 5690Sstevel@tonic-gate error = DDI_SUCCESS; 5700Sstevel@tonic-gate break; 5710Sstevel@tonic-gate default: 5720Sstevel@tonic-gate error = DDI_FAILURE; 5730Sstevel@tonic-gate break; 5740Sstevel@tonic-gate } 5750Sstevel@tonic-gate return (error); 5760Sstevel@tonic-gate } 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /*ARGSUSED*/ 5800Sstevel@tonic-gate static int 5810Sstevel@tonic-gate vgatext_open(dev_t *devp, int flag, int otyp, cred_t *cred) 5820Sstevel@tonic-gate { 5830Sstevel@tonic-gate struct vgatext_softc *softc = getsoftc(DEV2INST(*devp)); 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate if (softc == NULL || otyp == OTYP_BLK) 5860Sstevel@tonic-gate return (ENXIO); 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate return (0); 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate /*ARGSUSED*/ 5920Sstevel@tonic-gate static int 5930Sstevel@tonic-gate vgatext_close(dev_t devp, int flag, int otyp, cred_t *cred) 5940Sstevel@tonic-gate { 5950Sstevel@tonic-gate return (0); 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate /*ARGSUSED*/ 5990Sstevel@tonic-gate static int 6000Sstevel@tonic-gate vgatext_ioctl( 6010Sstevel@tonic-gate dev_t dev, 6020Sstevel@tonic-gate int cmd, 6030Sstevel@tonic-gate intptr_t data, 6040Sstevel@tonic-gate int mode, 6050Sstevel@tonic-gate cred_t *cred, 6060Sstevel@tonic-gate int *rval) 6070Sstevel@tonic-gate { 6080Sstevel@tonic-gate struct vgatext_softc *softc = getsoftc(DEV2INST(dev)); 6090Sstevel@tonic-gate static char kernel_only[] = "vgatext_ioctl: %s is a kernel only ioctl"; 6100Sstevel@tonic-gate int err; 6110Sstevel@tonic-gate int kd_mode; 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate switch (cmd) { 6140Sstevel@tonic-gate case KDSETMODE: 6150Sstevel@tonic-gate return (vgatext_kdsetmode(softc, (int)data)); 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate case KDGETMODE: 6180Sstevel@tonic-gate kd_mode = softc->mode; 6190Sstevel@tonic-gate if (ddi_copyout(&kd_mode, (void *)data, sizeof (int), mode)) 6200Sstevel@tonic-gate return (EFAULT); 6210Sstevel@tonic-gate break; 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate case VIS_GETIDENTIFIER: 6240Sstevel@tonic-gate if (ddi_copyout(&text_ident, (void *)data, 6250Sstevel@tonic-gate sizeof (struct vis_identifier), mode)) 6260Sstevel@tonic-gate return (EFAULT); 6270Sstevel@tonic-gate break; 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate case VIS_DEVINIT: 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 6320Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "VIS_DEVINIT"); 6330Sstevel@tonic-gate return (ENXIO); 6340Sstevel@tonic-gate } 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate err = vgatext_devinit(softc, (struct vis_devinit *)data); 6370Sstevel@tonic-gate if (err != 0) { 6380Sstevel@tonic-gate cmn_err(CE_WARN, 6390Sstevel@tonic-gate "vgatext_ioctl: could not initialize console"); 6400Sstevel@tonic-gate return (err); 6410Sstevel@tonic-gate } 6420Sstevel@tonic-gate break; 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate case VIS_CONSCOPY: /* move */ 6450Sstevel@tonic-gate { 6460Sstevel@tonic-gate struct vis_conscopy pma; 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate if (ddi_copyin((void *)data, &pma, 6490Sstevel@tonic-gate sizeof (struct vis_conscopy), mode)) 6500Sstevel@tonic-gate return (EFAULT); 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate vgatext_cons_copy(softc, &pma); 6530Sstevel@tonic-gate break; 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate case VIS_CONSDISPLAY: /* display */ 6570Sstevel@tonic-gate { 6580Sstevel@tonic-gate struct vis_consdisplay display_request; 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate if (ddi_copyin((void *)data, &display_request, 6610Sstevel@tonic-gate sizeof (display_request), mode)) 6620Sstevel@tonic-gate return (EFAULT); 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate vgatext_cons_display(softc, &display_request); 6650Sstevel@tonic-gate break; 6660Sstevel@tonic-gate } 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate case VIS_CONSCURSOR: 6690Sstevel@tonic-gate { 6700Sstevel@tonic-gate struct vis_conscursor cursor_request; 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate if (ddi_copyin((void *)data, &cursor_request, 6730Sstevel@tonic-gate sizeof (cursor_request), mode)) 6740Sstevel@tonic-gate return (EFAULT); 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate vgatext_cons_cursor(softc, &cursor_request); 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate if (cursor_request.action == VIS_GET_CURSOR && 6790Sstevel@tonic-gate ddi_copyout(&cursor_request, (void *)data, 6800Sstevel@tonic-gate sizeof (cursor_request), mode)) 6810Sstevel@tonic-gate return (EFAULT); 6820Sstevel@tonic-gate break; 6830Sstevel@tonic-gate } 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate case VIS_GETCMAP: 6860Sstevel@tonic-gate case VIS_PUTCMAP: 6870Sstevel@tonic-gate case FBIOPUTCMAP: 6880Sstevel@tonic-gate case FBIOGETCMAP: 6890Sstevel@tonic-gate /* 6900Sstevel@tonic-gate * At the moment, text mode is not considered to have 6910Sstevel@tonic-gate * a color map. 6920Sstevel@tonic-gate */ 6930Sstevel@tonic-gate return (EINVAL); 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate case FBIOGATTR: 6960Sstevel@tonic-gate if (copyout(&vgatext_attr, (void *)data, 6970Sstevel@tonic-gate sizeof (struct fbgattr))) 6980Sstevel@tonic-gate return (EFAULT); 6990Sstevel@tonic-gate break; 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate case FBIOGTYPE: 7020Sstevel@tonic-gate if (copyout(&vgatext_attr.fbtype, (void *)data, 7030Sstevel@tonic-gate sizeof (struct fbtype))) 7040Sstevel@tonic-gate return (EFAULT); 7050Sstevel@tonic-gate break; 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate #if 0 7080Sstevel@tonic-gate case GLY_LD_GLYPH: 7090Sstevel@tonic-gate { 7100Sstevel@tonic-gate temstat_t *ap; 7110Sstevel@tonic-gate da_t da; 7120Sstevel@tonic-gate struct glyph g; 7130Sstevel@tonic-gate int size; 7140Sstevel@tonic-gate uchar_t *c; 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate if (ddi_copyin(arg, &g, sizeof (g), flag)) 7170Sstevel@tonic-gate return (EFAULT); 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate size = g.width * g.height; 7200Sstevel@tonic-gate c = kmem_alloc(size, KM_SLEEP); 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate if (ddi_copyin(g.raster, c, size, flag)) { 7230Sstevel@tonic-gate kmem_free(c, size); 7240Sstevel@tonic-gate return (EFAULT); 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate ap = (temstat_t *)something; 7270Sstevel@tonic-gate da.data = c; 7280Sstevel@tonic-gate da.width = g.width; 7290Sstevel@tonic-gate da.height = g.height; 7300Sstevel@tonic-gate da.col = g.x_dest; 7310Sstevel@tonic-gate da.row = g.y_dest; 7320Sstevel@tonic-gate ap->a_fp.f_ad_display(ap->a_private, &da); 7330Sstevel@tonic-gate kmem_free(c, size); 7340Sstevel@tonic-gate return (0); 7350Sstevel@tonic-gate } 7360Sstevel@tonic-gate #endif 7370Sstevel@tonic-gate case DEVICE_DETECT: 7380Sstevel@tonic-gate { 7390Sstevel@tonic-gate agp_master_softc_t *agp_master; 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 7420Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "DEVICE_DETECT"); 7430Sstevel@tonic-gate return (ENXIO); 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate agp_master = softc->agp_master; 7460Sstevel@tonic-gate ASSERT(agp_master); 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate if (!agp_master) 7490Sstevel@tonic-gate return (EINVAL); 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate if (ddi_copyout(&agp_master->agpm_dev_type, 7520Sstevel@tonic-gate (void *)data, sizeof (int), mode)) 7530Sstevel@tonic-gate return (EFAULT); 7540Sstevel@tonic-gate break; 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate case I8XX_GET_INFO: 7570Sstevel@tonic-gate { 7580Sstevel@tonic-gate agp_master_softc_t *agp_master; 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 7610Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_GET_INFO"); 7620Sstevel@tonic-gate return (ENXIO); 7630Sstevel@tonic-gate } 7640Sstevel@tonic-gate agp_master = softc->agp_master; 7650Sstevel@tonic-gate ASSERT(agp_master); 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate if (!agp_master) 7680Sstevel@tonic-gate return (EINVAL); 769*1661Sms148562 ASSERT(IS_IGD(agp_master)); 7700Sstevel@tonic-gate 771*1661Sms148562 if (!IS_IGD(agp_master)) 7720Sstevel@tonic-gate return (EINVAL); 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate if (ddi_copyout(&agp_master->agpm_data.agpm_gtt.gtt_info, 775*1661Sms148562 (void *)data, sizeof (igd_info_t), mode)) 7760Sstevel@tonic-gate return (EFAULT); 7770Sstevel@tonic-gate break; 7780Sstevel@tonic-gate } 7790Sstevel@tonic-gate case I810_SET_GTT_BASE: 7800Sstevel@tonic-gate { 7810Sstevel@tonic-gate uint32_t base; 7820Sstevel@tonic-gate uint32_t addr; 7830Sstevel@tonic-gate agp_master_softc_t *agp_master; 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 7860Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_SET_GTT_ADDR"); 7870Sstevel@tonic-gate return (ENXIO); 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate agp_master = softc->agp_master; 7900Sstevel@tonic-gate ASSERT(agp_master); 7910Sstevel@tonic-gate if (!agp_master) 7920Sstevel@tonic-gate return (EINVAL); 7930Sstevel@tonic-gate ASSERT(agp_master->agpm_dev_type == DEVICE_IS_I810); 794*1661Sms148562 7950Sstevel@tonic-gate if (agp_master->agpm_dev_type != DEVICE_IS_I810) 7960Sstevel@tonic-gate return (EINVAL); 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate if (ddi_copyin((void *)data, &base, sizeof (uint32_t), mode)) 7990Sstevel@tonic-gate return (EFAULT); 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate /* enables page table */ 8020Sstevel@tonic-gate addr = (base & GTT_BASE_MASK) | GTT_TABLE_VALID; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate ddi_put32(agp_master->agpm_data.agpm_gtt.gtt_mmio_handle, 8050Sstevel@tonic-gate (uint32_t *)(agp_master->agpm_data.agpm_gtt.gtt_mmio_base + 8060Sstevel@tonic-gate I8XX_PGTBL_CTL), 8070Sstevel@tonic-gate addr); 8080Sstevel@tonic-gate break; 8090Sstevel@tonic-gate } 8100Sstevel@tonic-gate case I8XX_ADD2GTT: 8110Sstevel@tonic-gate { 8120Sstevel@tonic-gate igd_gtt_seg_t seg; 8130Sstevel@tonic-gate agp_master_softc_t *agp_master; 8140Sstevel@tonic-gate 8150Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 8160Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_ADD2GTT"); 8170Sstevel@tonic-gate return (ENXIO); 8180Sstevel@tonic-gate } 8190Sstevel@tonic-gate agp_master = softc->agp_master; 8200Sstevel@tonic-gate ASSERT(agp_master); 8210Sstevel@tonic-gate if (!agp_master) 8220Sstevel@tonic-gate return (EINVAL); 823*1661Sms148562 ASSERT(IS_IGD(agp_master)); 8240Sstevel@tonic-gate 825*1661Sms148562 if (!IS_IGD(agp_master)) 8260Sstevel@tonic-gate return (EINVAL); 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate if (ddi_copyin((void *)data, &seg, 8290Sstevel@tonic-gate sizeof (igd_gtt_seg_t), mode)) 8300Sstevel@tonic-gate return (EFAULT); 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate if (i8xx_add_to_gtt(&agp_master->agpm_data.agpm_gtt, seg)) 8330Sstevel@tonic-gate return (EINVAL); 8340Sstevel@tonic-gate break; 8350Sstevel@tonic-gate } 8360Sstevel@tonic-gate case I8XX_REM_GTT: 8370Sstevel@tonic-gate { 8380Sstevel@tonic-gate igd_gtt_seg_t seg; 8390Sstevel@tonic-gate agp_master_softc_t *agp_master; 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 8420Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_REM_GTT"); 8430Sstevel@tonic-gate return (ENXIO); 8440Sstevel@tonic-gate } 8450Sstevel@tonic-gate agp_master = softc->agp_master; 8460Sstevel@tonic-gate ASSERT(agp_master); 8470Sstevel@tonic-gate if (!agp_master) 8480Sstevel@tonic-gate return (EINVAL); 849*1661Sms148562 ASSERT(IS_IGD(agp_master)); 8500Sstevel@tonic-gate 851*1661Sms148562 if (!IS_IGD(agp_master)) 8520Sstevel@tonic-gate return (EINVAL); 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate if (ddi_copyin((void *)data, &seg, 8550Sstevel@tonic-gate sizeof (igd_gtt_seg_t), mode)) 8560Sstevel@tonic-gate return (EFAULT); 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate i8xx_remove_from_gtt(&agp_master->agpm_data.agpm_gtt, seg); 8590Sstevel@tonic-gate break; 8600Sstevel@tonic-gate } 8610Sstevel@tonic-gate case I8XX_UNCONFIG: 8620Sstevel@tonic-gate { 8630Sstevel@tonic-gate agp_master_softc_t *agp_master; 8640Sstevel@tonic-gate 8650Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 8660Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_UNCONFIG"); 8670Sstevel@tonic-gate return (ENXIO); 8680Sstevel@tonic-gate } 8690Sstevel@tonic-gate agp_master = softc->agp_master; 8700Sstevel@tonic-gate ASSERT(agp_master); 8710Sstevel@tonic-gate if (!agp_master) 8720Sstevel@tonic-gate return (EINVAL); 873*1661Sms148562 ASSERT(IS_IGD(agp_master)); 8740Sstevel@tonic-gate 875*1661Sms148562 if (!IS_IGD(agp_master)) 8760Sstevel@tonic-gate return (EINVAL); 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate if (agp_master->agpm_dev_type == DEVICE_IS_I810) 8790Sstevel@tonic-gate ddi_put32( 8800Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_mmio_handle, 8810Sstevel@tonic-gate (uint32_t *) 8820Sstevel@tonic-gate (agp_master->agpm_data.agpm_gtt.gtt_mmio_base + 8830Sstevel@tonic-gate I8XX_PGTBL_CTL), 8840Sstevel@tonic-gate 0); 8850Sstevel@tonic-gate /* 8860Sstevel@tonic-gate * may clear all gtt entries here for i830, 8870Sstevel@tonic-gate * but may not be necessary 8880Sstevel@tonic-gate */ 8890Sstevel@tonic-gate break; 8900Sstevel@tonic-gate } 8910Sstevel@tonic-gate case AGP_MASTER_GETINFO: 8920Sstevel@tonic-gate { 8930Sstevel@tonic-gate agp_info_t info; 8940Sstevel@tonic-gate uint32_t value; 8950Sstevel@tonic-gate off_t cap; 8960Sstevel@tonic-gate agp_master_softc_t *agp_master; 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 8990Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "AGP_MASTER_GETINFO"); 9000Sstevel@tonic-gate return (ENXIO); 9010Sstevel@tonic-gate } 9020Sstevel@tonic-gate agp_master = softc->agp_master; 9030Sstevel@tonic-gate ASSERT(agp_master); 9040Sstevel@tonic-gate if (!agp_master) 9050Sstevel@tonic-gate return (EINVAL); 9060Sstevel@tonic-gate ASSERT(agp_master->agpm_dev_type == DEVICE_IS_AGP); 9070Sstevel@tonic-gate if (agp_master->agpm_dev_type != DEVICE_IS_AGP) 9080Sstevel@tonic-gate return (EINVAL); 9090Sstevel@tonic-gate 9100Sstevel@tonic-gate ASSERT(agp_master->agpm_data.agpm_acaptr); 9110Sstevel@tonic-gate if (agp_master->agpm_data.agpm_acaptr == 0) 9120Sstevel@tonic-gate return (EINVAL); 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate cap = agp_master->agpm_data.agpm_acaptr; 9150Sstevel@tonic-gate value = pci_config_get32(agp_master->agpm_acc_hdl, cap); 9160Sstevel@tonic-gate info.agpi_version.agpv_major = (uint16_t)((value >> 20) & 0xf); 9170Sstevel@tonic-gate info.agpi_version.agpv_minor = (uint16_t)((value >> 16) & 0xf); 9180Sstevel@tonic-gate info.agpi_devid = agp_master->agpm_id; 9190Sstevel@tonic-gate info.agpi_mode = pci_config_get32( 9200Sstevel@tonic-gate agp_master->agpm_acc_hdl, cap + AGP_CONF_STATUS); 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate if (ddi_copyout(&info, (void *)data, 9230Sstevel@tonic-gate sizeof (agp_info_t), mode)) 9240Sstevel@tonic-gate return (EFAULT); 9250Sstevel@tonic-gate break; 9260Sstevel@tonic-gate } 9270Sstevel@tonic-gate case AGP_MASTER_SETCMD: 9280Sstevel@tonic-gate { 9290Sstevel@tonic-gate uint32_t command; 9300Sstevel@tonic-gate agp_master_softc_t *agp_master; 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 9330Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "AGP_MASTER_SETCMD"); 9340Sstevel@tonic-gate return (ENXIO); 9350Sstevel@tonic-gate } 9360Sstevel@tonic-gate agp_master = softc->agp_master; 9370Sstevel@tonic-gate ASSERT(agp_master); 9380Sstevel@tonic-gate if (!agp_master) 9390Sstevel@tonic-gate return (EINVAL); 9400Sstevel@tonic-gate ASSERT(agp_master->agpm_dev_type == DEVICE_IS_AGP); 9410Sstevel@tonic-gate if (agp_master->agpm_dev_type != DEVICE_IS_AGP) 9420Sstevel@tonic-gate return (EINVAL); 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate ASSERT(agp_master->agpm_data.agpm_acaptr); 9450Sstevel@tonic-gate if (agp_master->agpm_data.agpm_acaptr == 0) 9460Sstevel@tonic-gate return (EINVAL); 9470Sstevel@tonic-gate 9480Sstevel@tonic-gate if (ddi_copyin((void *)data, &command, 9490Sstevel@tonic-gate sizeof (uint32_t), mode)) 9500Sstevel@tonic-gate return (EFAULT); 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate pci_config_put32(agp_master->agpm_acc_hdl, 9530Sstevel@tonic-gate agp_master->agpm_data.agpm_acaptr + AGP_CONF_COMMAND, 9540Sstevel@tonic-gate command); 9550Sstevel@tonic-gate break; 9560Sstevel@tonic-gate 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate default: 9590Sstevel@tonic-gate return (ENXIO); 9600Sstevel@tonic-gate } 9610Sstevel@tonic-gate return (0); 9620Sstevel@tonic-gate } 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate static int 9650Sstevel@tonic-gate vgatext_kdsetmode(struct vgatext_softc *softc, int mode) 9660Sstevel@tonic-gate { 9670Sstevel@tonic-gate int i; 9680Sstevel@tonic-gate 9690Sstevel@tonic-gate if (mode == softc->mode) 9700Sstevel@tonic-gate return (0); 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate switch (mode) { 9730Sstevel@tonic-gate case KD_TEXT: 9740Sstevel@tonic-gate vgatext_init(softc); 9750Sstevel@tonic-gate for (i = 0; i < sizeof (softc->shadow); i++) { 9760Sstevel@tonic-gate softc->text_base[i] = softc->shadow[i]; 9770Sstevel@tonic-gate } 9780Sstevel@tonic-gate softc->current_base = softc->text_base; 9790Sstevel@tonic-gate if (softc->cursor.visible) { 9800Sstevel@tonic-gate vgatext_set_cursor(softc, 9810Sstevel@tonic-gate softc->cursor.row, softc->cursor.col); 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate vgatext_restore_colormap(softc); 9840Sstevel@tonic-gate break; 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate case KD_GRAPHICS: 9870Sstevel@tonic-gate if (vgatext_silent == 1) { 9880Sstevel@tonic-gate extern void progressbar_stop(void); 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate vgatext_silent = 0; 9910Sstevel@tonic-gate progressbar_stop(); 9920Sstevel@tonic-gate } 9930Sstevel@tonic-gate for (i = 0; i < sizeof (softc->shadow); i++) { 9940Sstevel@tonic-gate softc->shadow[i] = softc->text_base[i]; 9950Sstevel@tonic-gate } 9960Sstevel@tonic-gate softc->current_base = softc->shadow; 9970Sstevel@tonic-gate #if defined(USE_BORDERS) 9980Sstevel@tonic-gate vgatext_init_graphics(softc); 9990Sstevel@tonic-gate #endif 10000Sstevel@tonic-gate break; 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate default: 10030Sstevel@tonic-gate return (EINVAL); 10040Sstevel@tonic-gate } 10050Sstevel@tonic-gate softc->mode = mode; 10060Sstevel@tonic-gate return (0); 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate /*ARGSUSED*/ 10100Sstevel@tonic-gate static int 10110Sstevel@tonic-gate vgatext_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len, 10120Sstevel@tonic-gate size_t *maplen, uint_t model) 10130Sstevel@tonic-gate { 10140Sstevel@tonic-gate struct vgatext_softc *softc; 10150Sstevel@tonic-gate int err; 10160Sstevel@tonic-gate size_t length; 10170Sstevel@tonic-gate 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate softc = getsoftc(DEV2INST(dev)); 10200Sstevel@tonic-gate if (softc == NULL) { 10210Sstevel@tonic-gate cmn_err(CE_WARN, "vgatext: Can't find softstate"); 10220Sstevel@tonic-gate return (-1); 10230Sstevel@tonic-gate } 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate if (!(off >= VGA_MMAP_FB_BASE && 10260Sstevel@tonic-gate off < VGA_MMAP_FB_BASE + softc->fb_size)) { 10270Sstevel@tonic-gate cmn_err(CE_WARN, "vgatext: Can't map offset 0x%llx", off); 10280Sstevel@tonic-gate return (-1); 10290Sstevel@tonic-gate } 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate if (off + len > VGA_MMAP_FB_BASE + softc->fb_size) 10320Sstevel@tonic-gate length = VGA_MMAP_FB_BASE + softc->fb_size - off; 10330Sstevel@tonic-gate else 10340Sstevel@tonic-gate length = len; 10350Sstevel@tonic-gate 10360Sstevel@tonic-gate if ((err = devmap_devmem_setup(dhp, softc->devi, NULL, softc->fb_regno, 10370Sstevel@tonic-gate off - VGA_MMAP_FB_BASE, 10380Sstevel@tonic-gate length, PROT_ALL, 0, &dev_attr)) < 0) { 10390Sstevel@tonic-gate return (err); 10400Sstevel@tonic-gate } 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate *maplen = length; 10440Sstevel@tonic-gate return (0); 10450Sstevel@tonic-gate } 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate 10480Sstevel@tonic-gate static int 10490Sstevel@tonic-gate vgatext_devinit(struct vgatext_softc *softc, struct vis_devinit *data) 10500Sstevel@tonic-gate { 10510Sstevel@tonic-gate /* initialize console instance */ 10520Sstevel@tonic-gate data->version = VIS_CONS_REV; 10530Sstevel@tonic-gate data->width = TEXT_COLS; 10540Sstevel@tonic-gate data->height = TEXT_ROWS; 10550Sstevel@tonic-gate data->linebytes = TEXT_COLS; 10560Sstevel@tonic-gate data->depth = 4; 10570Sstevel@tonic-gate data->mode = VIS_TEXT; 10580Sstevel@tonic-gate data->polledio = &softc->polledio; 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate return (0); 10610Sstevel@tonic-gate } 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate /* 10640Sstevel@tonic-gate * display a string on the screen at (row, col) 10650Sstevel@tonic-gate * assume it has been cropped to fit. 10660Sstevel@tonic-gate */ 10670Sstevel@tonic-gate 10680Sstevel@tonic-gate static void 10690Sstevel@tonic-gate vgatext_cons_display(struct vgatext_softc *softc, struct vis_consdisplay *da) 10700Sstevel@tonic-gate { 10710Sstevel@tonic-gate unsigned char *string; 10720Sstevel@tonic-gate int i; 10730Sstevel@tonic-gate unsigned char attr; 10740Sstevel@tonic-gate struct cgatext { 10750Sstevel@tonic-gate unsigned char ch; 10760Sstevel@tonic-gate unsigned char attr; 10770Sstevel@tonic-gate }; 10780Sstevel@tonic-gate struct cgatext *addr; 10790Sstevel@tonic-gate 10800Sstevel@tonic-gate if (vgatext_silent) 10810Sstevel@tonic-gate return; 10820Sstevel@tonic-gate /* 10830Sstevel@tonic-gate * Sanity checks. This is a last-ditch effort to avoid damage 10840Sstevel@tonic-gate * from brokenness or maliciousness above. 10850Sstevel@tonic-gate */ 10860Sstevel@tonic-gate if (da->row < 0 || da->row >= TEXT_ROWS || 10870Sstevel@tonic-gate da->col < 0 || da->col >= TEXT_COLS || 10880Sstevel@tonic-gate da->col + da->width > TEXT_COLS) 10890Sstevel@tonic-gate return; 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /* 10920Sstevel@tonic-gate * To be fully general, we should copyin the data. This is not 10930Sstevel@tonic-gate * really relevant for this text-only driver, but a graphical driver 10940Sstevel@tonic-gate * should support these ioctls from userland to enable simple 10950Sstevel@tonic-gate * system startup graphics. 10960Sstevel@tonic-gate */ 10970Sstevel@tonic-gate attr = (solaris_color_to_pc_color[da->bg_color & 0xf] << 4) 10980Sstevel@tonic-gate | solaris_color_to_pc_color[da->fg_color & 0xf]; 10990Sstevel@tonic-gate string = da->data; 11000Sstevel@tonic-gate addr = (struct cgatext *)softc->current_base 11010Sstevel@tonic-gate + (da->row * TEXT_COLS + da->col); 11020Sstevel@tonic-gate for (i = 0; i < da->width; i++) { 11030Sstevel@tonic-gate addr->ch = string[i]; 11040Sstevel@tonic-gate addr->attr = attr; 11050Sstevel@tonic-gate addr++; 11060Sstevel@tonic-gate } 11070Sstevel@tonic-gate } 11080Sstevel@tonic-gate 11090Sstevel@tonic-gate static void 11100Sstevel@tonic-gate vgatext_polled_display( 11110Sstevel@tonic-gate struct vis_polledio_arg *arg, 11120Sstevel@tonic-gate struct vis_consdisplay *da) 11130Sstevel@tonic-gate { 11140Sstevel@tonic-gate vgatext_cons_display((struct vgatext_softc *)arg, da); 11150Sstevel@tonic-gate } 11160Sstevel@tonic-gate 11170Sstevel@tonic-gate /* 11180Sstevel@tonic-gate * screen-to-screen copy 11190Sstevel@tonic-gate */ 11200Sstevel@tonic-gate 11210Sstevel@tonic-gate static void 11220Sstevel@tonic-gate vgatext_cons_copy(struct vgatext_softc *softc, struct vis_conscopy *ma) 11230Sstevel@tonic-gate { 11240Sstevel@tonic-gate unsigned short *from; 11250Sstevel@tonic-gate unsigned short *to; 11260Sstevel@tonic-gate int cnt; 11270Sstevel@tonic-gate screen_size_t chars_per_row; 11280Sstevel@tonic-gate unsigned short *to_row_start; 11290Sstevel@tonic-gate unsigned short *from_row_start; 11300Sstevel@tonic-gate screen_size_t rows_to_move; 11310Sstevel@tonic-gate unsigned short *base; 11320Sstevel@tonic-gate 11330Sstevel@tonic-gate if (vgatext_silent) 11340Sstevel@tonic-gate return; 11350Sstevel@tonic-gate 11360Sstevel@tonic-gate /* 11370Sstevel@tonic-gate * Sanity checks. Note that this is a last-ditch effort to avoid 11380Sstevel@tonic-gate * damage caused by broken-ness or maliciousness above. 11390Sstevel@tonic-gate */ 11400Sstevel@tonic-gate if (ma->s_col < 0 || ma->s_col >= TEXT_COLS || 11410Sstevel@tonic-gate ma->s_row < 0 || ma->s_row >= TEXT_ROWS || 11420Sstevel@tonic-gate ma->e_col < 0 || ma->e_col >= TEXT_COLS || 11430Sstevel@tonic-gate ma->e_row < 0 || ma->e_row >= TEXT_ROWS || 11440Sstevel@tonic-gate ma->t_col < 0 || ma->t_col >= TEXT_COLS || 11450Sstevel@tonic-gate ma->t_row < 0 || ma->t_row >= TEXT_ROWS || 11460Sstevel@tonic-gate ma->s_col > ma->e_col || 11470Sstevel@tonic-gate ma->s_row > ma->e_row) 11480Sstevel@tonic-gate return; 11490Sstevel@tonic-gate 11500Sstevel@tonic-gate /* 11510Sstevel@tonic-gate * Remember we're going to copy shorts because each 11520Sstevel@tonic-gate * character/attribute pair is 16 bits. 11530Sstevel@tonic-gate */ 11540Sstevel@tonic-gate chars_per_row = ma->e_col - ma->s_col + 1; 11550Sstevel@tonic-gate rows_to_move = ma->e_row - ma->s_row + 1; 11560Sstevel@tonic-gate 11570Sstevel@tonic-gate /* More sanity checks. */ 11580Sstevel@tonic-gate if (ma->t_row + rows_to_move > TEXT_ROWS || 11590Sstevel@tonic-gate ma->t_col + chars_per_row > TEXT_COLS) 11600Sstevel@tonic-gate return; 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate base = (unsigned short *)softc->current_base; 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate to_row_start = base + ((ma->t_row * TEXT_COLS) + ma->t_col); 11650Sstevel@tonic-gate from_row_start = base + ((ma->s_row * TEXT_COLS) + ma->s_col); 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate if (to_row_start < from_row_start) { 11680Sstevel@tonic-gate while (rows_to_move-- > 0) { 11690Sstevel@tonic-gate to = to_row_start; 11700Sstevel@tonic-gate from = from_row_start; 11710Sstevel@tonic-gate to_row_start += TEXT_COLS; 11720Sstevel@tonic-gate from_row_start += TEXT_COLS; 11730Sstevel@tonic-gate for (cnt = chars_per_row; cnt-- > 0; ) 11740Sstevel@tonic-gate *to++ = *from++; 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate } else { 11770Sstevel@tonic-gate /* 11780Sstevel@tonic-gate * Offset to the end of the region and copy backwards. 11790Sstevel@tonic-gate */ 11800Sstevel@tonic-gate cnt = rows_to_move * TEXT_COLS + chars_per_row; 11810Sstevel@tonic-gate to_row_start += cnt; 11820Sstevel@tonic-gate from_row_start += cnt; 11830Sstevel@tonic-gate 11840Sstevel@tonic-gate while (rows_to_move-- > 0) { 11850Sstevel@tonic-gate to_row_start -= TEXT_COLS; 11860Sstevel@tonic-gate from_row_start -= TEXT_COLS; 11870Sstevel@tonic-gate to = to_row_start; 11880Sstevel@tonic-gate from = from_row_start; 11890Sstevel@tonic-gate for (cnt = chars_per_row; cnt-- > 0; ) 11900Sstevel@tonic-gate *--to = *--from; 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate } 11930Sstevel@tonic-gate } 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate static void 11960Sstevel@tonic-gate vgatext_polled_copy( 11970Sstevel@tonic-gate struct vis_polledio_arg *arg, 11980Sstevel@tonic-gate struct vis_conscopy *ca) 11990Sstevel@tonic-gate { 12000Sstevel@tonic-gate vgatext_cons_copy((struct vgatext_softc *)arg, ca); 12010Sstevel@tonic-gate } 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate 12040Sstevel@tonic-gate static void 12050Sstevel@tonic-gate vgatext_cons_cursor(struct vgatext_softc *softc, struct vis_conscursor *ca) 12060Sstevel@tonic-gate { 12070Sstevel@tonic-gate if (vgatext_silent) 12080Sstevel@tonic-gate return; 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate switch (ca->action) { 12110Sstevel@tonic-gate case VIS_HIDE_CURSOR: 12120Sstevel@tonic-gate softc->cursor.visible = B_FALSE; 12130Sstevel@tonic-gate if (softc->current_base == softc->text_base) 12140Sstevel@tonic-gate vgatext_hide_cursor(softc); 12150Sstevel@tonic-gate break; 12160Sstevel@tonic-gate case VIS_DISPLAY_CURSOR: 12170Sstevel@tonic-gate /* 12180Sstevel@tonic-gate * Sanity check. This is a last-ditch effort to avoid 12190Sstevel@tonic-gate * damage from brokenness or maliciousness above. 12200Sstevel@tonic-gate */ 12210Sstevel@tonic-gate if (ca->col < 0 || ca->col >= TEXT_COLS || 12220Sstevel@tonic-gate ca->row < 0 || ca->row >= TEXT_ROWS) 12230Sstevel@tonic-gate return; 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate softc->cursor.visible = B_TRUE; 12260Sstevel@tonic-gate softc->cursor.col = ca->col; 12270Sstevel@tonic-gate softc->cursor.row = ca->row; 12280Sstevel@tonic-gate if (softc->current_base == softc->text_base) 12290Sstevel@tonic-gate vgatext_set_cursor(softc, ca->row, ca->col); 12300Sstevel@tonic-gate break; 12310Sstevel@tonic-gate case VIS_GET_CURSOR: 12320Sstevel@tonic-gate if (softc->current_base == softc->text_base) { 12330Sstevel@tonic-gate vgatext_get_cursor(softc, &ca->row, &ca->col); 12340Sstevel@tonic-gate } 12350Sstevel@tonic-gate break; 12360Sstevel@tonic-gate } 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate 12390Sstevel@tonic-gate static void 12400Sstevel@tonic-gate vgatext_polled_cursor( 12410Sstevel@tonic-gate struct vis_polledio_arg *arg, 12420Sstevel@tonic-gate struct vis_conscursor *ca) 12430Sstevel@tonic-gate { 12440Sstevel@tonic-gate vgatext_cons_cursor((struct vgatext_softc *)arg, ca); 12450Sstevel@tonic-gate } 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate /*ARGSUSED*/ 12500Sstevel@tonic-gate static void 12510Sstevel@tonic-gate vgatext_hide_cursor(struct vgatext_softc *softc) 12520Sstevel@tonic-gate { 12530Sstevel@tonic-gate /* Nothing at present */ 12540Sstevel@tonic-gate } 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate static void 12570Sstevel@tonic-gate vgatext_set_cursor(struct vgatext_softc *softc, int row, int col) 12580Sstevel@tonic-gate { 12590Sstevel@tonic-gate short addr; 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate if (vgatext_silent) 12620Sstevel@tonic-gate return; 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate addr = row * TEXT_COLS + col; 12650Sstevel@tonic-gate 12660Sstevel@tonic-gate vga_set_crtc(&softc->regs, VGA_CRTC_CLAH, addr >> 8); 12670Sstevel@tonic-gate vga_set_crtc(&softc->regs, VGA_CRTC_CLAL, addr & 0xff); 12680Sstevel@tonic-gate } 12690Sstevel@tonic-gate 12700Sstevel@tonic-gate static int vga_row, vga_col; 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate static void 12730Sstevel@tonic-gate vgatext_get_cursor(struct vgatext_softc *softc, 12740Sstevel@tonic-gate screen_pos_t *row, screen_pos_t *col) 12750Sstevel@tonic-gate { 12760Sstevel@tonic-gate short addr; 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate addr = (vga_get_crtc(&softc->regs, VGA_CRTC_CLAH) << 8) + 12790Sstevel@tonic-gate vga_get_crtc(&softc->regs, VGA_CRTC_CLAL); 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate vga_row = *row = addr / TEXT_COLS; 12820Sstevel@tonic-gate vga_col = *col = addr % TEXT_COLS; 12830Sstevel@tonic-gate } 12840Sstevel@tonic-gate 12850Sstevel@tonic-gate /* 12860Sstevel@tonic-gate * This code is experimental. It's only enabled if console is 12870Sstevel@tonic-gate * set to graphics, a preliminary implementation of happyface boot. 12880Sstevel@tonic-gate */ 12890Sstevel@tonic-gate static void 12900Sstevel@tonic-gate vgatext_set_text(struct vgatext_softc *softc) 12910Sstevel@tonic-gate { 12920Sstevel@tonic-gate int i; 12930Sstevel@tonic-gate 12940Sstevel@tonic-gate if (happyface_boot == 0) 12950Sstevel@tonic-gate return; 12960Sstevel@tonic-gate 12970Sstevel@tonic-gate /* we are in graphics mode, set to text 80X25 mode */ 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate /* set misc registers */ 13000Sstevel@tonic-gate vga_set_reg(&softc->regs, VGA_MISC_W, VGA_MISC_TEXT); 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate /* set sequencer registers */ 13030Sstevel@tonic-gate vga_set_seq(&softc->regs, VGA_SEQ_RST_SYN, 13040Sstevel@tonic-gate (vga_get_seq(&softc->regs, VGA_SEQ_RST_SYN) & 13050Sstevel@tonic-gate ~VGA_SEQ_RST_SYN_NO_SYNC_RESET)); 13060Sstevel@tonic-gate for (i = 1; i < NUM_SEQ_REG; i++) { 13070Sstevel@tonic-gate vga_set_seq(&softc->regs, i, VGA_SEQ_TEXT[i]); 13080Sstevel@tonic-gate } 13090Sstevel@tonic-gate vga_set_seq(&softc->regs, VGA_SEQ_RST_SYN, 13100Sstevel@tonic-gate (vga_get_seq(&softc->regs, VGA_SEQ_RST_SYN) | 13110Sstevel@tonic-gate VGA_SEQ_RST_SYN_NO_ASYNC_RESET | 13120Sstevel@tonic-gate VGA_SEQ_RST_SYN_NO_SYNC_RESET)); 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate /* set crt controller registers */ 13150Sstevel@tonic-gate vga_set_crtc(&softc->regs, VGA_CRTC_VRE, 13160Sstevel@tonic-gate (vga_get_crtc(&softc->regs, VGA_CRTC_VRE) & 13170Sstevel@tonic-gate ~VGA_CRTC_VRE_LOCK)); 13180Sstevel@tonic-gate for (i = 0; i < NUM_CRTC_REG; i++) { 13190Sstevel@tonic-gate vga_set_crtc(&softc->regs, i, VGA_CRTC_TEXT[i]); 13200Sstevel@tonic-gate } 13210Sstevel@tonic-gate 13220Sstevel@tonic-gate /* set graphics controller registers */ 13230Sstevel@tonic-gate for (i = 0; i < NUM_GRC_REG; i++) { 13240Sstevel@tonic-gate vga_set_grc(&softc->regs, i, VGA_GRC_TEXT[i]); 13250Sstevel@tonic-gate } 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate /* set attribute registers */ 13280Sstevel@tonic-gate for (i = 0; i < NUM_ATR_REG; i++) { 13290Sstevel@tonic-gate vga_set_atr(&softc->regs, i, VGA_ATR_TEXT[i]); 13300Sstevel@tonic-gate } 13310Sstevel@tonic-gate 13320Sstevel@tonic-gate /* set palette */ 13330Sstevel@tonic-gate for (i = 0; i < VGA_TEXT_CMAP_ENTRIES; i++) { 13340Sstevel@tonic-gate vga_put_cmap(&softc->regs, i, VGA_TEXT_PALETTES[i][0] << 2, 13350Sstevel@tonic-gate VGA_TEXT_PALETTES[i][1] << 2, 13360Sstevel@tonic-gate VGA_TEXT_PALETTES[i][2] << 2); 13370Sstevel@tonic-gate } 13380Sstevel@tonic-gate for (i = VGA_TEXT_CMAP_ENTRIES; i < VGA8_CMAP_ENTRIES; i++) { 13390Sstevel@tonic-gate vga_put_cmap(&softc->regs, i, 0, 0, 0); 13400Sstevel@tonic-gate } 13410Sstevel@tonic-gate 13420Sstevel@tonic-gate vgatext_save_colormap(softc); 13430Sstevel@tonic-gate } 13440Sstevel@tonic-gate 13450Sstevel@tonic-gate static void 13460Sstevel@tonic-gate vgatext_init(struct vgatext_softc *softc) 13470Sstevel@tonic-gate { 13480Sstevel@tonic-gate unsigned char atr_mode; 13490Sstevel@tonic-gate 13500Sstevel@tonic-gate atr_mode = vga_get_atr(&softc->regs, VGA_ATR_MODE); 13510Sstevel@tonic-gate if (atr_mode & VGA_ATR_MODE_GRAPH) 13520Sstevel@tonic-gate vgatext_set_text(softc); 13530Sstevel@tonic-gate atr_mode = vga_get_atr(&softc->regs, VGA_ATR_MODE); 13540Sstevel@tonic-gate atr_mode &= ~VGA_ATR_MODE_BLINK; 13550Sstevel@tonic-gate atr_mode &= ~VGA_ATR_MODE_9WIDE; 13560Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_MODE, atr_mode); 13570Sstevel@tonic-gate #if defined(USE_BORDERS) 13580Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR, 13590Sstevel@tonic-gate vga_get_atr(&softc->regs, VGA_BRIGHT_WHITE)); 13600Sstevel@tonic-gate #else 13610Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR, 13620Sstevel@tonic-gate vga_get_atr(&softc->regs, VGA_BLACK)); 13630Sstevel@tonic-gate #endif 13640Sstevel@tonic-gate vgatext_setfont(softc); /* need selectable font? */ 13650Sstevel@tonic-gate } 13660Sstevel@tonic-gate 13670Sstevel@tonic-gate #if defined(USE_BORDERS) 13680Sstevel@tonic-gate static void 13690Sstevel@tonic-gate vgatext_init_graphics(struct vgatext_softc *softc) 13700Sstevel@tonic-gate { 13710Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR, 13720Sstevel@tonic-gate vga_get_atr(&softc->regs, VGA_BLACK)); 13730Sstevel@tonic-gate } 13740Sstevel@tonic-gate #endif 13750Sstevel@tonic-gate 137625Sszhou static char vga_fontslot = 0; 137725Sszhou 13780Sstevel@tonic-gate static void 13790Sstevel@tonic-gate vgatext_setfont(struct vgatext_softc *softc) 13800Sstevel@tonic-gate { 138125Sszhou static uchar_t fsreg[8] = {0x0, 0x30, 0x5, 0x35, 0xa, 0x3a, 0xf, 0x3f}; 138225Sszhou 13830Sstevel@tonic-gate extern unsigned char *ENCODINGS[]; 138425Sszhou uchar_t *from; 138525Sszhou uchar_t volatile *to; 138625Sszhou int i, j, s; 138725Sszhou int bpc, f_offset; 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate /* Sync-reset the sequencer registers */ 13900Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x01); 13910Sstevel@tonic-gate /* 13920Sstevel@tonic-gate * enable write to plane2, since fonts 13930Sstevel@tonic-gate * could only be loaded into plane2 13940Sstevel@tonic-gate */ 13950Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x02, 0x04); 13960Sstevel@tonic-gate /* 13970Sstevel@tonic-gate * sequentially access data in the bit map being 13980Sstevel@tonic-gate * selected by MapMask register (index 0x02) 13990Sstevel@tonic-gate */ 14000Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x04, 0x07); 14010Sstevel@tonic-gate /* Sync-reset ended, and allow the sequencer to operate */ 14020Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x03); 14030Sstevel@tonic-gate 14040Sstevel@tonic-gate /* 14050Sstevel@tonic-gate * select plane 2 on Read Mode 0 14060Sstevel@tonic-gate */ 14070Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x04, 0x02); 14080Sstevel@tonic-gate /* 14090Sstevel@tonic-gate * system addresses sequentially access data, follow 14100Sstevel@tonic-gate * Memory Mode register bit 2 in the sequencer 14110Sstevel@tonic-gate */ 14120Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x05, 0x00); 14130Sstevel@tonic-gate /* 14140Sstevel@tonic-gate * set range of host memory addresses decoded by VGA 14150Sstevel@tonic-gate * hardware -- A0000h-BFFFFh (128K region) 14160Sstevel@tonic-gate */ 14170Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x06, 0x00); 14180Sstevel@tonic-gate 14190Sstevel@tonic-gate /* 14200Sstevel@tonic-gate * This assumes 8x16 characters, which yield the traditional 80x25 14210Sstevel@tonic-gate * screen. It really should support other character heights. 14220Sstevel@tonic-gate */ 14230Sstevel@tonic-gate bpc = 16; 142425Sszhou s = vga_fontslot; 142525Sszhou f_offset = s * 8 * 1024; 14260Sstevel@tonic-gate for (i = 0; i < 256; i++) { 14270Sstevel@tonic-gate from = ENCODINGS[i]; 142825Sszhou to = (unsigned char *)softc->fb.addr + f_offset + i * 0x20; 14290Sstevel@tonic-gate for (j = 0; j < bpc; j++) 14300Sstevel@tonic-gate *to++ = *from++; 14310Sstevel@tonic-gate } 14320Sstevel@tonic-gate 14330Sstevel@tonic-gate /* Sync-reset the sequencer registers */ 14340Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x01); 14350Sstevel@tonic-gate /* enable write to plane 0 and 1 */ 14360Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x02, 0x03); 14370Sstevel@tonic-gate /* 14380Sstevel@tonic-gate * enable character map selection 14390Sstevel@tonic-gate * and odd/even addressing 14400Sstevel@tonic-gate */ 14410Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x04, 0x03); 14420Sstevel@tonic-gate /* 144325Sszhou * select font map 14440Sstevel@tonic-gate */ 144525Sszhou vga_set_seq(&softc->regs, 0x03, fsreg[s]); 14460Sstevel@tonic-gate /* Sync-reset ended, and allow the sequencer to operate */ 14470Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x03); 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate /* restore graphic registers */ 14500Sstevel@tonic-gate 14510Sstevel@tonic-gate /* select plane 0 */ 14520Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x04, 0x00); 14530Sstevel@tonic-gate /* enable odd/even addressing mode */ 14540Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x05, 0x10); 14550Sstevel@tonic-gate /* 14560Sstevel@tonic-gate * range of host memory addresses decoded by VGA 14570Sstevel@tonic-gate * hardware -- B8000h-BFFFFh (32K region) 14580Sstevel@tonic-gate */ 14590Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x06, 0x0e); 14600Sstevel@tonic-gate /* enable all color plane */ 14610Sstevel@tonic-gate vga_set_atr(&softc->regs, 0x12, 0x0f); 14620Sstevel@tonic-gate 14630Sstevel@tonic-gate } 14640Sstevel@tonic-gate 14650Sstevel@tonic-gate static void 14660Sstevel@tonic-gate vgatext_save_colormap(struct vgatext_softc *softc) 14670Sstevel@tonic-gate { 14680Sstevel@tonic-gate int i; 14690Sstevel@tonic-gate 14700Sstevel@tonic-gate for (i = 0; i < VGA_ATR_NUM_PLT; i++) { 14710Sstevel@tonic-gate softc->attrib_palette[i] = vga_get_atr(&softc->regs, i); 14720Sstevel@tonic-gate } 14730Sstevel@tonic-gate for (i = 0; i < VGA8_CMAP_ENTRIES; i++) { 14740Sstevel@tonic-gate vga_get_cmap(&softc->regs, i, 14750Sstevel@tonic-gate &softc->colormap[i].red, 14760Sstevel@tonic-gate &softc->colormap[i].green, 14770Sstevel@tonic-gate &softc->colormap[i].blue); 14780Sstevel@tonic-gate } 14790Sstevel@tonic-gate } 14800Sstevel@tonic-gate 14810Sstevel@tonic-gate static void 14820Sstevel@tonic-gate vgatext_restore_colormap(struct vgatext_softc *softc) 14830Sstevel@tonic-gate { 14840Sstevel@tonic-gate int i; 14850Sstevel@tonic-gate 14860Sstevel@tonic-gate for (i = 0; i < VGA_ATR_NUM_PLT; i++) { 14870Sstevel@tonic-gate vga_set_atr(&softc->regs, i, softc->attrib_palette[i]); 14880Sstevel@tonic-gate } 14890Sstevel@tonic-gate for (i = 0; i < VGA8_CMAP_ENTRIES; i++) { 14900Sstevel@tonic-gate vga_put_cmap(&softc->regs, i, 14910Sstevel@tonic-gate softc->colormap[i].red, 14920Sstevel@tonic-gate softc->colormap[i].green, 14930Sstevel@tonic-gate softc->colormap[i].blue); 14940Sstevel@tonic-gate } 14950Sstevel@tonic-gate } 14960Sstevel@tonic-gate 14970Sstevel@tonic-gate /* 14980Sstevel@tonic-gate * search the entries of the "reg" property for one which has the desired 14990Sstevel@tonic-gate * combination of phys_hi bits and contains the desired address. 15000Sstevel@tonic-gate * 15010Sstevel@tonic-gate * This version searches a PCI-style "reg" property. It was prompted by 15020Sstevel@tonic-gate * issues surrounding the presence or absence of an entry for the ROM: 15030Sstevel@tonic-gate * (a) a transition problem with PowerPC Virtual Open Firmware 15040Sstevel@tonic-gate * (b) uncertainty as to whether an entry will be included on a device 15050Sstevel@tonic-gate * with ROM support (and so an "active" ROM base address register), 15060Sstevel@tonic-gate * but no ROM actually installed. 15070Sstevel@tonic-gate * 15080Sstevel@tonic-gate * See the note below on vgatext_get_isa_reg_index for the reasons for 15090Sstevel@tonic-gate * returning the offset. 15100Sstevel@tonic-gate * 15110Sstevel@tonic-gate * Note that this routine may not be fully general; it is intended for the 15120Sstevel@tonic-gate * specific purpose of finding a couple of particular VGA reg entries and 15130Sstevel@tonic-gate * may not be suitable for all reg-searching purposes. 15140Sstevel@tonic-gate */ 15150Sstevel@tonic-gate static int 15160Sstevel@tonic-gate vgatext_get_pci_reg_index( 15170Sstevel@tonic-gate dev_info_t *const devi, 15180Sstevel@tonic-gate unsigned long himask, 15190Sstevel@tonic-gate unsigned long hival, 15200Sstevel@tonic-gate unsigned long addr, 15210Sstevel@tonic-gate off_t *offset) 15220Sstevel@tonic-gate { 15230Sstevel@tonic-gate 15240Sstevel@tonic-gate int length, index; 15250Sstevel@tonic-gate pci_regspec_t *reg; 15260Sstevel@tonic-gate 15270Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 15280Sstevel@tonic-gate "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) { 15290Sstevel@tonic-gate return (-1); 15300Sstevel@tonic-gate } 15310Sstevel@tonic-gate 15320Sstevel@tonic-gate for (index = 0; index < length / sizeof (pci_regspec_t); index++) { 15330Sstevel@tonic-gate if ((reg[index].pci_phys_hi & himask) != hival) 15340Sstevel@tonic-gate continue; 15350Sstevel@tonic-gate if (reg[index].pci_size_hi != 0) 15360Sstevel@tonic-gate continue; 15370Sstevel@tonic-gate if (reg[index].pci_phys_mid != 0) 15380Sstevel@tonic-gate continue; 15390Sstevel@tonic-gate if (reg[index].pci_phys_low > addr) 15400Sstevel@tonic-gate continue; 15410Sstevel@tonic-gate if (reg[index].pci_phys_low + reg[index].pci_size_low <= addr) 15420Sstevel@tonic-gate continue; 15430Sstevel@tonic-gate 15440Sstevel@tonic-gate *offset = addr - reg[index].pci_phys_low; 15450Sstevel@tonic-gate kmem_free(reg, (size_t)length); 15460Sstevel@tonic-gate return (index); 15470Sstevel@tonic-gate } 15480Sstevel@tonic-gate kmem_free(reg, (size_t)length); 15490Sstevel@tonic-gate 15500Sstevel@tonic-gate return (-1); 15510Sstevel@tonic-gate } 15520Sstevel@tonic-gate 15530Sstevel@tonic-gate /* 15540Sstevel@tonic-gate * search the entries of the "reg" property for one which has the desired 15550Sstevel@tonic-gate * combination of phys_hi bits and contains the desired address. 15560Sstevel@tonic-gate * 15570Sstevel@tonic-gate * This version searches a ISA-style "reg" property. It was prompted by 15580Sstevel@tonic-gate * issues surrounding 8514/A support. By IEEE 1275 compatibility conventions, 15590Sstevel@tonic-gate * 8514/A registers should have been added after all standard VGA registers. 15600Sstevel@tonic-gate * Unfortunately, the Solaris/Intel device configuration framework 15610Sstevel@tonic-gate * (a) lists the 8514/A registers before the video memory, and then 15620Sstevel@tonic-gate * (b) also sorts the entries so that I/O entries come before memory 15630Sstevel@tonic-gate * entries. 15640Sstevel@tonic-gate * 15650Sstevel@tonic-gate * It returns the "reg" index and offset into that register set. 15660Sstevel@tonic-gate * The offset is needed because there exist (broken?) BIOSes that 15670Sstevel@tonic-gate * report larger ranges enclosing the standard ranges. One reports 15680Sstevel@tonic-gate * 0x3bf for 0x21 instead of 0x3c0 for 0x20, for instance. Using the 15690Sstevel@tonic-gate * offset adjusts for this difference in the base of the register set. 15700Sstevel@tonic-gate * 15710Sstevel@tonic-gate * Note that this routine may not be fully general; it is intended for the 15720Sstevel@tonic-gate * specific purpose of finding a couple of particular VGA reg entries and 15730Sstevel@tonic-gate * may not be suitable for all reg-searching purposes. 15740Sstevel@tonic-gate */ 15750Sstevel@tonic-gate static int 15760Sstevel@tonic-gate vgatext_get_isa_reg_index( 15770Sstevel@tonic-gate dev_info_t *const devi, 15780Sstevel@tonic-gate unsigned long hival, 15790Sstevel@tonic-gate unsigned long addr, 15800Sstevel@tonic-gate off_t *offset) 15810Sstevel@tonic-gate { 15820Sstevel@tonic-gate 15830Sstevel@tonic-gate int length, index; 15840Sstevel@tonic-gate struct regspec *reg; 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 15870Sstevel@tonic-gate "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) { 15880Sstevel@tonic-gate return (-1); 15890Sstevel@tonic-gate } 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate for (index = 0; index < length / sizeof (struct regspec); index++) { 15920Sstevel@tonic-gate if (reg[index].regspec_bustype != hival) 15930Sstevel@tonic-gate continue; 15940Sstevel@tonic-gate if (reg[index].regspec_addr > addr) 15950Sstevel@tonic-gate continue; 15960Sstevel@tonic-gate if (reg[index].regspec_addr + reg[index].regspec_size <= addr) 15970Sstevel@tonic-gate continue; 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate *offset = addr - reg[index].regspec_addr; 16000Sstevel@tonic-gate kmem_free(reg, (size_t)length); 16010Sstevel@tonic-gate return (index); 16020Sstevel@tonic-gate } 16030Sstevel@tonic-gate kmem_free(reg, (size_t)length); 16040Sstevel@tonic-gate 16050Sstevel@tonic-gate return (-1); 16060Sstevel@tonic-gate } 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate /* 16090Sstevel@tonic-gate * If AGP cap pointer is successfully found, none-zero value is returned. 16100Sstevel@tonic-gate * Otherwise 0 is returned. 16110Sstevel@tonic-gate */ 16120Sstevel@tonic-gate static off_t 16130Sstevel@tonic-gate agp_master_cap_find(ddi_acc_handle_t acc_handle) 16140Sstevel@tonic-gate { 16150Sstevel@tonic-gate off_t nextcap; 16160Sstevel@tonic-gate uint32_t ncapid; 16170Sstevel@tonic-gate uint8_t value; 16180Sstevel@tonic-gate 16190Sstevel@tonic-gate /* check if this device supports capibility pointer */ 16200Sstevel@tonic-gate value = (uint8_t)(pci_config_get16(acc_handle, PCI_CONF_STAT) 16210Sstevel@tonic-gate & PCI_CONF_CAP_MASK); 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate if (!value) 16240Sstevel@tonic-gate return (0); 16250Sstevel@tonic-gate /* get the offset of the first capability pointer from CAPPTR */ 16260Sstevel@tonic-gate nextcap = (off_t)(pci_config_get8(acc_handle, AGP_CONF_CAPPTR)); 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate /* check AGP capability from the first capability pointer */ 16290Sstevel@tonic-gate while (nextcap) { 16300Sstevel@tonic-gate ncapid = pci_config_get32(acc_handle, nextcap); 16310Sstevel@tonic-gate if ((ncapid & PCI_CONF_CAPID_MASK) 16320Sstevel@tonic-gate == AGP_CAP_ID) /* find AGP cap */ 16330Sstevel@tonic-gate break; 16340Sstevel@tonic-gate 16350Sstevel@tonic-gate nextcap = (off_t)((ncapid & PCI_CONF_NCAPID_MASK) >> 8); 16360Sstevel@tonic-gate } 16370Sstevel@tonic-gate 16380Sstevel@tonic-gate return (nextcap); 16390Sstevel@tonic-gate 16400Sstevel@tonic-gate } 16410Sstevel@tonic-gate 16420Sstevel@tonic-gate /* 16430Sstevel@tonic-gate * If i8xx device is successfully detected, 0 is returned. 16440Sstevel@tonic-gate * Otherwise -1 is returned. 16450Sstevel@tonic-gate */ 16460Sstevel@tonic-gate static int 16470Sstevel@tonic-gate detect_i8xx_device(agp_master_softc_t *master_softc) 16480Sstevel@tonic-gate { 16490Sstevel@tonic-gate 16500Sstevel@tonic-gate switch (master_softc->agpm_id) { 16510Sstevel@tonic-gate case INTEL_IGD_810: 16520Sstevel@tonic-gate case INTEL_IGD_810DC: 16530Sstevel@tonic-gate case INTEL_IGD_810E: 16540Sstevel@tonic-gate case INTEL_IGD_815: 16550Sstevel@tonic-gate master_softc->agpm_dev_type = DEVICE_IS_I810; 16560Sstevel@tonic-gate break; 16570Sstevel@tonic-gate case INTEL_IGD_830M: 16580Sstevel@tonic-gate case INTEL_IGD_845G: 16590Sstevel@tonic-gate case INTEL_IGD_855GM: 16600Sstevel@tonic-gate case INTEL_IGD_865G: 1661*1661Sms148562 case INTEL_IGD_910: 1662*1661Sms148562 case INTEL_IGD_910M: 16630Sstevel@tonic-gate master_softc->agpm_dev_type = DEVICE_IS_I830; 16640Sstevel@tonic-gate break; 16650Sstevel@tonic-gate default: /* unknown id */ 16660Sstevel@tonic-gate return (-1); 16670Sstevel@tonic-gate } 16680Sstevel@tonic-gate 16690Sstevel@tonic-gate return (0); 16700Sstevel@tonic-gate } 16710Sstevel@tonic-gate 16720Sstevel@tonic-gate /* 16730Sstevel@tonic-gate * If agp master is succssfully detected, 0 is returned. 16740Sstevel@tonic-gate * Otherwise -1 is returned. 16750Sstevel@tonic-gate */ 16760Sstevel@tonic-gate static int 16770Sstevel@tonic-gate detect_agp_devcice(agp_master_softc_t *master_softc) 16780Sstevel@tonic-gate { 16790Sstevel@tonic-gate off_t cap; 16800Sstevel@tonic-gate 16810Sstevel@tonic-gate cap = agp_master_cap_find(master_softc->agpm_acc_hdl); 16820Sstevel@tonic-gate if (cap) { 16830Sstevel@tonic-gate master_softc->agpm_dev_type = DEVICE_IS_AGP; 16840Sstevel@tonic-gate master_softc->agpm_data.agpm_acaptr = cap; 16850Sstevel@tonic-gate return (0); 16860Sstevel@tonic-gate } else { 16870Sstevel@tonic-gate return (-1); 16880Sstevel@tonic-gate } 16890Sstevel@tonic-gate 16900Sstevel@tonic-gate } 16910Sstevel@tonic-gate 16920Sstevel@tonic-gate /* 16930Sstevel@tonic-gate * If agp master is successfully initialized, 0 is returned. 16940Sstevel@tonic-gate * Otherwise -1 is returned. 16950Sstevel@tonic-gate */ 16960Sstevel@tonic-gate static int 16970Sstevel@tonic-gate agp_master_init(struct vgatext_softc *softc) 16980Sstevel@tonic-gate { 16990Sstevel@tonic-gate dev_info_t *devi; 17000Sstevel@tonic-gate int instance; 17010Sstevel@tonic-gate int status; 17020Sstevel@tonic-gate agp_master_softc_t *agp_master; 17030Sstevel@tonic-gate uint32_t value; 17040Sstevel@tonic-gate off_t reg_size; 17050Sstevel@tonic-gate 17060Sstevel@tonic-gate 17070Sstevel@tonic-gate ASSERT(softc); 17080Sstevel@tonic-gate agp_master = softc->agp_master; 17090Sstevel@tonic-gate 17100Sstevel@tonic-gate devi = softc->devi; 17110Sstevel@tonic-gate 17120Sstevel@tonic-gate instance = ddi_get_instance(devi); 17130Sstevel@tonic-gate 17140Sstevel@tonic-gate status = pci_config_setup(devi, &agp_master->agpm_acc_hdl); 17150Sstevel@tonic-gate 17160Sstevel@tonic-gate if (status != DDI_SUCCESS) { 17170Sstevel@tonic-gate cmn_err(CE_WARN, "agp_master_init: pci_config_setup failed"); 17180Sstevel@tonic-gate return (-1); 17190Sstevel@tonic-gate } 17200Sstevel@tonic-gate 17210Sstevel@tonic-gate agp_master->agpm_id = 17220Sstevel@tonic-gate pci_config_get32(agp_master->agpm_acc_hdl, PCI_CONF_VENID); 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate if (!detect_i8xx_device(agp_master)) { 17250Sstevel@tonic-gate /* map mmio register set */ 1726*1661Sms148562 if ((agp_master->agpm_id == INTEL_IGD_910) || 1727*1661Sms148562 (agp_master->agpm_id == INTEL_IGD_910M)) { 1728*1661Sms148562 status = ddi_regs_map_setup(devi, I915_GTTADDR_BAR, 1729*1661Sms148562 &agp_master->agpm_data.agpm_gtt.gtt_mmio_base, 1730*1661Sms148562 0, 0, &i8xx_dev_access, 1731*1661Sms148562 &agp_master->agpm_data.agpm_gtt.gtt_mmio_handle); 1732*1661Sms148562 1733*1661Sms148562 } else { 1734*1661Sms148562 status = ddi_regs_map_setup(devi, I8XX_MMIO_REGSET, 1735*1661Sms148562 &agp_master->agpm_data.agpm_gtt.gtt_mmio_base, 1736*1661Sms148562 0, 0, &i8xx_dev_access, 1737*1661Sms148562 &agp_master->agpm_data.agpm_gtt.gtt_mmio_handle); 1738*1661Sms148562 } 17390Sstevel@tonic-gate 17400Sstevel@tonic-gate if (status != DDI_SUCCESS) { 17410Sstevel@tonic-gate cmn_err(CE_WARN, 17420Sstevel@tonic-gate "agp_master_init: ddi_regs_map_setup failed"); 17430Sstevel@tonic-gate agp_master_end(agp_master); 17440Sstevel@tonic-gate return (-1); 17450Sstevel@tonic-gate } 17460Sstevel@tonic-gate /* get GTT range base offset */ 1747*1661Sms148562 if ((agp_master->agpm_id == INTEL_IGD_910) || 1748*1661Sms148562 (agp_master->agpm_id == INTEL_IGD_910M)) { 1749*1661Sms148562 agp_master->agpm_data.agpm_gtt.gtt_addr = 1750*1661Sms148562 agp_master->agpm_data.agpm_gtt.gtt_mmio_base; 1751*1661Sms148562 } else 1752*1661Sms148562 agp_master->agpm_data.agpm_gtt.gtt_addr = 1753*1661Sms148562 agp_master->agpm_data.agpm_gtt.gtt_mmio_base + 1754*1661Sms148562 I8XX_PTE_OFFSET; 1755*1661Sms148562 17560Sstevel@tonic-gate /* get graphics memory size */ 1757*1661Sms148562 if ((agp_master->agpm_id == INTEL_IGD_910) || 1758*1661Sms148562 (agp_master->agpm_id == INTEL_IGD_910M)) { 1759*1661Sms148562 status = ddi_dev_regsize(devi, I915_FB_REGSET, 1760*1661Sms148562 ®_size); 1761*1661Sms148562 } else 1762*1661Sms148562 status = ddi_dev_regsize(devi, I8XX_FB_REGSET, 1763*1661Sms148562 ®_size); 17640Sstevel@tonic-gate /* 17650Sstevel@tonic-gate * if memory size is smaller than a certain value, it means 17660Sstevel@tonic-gate * the register set number for graphics memory range might 17670Sstevel@tonic-gate * be wrong 17680Sstevel@tonic-gate */ 17690Sstevel@tonic-gate if (status != DDI_SUCCESS || reg_size < 0x400000) { 17700Sstevel@tonic-gate cmn_err(CE_WARN, 17710Sstevel@tonic-gate "agp_master_init: ddi_dev_regsize error"); 17720Sstevel@tonic-gate agp_master_end(agp_master); 17730Sstevel@tonic-gate return (-1); 17740Sstevel@tonic-gate } 17750Sstevel@tonic-gate 17760Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_info.igd_apersize = 17770Sstevel@tonic-gate BYTES2MB(reg_size); 1778*1661Sms148562 1779*1661Sms148562 if ((agp_master->agpm_id == INTEL_IGD_910) || 1780*1661Sms148562 (agp_master->agpm_id == INTEL_IGD_910M)) 1781*1661Sms148562 value = pci_config_get32(agp_master->agpm_acc_hdl, 1782*1661Sms148562 I915_CONF_GMADR); 1783*1661Sms148562 else 1784*1661Sms148562 value = pci_config_get32(agp_master->agpm_acc_hdl, 1785*1661Sms148562 I8XX_CONF_GMADR); 17860Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_info.igd_aperbase = 17870Sstevel@tonic-gate value & GTT_BASE_MASK; 17880Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_info.igd_devid = 17890Sstevel@tonic-gate agp_master->agpm_id; 17900Sstevel@tonic-gate } else if (detect_agp_devcice(agp_master)) { 17910Sstevel@tonic-gate /* 17920Sstevel@tonic-gate * non IGD or AGP devices, not error 17930Sstevel@tonic-gate */ 17940Sstevel@tonic-gate agp_master_end(agp_master); 17950Sstevel@tonic-gate return (-1); 17960Sstevel@tonic-gate } 17970Sstevel@tonic-gate 17980Sstevel@tonic-gate /* create extra minor node for IGD or AGP device */ 17990Sstevel@tonic-gate status = ddi_create_minor_node(softc->devi, AGPMASTER_NAME, 18000Sstevel@tonic-gate S_IFCHR, INST2NODE2(instance), DDI_NT_AGP_MASTER, 0); 18010Sstevel@tonic-gate 18020Sstevel@tonic-gate if (status != DDI_SUCCESS) { 18030Sstevel@tonic-gate cmn_err(CE_WARN, 18040Sstevel@tonic-gate "agp_master_init: create agpmaster node failed"); 18050Sstevel@tonic-gate agp_master_end(agp_master); 18060Sstevel@tonic-gate return (-1); 18070Sstevel@tonic-gate } 18080Sstevel@tonic-gate 18090Sstevel@tonic-gate return (0); 18100Sstevel@tonic-gate } 18110Sstevel@tonic-gate 18120Sstevel@tonic-gate /* 18130Sstevel@tonic-gate * Minor node is not removed here, since vgatext_detach is responsible 18140Sstevel@tonic-gate * for removing all nodes. 18150Sstevel@tonic-gate */ 18160Sstevel@tonic-gate static void 18170Sstevel@tonic-gate agp_master_end(agp_master_softc_t *master_softc) 18180Sstevel@tonic-gate { 18190Sstevel@tonic-gate ASSERT(master_softc); 18200Sstevel@tonic-gate 18210Sstevel@tonic-gate /* intel integrated device */ 1822*1661Sms148562 if (IS_IGD(master_softc)) { 18230Sstevel@tonic-gate if (master_softc->agpm_data.agpm_gtt.gtt_mmio_handle != NULL) { 18240Sstevel@tonic-gate ddi_regs_map_free( 18250Sstevel@tonic-gate &master_softc->agpm_data.agpm_gtt.gtt_mmio_handle); 18260Sstevel@tonic-gate } 18270Sstevel@tonic-gate } 18280Sstevel@tonic-gate if (master_softc->agpm_acc_hdl != NULL) { 18290Sstevel@tonic-gate pci_config_teardown(&master_softc->agpm_acc_hdl); 18300Sstevel@tonic-gate } 18310Sstevel@tonic-gate 18320Sstevel@tonic-gate bzero(master_softc, sizeof (agp_master_softc_t)); 18330Sstevel@tonic-gate return; 18340Sstevel@tonic-gate 18350Sstevel@tonic-gate } 18360Sstevel@tonic-gate 18370Sstevel@tonic-gate /* 18380Sstevel@tonic-gate * Please refer to GART and GTT entry format table in agpdefs.h for 18390Sstevel@tonic-gate * intel GTT entry format. 18400Sstevel@tonic-gate */ 18410Sstevel@tonic-gate static int 18420Sstevel@tonic-gate phys2entry(uint32_t type, uint32_t physaddr, uint32_t *entry) 18430Sstevel@tonic-gate { 18440Sstevel@tonic-gate uint32_t value; 18450Sstevel@tonic-gate 18460Sstevel@tonic-gate switch (type) { 18470Sstevel@tonic-gate case AGP_PHYSICAL: 18480Sstevel@tonic-gate case AGP_NORMAL: 18490Sstevel@tonic-gate value = (physaddr & GTT_PTE_MASK) | GTT_PTE_VALID; 18500Sstevel@tonic-gate break; 18510Sstevel@tonic-gate default: 18520Sstevel@tonic-gate return (-1); 18530Sstevel@tonic-gate } 18540Sstevel@tonic-gate 18550Sstevel@tonic-gate *entry = value; 18560Sstevel@tonic-gate 18570Sstevel@tonic-gate return (0); 18580Sstevel@tonic-gate } 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate static int 18610Sstevel@tonic-gate i8xx_add_to_gtt(gtt_impl_t *gtt, igd_gtt_seg_t seg) 18620Sstevel@tonic-gate { 18630Sstevel@tonic-gate int i; 18640Sstevel@tonic-gate uint32_t *paddr; 18650Sstevel@tonic-gate uint32_t entry; 18660Sstevel@tonic-gate uint32_t maxpages; 18670Sstevel@tonic-gate 18680Sstevel@tonic-gate maxpages = gtt->gtt_info.igd_apersize; 18690Sstevel@tonic-gate maxpages = GTT_MB_TO_PAGES(maxpages); 18700Sstevel@tonic-gate 18710Sstevel@tonic-gate paddr = seg.igs_phyaddr; 18720Sstevel@tonic-gate 18730Sstevel@tonic-gate /* 18740Sstevel@tonic-gate * check if gtt max pages reached 18750Sstevel@tonic-gate */ 18760Sstevel@tonic-gate if ((seg.igs_pgstart + seg.igs_npage) > maxpages) 18770Sstevel@tonic-gate return (-1); 18780Sstevel@tonic-gate 18790Sstevel@tonic-gate paddr = seg.igs_phyaddr; 18800Sstevel@tonic-gate for (i = seg.igs_pgstart; i < (seg.igs_pgstart + seg.igs_npage); 18810Sstevel@tonic-gate i++, paddr++) { 18820Sstevel@tonic-gate if (phys2entry(seg.igs_type, *paddr, &entry)) 18830Sstevel@tonic-gate return (-1); 18840Sstevel@tonic-gate ddi_put32(gtt->gtt_mmio_handle, 18850Sstevel@tonic-gate (uint32_t *)(gtt->gtt_addr + i * sizeof (uint32_t)), 18860Sstevel@tonic-gate entry); 18870Sstevel@tonic-gate } 18880Sstevel@tonic-gate 18890Sstevel@tonic-gate return (0); 18900Sstevel@tonic-gate } 18910Sstevel@tonic-gate 18920Sstevel@tonic-gate static void 18930Sstevel@tonic-gate i8xx_remove_from_gtt(gtt_impl_t *gtt, igd_gtt_seg_t seg) 18940Sstevel@tonic-gate { 18950Sstevel@tonic-gate int i; 18960Sstevel@tonic-gate uint32_t maxpages; 18970Sstevel@tonic-gate 18980Sstevel@tonic-gate maxpages = gtt->gtt_info.igd_apersize; 18990Sstevel@tonic-gate maxpages = GTT_MB_TO_PAGES(maxpages); 19000Sstevel@tonic-gate 19010Sstevel@tonic-gate /* 19020Sstevel@tonic-gate * check if gtt max pages reached 19030Sstevel@tonic-gate */ 19040Sstevel@tonic-gate if ((seg.igs_pgstart + seg.igs_npage) > maxpages) 19050Sstevel@tonic-gate return; 19060Sstevel@tonic-gate 19070Sstevel@tonic-gate for (i = seg.igs_pgstart; i < (seg.igs_pgstart + seg.igs_npage); i++) { 19080Sstevel@tonic-gate ddi_put32(gtt->gtt_mmio_handle, 19090Sstevel@tonic-gate (uint32_t *)(gtt->gtt_addr + 19100Sstevel@tonic-gate i * sizeof (uint32_t)), 19110Sstevel@tonic-gate 0); 19120Sstevel@tonic-gate } 19130Sstevel@tonic-gate } 1914