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