1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ 23*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */ 24*0Sstevel@tonic-gate /* All Rights Reserved */ 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <sys/errno.h> 34*0Sstevel@tonic-gate #include <sys/types.h> 35*0Sstevel@tonic-gate #include <sys/conf.h> 36*0Sstevel@tonic-gate #include <sys/kmem.h> 37*0Sstevel@tonic-gate #include <sys/visual_io.h> 38*0Sstevel@tonic-gate #include <sys/font.h> 39*0Sstevel@tonic-gate #include <sys/fbio.h> 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #include <sys/ddi.h> 42*0Sstevel@tonic-gate #include <sys/stat.h> 43*0Sstevel@tonic-gate #include <sys/sunddi.h> 44*0Sstevel@tonic-gate #include <sys/file.h> 45*0Sstevel@tonic-gate #include <sys/open.h> 46*0Sstevel@tonic-gate #include <sys/modctl.h> 47*0Sstevel@tonic-gate #include <sys/vgareg.h> 48*0Sstevel@tonic-gate #include <sys/vgasubr.h> 49*0Sstevel@tonic-gate #include <sys/pci.h> 50*0Sstevel@tonic-gate #include <sys/kd.h> 51*0Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 52*0Sstevel@tonic-gate #include <sys/sunldi.h> 53*0Sstevel@tonic-gate #include <sys/agpgart.h> 54*0Sstevel@tonic-gate #include <sys/agp/agpdefs.h> 55*0Sstevel@tonic-gate #include <sys/agp/agpmaster_io.h> 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate #define MYNAME "vgatext" 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate /* 60*0Sstevel@tonic-gate * agp support macros 61*0Sstevel@tonic-gate */ 62*0Sstevel@tonic-gate #define I8XX_MMIO_REGSET 2 63*0Sstevel@tonic-gate #define I8XX_FB_REGSET 1 64*0Sstevel@tonic-gate #define I8XX_PTE_OFFSET 0x10000 65*0Sstevel@tonic-gate #define I8XX_PGTBL_CTL 0x2020 66*0Sstevel@tonic-gate #define DEV2INST(dev) (getminor(dev) >> 1) 67*0Sstevel@tonic-gate #define INST2NODE1(inst) ((inst) << 1) 68*0Sstevel@tonic-gate #define INST2NODE2(inst) (((inst) << 1) + 1) 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* I don't know exactly where these should be defined, but this is a */ 71*0Sstevel@tonic-gate /* heck of a lot better than constants in the code. */ 72*0Sstevel@tonic-gate #define TEXT_ROWS 25 73*0Sstevel@tonic-gate #define TEXT_COLS 80 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate #define VGA_BRIGHT_WHITE 0x0f 76*0Sstevel@tonic-gate #define VGA_BLACK 0x00 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #define VGA_REG_ADDR 0x3c0 79*0Sstevel@tonic-gate #define VGA_REG_SIZE 0x20 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate #define VGA_MEM_ADDR 0xa0000 82*0Sstevel@tonic-gate #define VGA_MEM_SIZE 0x20000 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate #define VGA_MMAP_FB_BASE VGA_MEM_ADDR 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate static int vgatext_open(dev_t *, int, int, cred_t *); 87*0Sstevel@tonic-gate static int vgatext_close(dev_t, int, int, cred_t *); 88*0Sstevel@tonic-gate static int vgatext_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 89*0Sstevel@tonic-gate static int vgatext_devmap(dev_t, devmap_cookie_t, offset_t, size_t, 90*0Sstevel@tonic-gate size_t *, uint_t); 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate static struct cb_ops cb_vgatext_ops = { 93*0Sstevel@tonic-gate vgatext_open, /* cb_open */ 94*0Sstevel@tonic-gate vgatext_close, /* cb_close */ 95*0Sstevel@tonic-gate nodev, /* cb_strategy */ 96*0Sstevel@tonic-gate nodev, /* cb_print */ 97*0Sstevel@tonic-gate nodev, /* cb_dump */ 98*0Sstevel@tonic-gate nodev, /* cb_read */ 99*0Sstevel@tonic-gate nodev, /* cb_write */ 100*0Sstevel@tonic-gate vgatext_ioctl, /* cb_ioctl */ 101*0Sstevel@tonic-gate vgatext_devmap, /* cb_devmap */ 102*0Sstevel@tonic-gate nodev, /* cb_mmap */ 103*0Sstevel@tonic-gate ddi_devmap_segmap, /* cb_segmap */ 104*0Sstevel@tonic-gate nochpoll, /* cb_chpoll */ 105*0Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 106*0Sstevel@tonic-gate 0, /* cb_stream */ 107*0Sstevel@tonic-gate D_NEW | D_MTSAFE /* cb_flag */ 108*0Sstevel@tonic-gate }; 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate static int vgatext_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 112*0Sstevel@tonic-gate void **result); 113*0Sstevel@tonic-gate static int vgatext_attach(dev_info_t *, ddi_attach_cmd_t); 114*0Sstevel@tonic-gate static int vgatext_detach(dev_info_t *, ddi_detach_cmd_t); 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate static struct vis_identifier text_ident = { "SUNWtext" }; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate static struct dev_ops vgatext_ops = { 119*0Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 120*0Sstevel@tonic-gate 0, /* devo_refcnt */ 121*0Sstevel@tonic-gate vgatext_info, /* devo_getinfo */ 122*0Sstevel@tonic-gate nulldev, /* devo_identify */ 123*0Sstevel@tonic-gate nulldev, /* devo_probe */ 124*0Sstevel@tonic-gate vgatext_attach, /* devo_attach */ 125*0Sstevel@tonic-gate vgatext_detach, /* devo_detach */ 126*0Sstevel@tonic-gate nodev, /* devo_reset */ 127*0Sstevel@tonic-gate &cb_vgatext_ops, /* devo_cb_ops */ 128*0Sstevel@tonic-gate (struct bus_ops *)NULL, /* devo_bus_ops */ 129*0Sstevel@tonic-gate NULL /* power */ 130*0Sstevel@tonic-gate }; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate /* 134*0Sstevel@tonic-gate * agp support data structures 135*0Sstevel@tonic-gate */ 136*0Sstevel@tonic-gate typedef struct gtt_impl { 137*0Sstevel@tonic-gate ddi_acc_handle_t gtt_mmio_handle; /* mmaped graph registers */ 138*0Sstevel@tonic-gate caddr_t gtt_mmio_base; /* pointer to register base */ 139*0Sstevel@tonic-gate caddr_t gtt_addr; /* pointer to gtt */ 140*0Sstevel@tonic-gate igd_info_t gtt_info; /* for I8XX_GET_INFO ioctl */ 141*0Sstevel@tonic-gate } gtt_impl_t; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate typedef struct agp_master_softc { 144*0Sstevel@tonic-gate uint32_t agpm_id; /* agp master device id */ 145*0Sstevel@tonic-gate ddi_acc_handle_t agpm_acc_hdl; /* agp master pci conf handle */ 146*0Sstevel@tonic-gate int agpm_dev_type; /* which agp device type */ 147*0Sstevel@tonic-gate union { 148*0Sstevel@tonic-gate off_t agpm_acaptr; /* AGP capability reg pointer */ 149*0Sstevel@tonic-gate gtt_impl_t agpm_gtt; /* for gtt table */ 150*0Sstevel@tonic-gate } agpm_data; 151*0Sstevel@tonic-gate } agp_master_softc_t; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate struct vgatext_softc { 156*0Sstevel@tonic-gate struct vgaregmap regs; 157*0Sstevel@tonic-gate struct vgaregmap fb; 158*0Sstevel@tonic-gate off_t fb_size; 159*0Sstevel@tonic-gate int fb_regno; 160*0Sstevel@tonic-gate dev_info_t *devi; 161*0Sstevel@tonic-gate int mode; /* KD_TEXT or KD_GRAPHICS */ 162*0Sstevel@tonic-gate caddr_t text_base; /* hardware text base */ 163*0Sstevel@tonic-gate char shadow[TEXT_ROWS*TEXT_COLS*2]; 164*0Sstevel@tonic-gate caddr_t current_base; /* hardware or shadow */ 165*0Sstevel@tonic-gate struct { 166*0Sstevel@tonic-gate boolean_t visible; 167*0Sstevel@tonic-gate int row; 168*0Sstevel@tonic-gate int col; 169*0Sstevel@tonic-gate } cursor; 170*0Sstevel@tonic-gate struct vis_polledio polledio; 171*0Sstevel@tonic-gate struct { 172*0Sstevel@tonic-gate unsigned char red; 173*0Sstevel@tonic-gate unsigned char green; 174*0Sstevel@tonic-gate unsigned char blue; 175*0Sstevel@tonic-gate } colormap[VGA8_CMAP_ENTRIES]; 176*0Sstevel@tonic-gate unsigned char attrib_palette[VGA_ATR_NUM_PLT]; 177*0Sstevel@tonic-gate agp_master_softc_t *agp_master; /* NULL mean not PCI, for AGP */ 178*0Sstevel@tonic-gate }; 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate static int vgatext_devinit(struct vgatext_softc *, struct vis_devinit *data); 181*0Sstevel@tonic-gate static void vgatext_cons_copy(struct vgatext_softc *, 182*0Sstevel@tonic-gate struct vis_conscopy *); 183*0Sstevel@tonic-gate static void vgatext_cons_display(struct vgatext_softc *, 184*0Sstevel@tonic-gate struct vis_consdisplay *); 185*0Sstevel@tonic-gate static void vgatext_cons_cursor(struct vgatext_softc *, 186*0Sstevel@tonic-gate struct vis_conscursor *); 187*0Sstevel@tonic-gate static void vgatext_polled_copy(struct vis_polledio_arg *, 188*0Sstevel@tonic-gate struct vis_conscopy *); 189*0Sstevel@tonic-gate static void vgatext_polled_display(struct vis_polledio_arg *, 190*0Sstevel@tonic-gate struct vis_consdisplay *); 191*0Sstevel@tonic-gate static void vgatext_polled_cursor(struct vis_polledio_arg *, 192*0Sstevel@tonic-gate struct vis_conscursor *); 193*0Sstevel@tonic-gate static void vgatext_init(struct vgatext_softc *); 194*0Sstevel@tonic-gate static void vgatext_set_text(struct vgatext_softc *); 195*0Sstevel@tonic-gate #if defined(USE_BORDERS) 196*0Sstevel@tonic-gate static void vgatext_init_graphics(struct vgatext_softc *); 197*0Sstevel@tonic-gate #endif 198*0Sstevel@tonic-gate static int vgatext_kdsetmode(struct vgatext_softc *softc, int mode); 199*0Sstevel@tonic-gate static void vgatext_setfont(struct vgatext_softc *softc); 200*0Sstevel@tonic-gate static void vgatext_get_cursor(struct vgatext_softc *softc, 201*0Sstevel@tonic-gate screen_pos_t *row, screen_pos_t *col); 202*0Sstevel@tonic-gate static void vgatext_set_cursor(struct vgatext_softc *softc, int row, int col); 203*0Sstevel@tonic-gate static void vgatext_hide_cursor(struct vgatext_softc *softc); 204*0Sstevel@tonic-gate static void vgatext_save_colormap(struct vgatext_softc *softc); 205*0Sstevel@tonic-gate static void vgatext_restore_colormap(struct vgatext_softc *softc); 206*0Sstevel@tonic-gate static int vgatext_get_pci_reg_index(dev_info_t *const devi, 207*0Sstevel@tonic-gate unsigned long himask, unsigned long hival, unsigned long addr, 208*0Sstevel@tonic-gate off_t *offset); 209*0Sstevel@tonic-gate static int vgatext_get_isa_reg_index(dev_info_t *const devi, 210*0Sstevel@tonic-gate unsigned long hival, unsigned long addr, off_t *offset); 211*0Sstevel@tonic-gate /* 212*0Sstevel@tonic-gate * agp support functions prototype 213*0Sstevel@tonic-gate */ 214*0Sstevel@tonic-gate static off_t agp_master_cap_find(ddi_acc_handle_t); 215*0Sstevel@tonic-gate static int detect_i8xx_device(agp_master_softc_t *); 216*0Sstevel@tonic-gate static int detect_agp_devcice(agp_master_softc_t *); 217*0Sstevel@tonic-gate static int agp_master_init(struct vgatext_softc *); 218*0Sstevel@tonic-gate static void agp_master_end(agp_master_softc_t *); 219*0Sstevel@tonic-gate static int phys2entry(uint32_t, uint32_t, uint32_t *); 220*0Sstevel@tonic-gate static int i8xx_add_to_gtt(gtt_impl_t *, igd_gtt_seg_t); 221*0Sstevel@tonic-gate static void i8xx_remove_from_gtt(gtt_impl_t *, igd_gtt_seg_t); 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate static void *vgatext_softc_head; 224*0Sstevel@tonic-gate static char vgatext_silent; 225*0Sstevel@tonic-gate static char happyface_boot; 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate /* Loadable Driver stuff */ 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate static struct modldrv modldrv = { 230*0Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 231*0Sstevel@tonic-gate "VGA text driver v%I%", /* Name of the module. */ 232*0Sstevel@tonic-gate &vgatext_ops, /* driver ops */ 233*0Sstevel@tonic-gate }; 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 236*0Sstevel@tonic-gate MODREV_1, (void *) &modldrv, NULL 237*0Sstevel@tonic-gate }; 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate typedef enum pc_colors { 240*0Sstevel@tonic-gate pc_black = 0, 241*0Sstevel@tonic-gate pc_blue = 1, 242*0Sstevel@tonic-gate pc_green = 2, 243*0Sstevel@tonic-gate pc_cyan = 3, 244*0Sstevel@tonic-gate pc_red = 4, 245*0Sstevel@tonic-gate pc_magenta = 5, 246*0Sstevel@tonic-gate pc_brown = 6, 247*0Sstevel@tonic-gate pc_white = 7, 248*0Sstevel@tonic-gate pc_grey = 8, 249*0Sstevel@tonic-gate pc_brt_blue = 9, 250*0Sstevel@tonic-gate pc_brt_green = 10, 251*0Sstevel@tonic-gate pc_brt_cyan = 11, 252*0Sstevel@tonic-gate pc_brt_red = 12, 253*0Sstevel@tonic-gate pc_brt_magenta = 13, 254*0Sstevel@tonic-gate pc_yellow = 14, 255*0Sstevel@tonic-gate pc_brt_white = 15 256*0Sstevel@tonic-gate } pc_colors_t; 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gate static const unsigned char solaris_color_to_pc_color[16] = { 259*0Sstevel@tonic-gate pc_brt_white, /* 0 - brt_white */ 260*0Sstevel@tonic-gate pc_black, /* 1 - black */ 261*0Sstevel@tonic-gate pc_blue, /* 2 - blue */ 262*0Sstevel@tonic-gate pc_green, /* 3 - green */ 263*0Sstevel@tonic-gate pc_cyan, /* 4 - cyan */ 264*0Sstevel@tonic-gate pc_red, /* 5 - red */ 265*0Sstevel@tonic-gate pc_magenta, /* 6 - magenta */ 266*0Sstevel@tonic-gate pc_brown, /* 7 - brown */ 267*0Sstevel@tonic-gate pc_white, /* 8 - white */ 268*0Sstevel@tonic-gate pc_grey, /* 9 - gery */ 269*0Sstevel@tonic-gate pc_brt_blue, /* 10 - brt_blue */ 270*0Sstevel@tonic-gate pc_brt_green, /* 11 - brt_green */ 271*0Sstevel@tonic-gate pc_brt_cyan, /* 12 - brt_cyan */ 272*0Sstevel@tonic-gate pc_brt_red, /* 13 - brt_red */ 273*0Sstevel@tonic-gate pc_brt_magenta, /* 14 - brt_magenta */ 274*0Sstevel@tonic-gate pc_yellow /* 15 - yellow */ 275*0Sstevel@tonic-gate }; 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate static ddi_device_acc_attr_t i8xx_dev_access = { 278*0Sstevel@tonic-gate DDI_DEVICE_ATTR_V0, 279*0Sstevel@tonic-gate DDI_NEVERSWAP_ACC, 280*0Sstevel@tonic-gate DDI_STRICTORDER_ACC 281*0Sstevel@tonic-gate }; 282*0Sstevel@tonic-gate 283*0Sstevel@tonic-gate static ddi_device_acc_attr_t dev_attr = { 284*0Sstevel@tonic-gate DDI_DEVICE_ATTR_V0, 285*0Sstevel@tonic-gate DDI_NEVERSWAP_ACC, 286*0Sstevel@tonic-gate DDI_STRICTORDER_ACC, 287*0Sstevel@tonic-gate }; 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate int 290*0Sstevel@tonic-gate _init(void) 291*0Sstevel@tonic-gate { 292*0Sstevel@tonic-gate int e; 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gate if ((e = ddi_soft_state_init(&vgatext_softc_head, 295*0Sstevel@tonic-gate sizeof (struct vgatext_softc), 1)) != 0) { 296*0Sstevel@tonic-gate return (e); 297*0Sstevel@tonic-gate } 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate e = mod_install(&modlinkage); 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gate if (e) { 302*0Sstevel@tonic-gate ddi_soft_state_fini(&vgatext_softc_head); 303*0Sstevel@tonic-gate } 304*0Sstevel@tonic-gate return (e); 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate int 308*0Sstevel@tonic-gate _fini(void) 309*0Sstevel@tonic-gate { 310*0Sstevel@tonic-gate int e; 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) != 0) 313*0Sstevel@tonic-gate return (e); 314*0Sstevel@tonic-gate 315*0Sstevel@tonic-gate ddi_soft_state_fini(&vgatext_softc_head); 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate return (0); 318*0Sstevel@tonic-gate } 319*0Sstevel@tonic-gate 320*0Sstevel@tonic-gate int 321*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 322*0Sstevel@tonic-gate { 323*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 324*0Sstevel@tonic-gate } 325*0Sstevel@tonic-gate 326*0Sstevel@tonic-gate /* default structure for FBIOGATTR ioctl */ 327*0Sstevel@tonic-gate static struct fbgattr vgatext_attr = { 328*0Sstevel@tonic-gate /* real_type owner */ 329*0Sstevel@tonic-gate FBTYPE_SUNFAST_COLOR, 0, 330*0Sstevel@tonic-gate /* fbtype: type h w depth cms size */ 331*0Sstevel@tonic-gate { FBTYPE_SUNFAST_COLOR, TEXT_ROWS, TEXT_COLS, 1, 256, 0 }, 332*0Sstevel@tonic-gate /* fbsattr: flags emu_type dev_specific */ 333*0Sstevel@tonic-gate { 0, FBTYPE_SUN4COLOR, { 0 } }, 334*0Sstevel@tonic-gate /* emu_types */ 335*0Sstevel@tonic-gate { -1 } 336*0Sstevel@tonic-gate }; 337*0Sstevel@tonic-gate 338*0Sstevel@tonic-gate /* 339*0Sstevel@tonic-gate * handy macros 340*0Sstevel@tonic-gate */ 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate #define getsoftc(instance) ((struct vgatext_softc *) \ 343*0Sstevel@tonic-gate ddi_get_soft_state(vgatext_softc_head, (instance))) 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate static int 346*0Sstevel@tonic-gate vgatext_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 347*0Sstevel@tonic-gate { 348*0Sstevel@tonic-gate struct vgatext_softc *softc; 349*0Sstevel@tonic-gate int unit = ddi_get_instance(devi); 350*0Sstevel@tonic-gate int error; 351*0Sstevel@tonic-gate char *parent_type = NULL; 352*0Sstevel@tonic-gate int reg_rnumber; 353*0Sstevel@tonic-gate off_t reg_offset; 354*0Sstevel@tonic-gate off_t mem_offset; 355*0Sstevel@tonic-gate char buf[80], *cons; 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate switch (cmd) { 359*0Sstevel@tonic-gate case DDI_ATTACH: 360*0Sstevel@tonic-gate break; 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate case DDI_RESUME: 363*0Sstevel@tonic-gate return (DDI_SUCCESS); 364*0Sstevel@tonic-gate default: 365*0Sstevel@tonic-gate return (DDI_FAILURE); 366*0Sstevel@tonic-gate } 367*0Sstevel@tonic-gate 368*0Sstevel@tonic-gate /* DDI_ATTACH */ 369*0Sstevel@tonic-gate 370*0Sstevel@tonic-gate /* Allocate softc struct */ 371*0Sstevel@tonic-gate if (ddi_soft_state_zalloc(vgatext_softc_head, unit) != DDI_SUCCESS) { 372*0Sstevel@tonic-gate return (DDI_FAILURE); 373*0Sstevel@tonic-gate } 374*0Sstevel@tonic-gate softc = getsoftc(unit); 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate /* link it in */ 377*0Sstevel@tonic-gate softc->devi = devi; 378*0Sstevel@tonic-gate ddi_set_driver_private(devi, softc); 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate softc->polledio.arg = (struct vis_polledio_arg *)softc; 381*0Sstevel@tonic-gate softc->polledio.display = vgatext_polled_display; 382*0Sstevel@tonic-gate softc->polledio.copy = vgatext_polled_copy; 383*0Sstevel@tonic-gate softc->polledio.cursor = vgatext_polled_cursor; 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate error = ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_get_parent(devi), 386*0Sstevel@tonic-gate DDI_PROP_DONTPASS, "device_type", &parent_type); 387*0Sstevel@tonic-gate if (error != DDI_SUCCESS) { 388*0Sstevel@tonic-gate cmn_err(CE_WARN, MYNAME ": can't determine parent type."); 389*0Sstevel@tonic-gate goto fail; 390*0Sstevel@tonic-gate } 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gate #define STREQ(a, b) (strcmp((a), (b)) == 0) 393*0Sstevel@tonic-gate if (STREQ(parent_type, "isa") || STREQ(parent_type, "eisa")) { 394*0Sstevel@tonic-gate reg_rnumber = vgatext_get_isa_reg_index(devi, 1, VGA_REG_ADDR, 395*0Sstevel@tonic-gate ®_offset); 396*0Sstevel@tonic-gate if (reg_rnumber < 0) { 397*0Sstevel@tonic-gate cmn_err(CE_WARN, 398*0Sstevel@tonic-gate MYNAME ": can't find reg entry for registers"); 399*0Sstevel@tonic-gate goto fail; 400*0Sstevel@tonic-gate } 401*0Sstevel@tonic-gate softc->fb_regno = vgatext_get_isa_reg_index(devi, 0, 402*0Sstevel@tonic-gate VGA_MEM_ADDR, &mem_offset); 403*0Sstevel@tonic-gate if (softc->fb_regno < 0) { 404*0Sstevel@tonic-gate cmn_err(CE_WARN, 405*0Sstevel@tonic-gate MYNAME ": can't find reg entry for memory"); 406*0Sstevel@tonic-gate goto fail; 407*0Sstevel@tonic-gate } 408*0Sstevel@tonic-gate } else if (STREQ(parent_type, "pci")) { 409*0Sstevel@tonic-gate reg_rnumber = vgatext_get_pci_reg_index(devi, 410*0Sstevel@tonic-gate PCI_REG_ADDR_M|PCI_REG_REL_M, 411*0Sstevel@tonic-gate PCI_ADDR_IO|PCI_RELOCAT_B, VGA_REG_ADDR, 412*0Sstevel@tonic-gate ®_offset); 413*0Sstevel@tonic-gate if (reg_rnumber < 0) { 414*0Sstevel@tonic-gate cmn_err(CE_WARN, 415*0Sstevel@tonic-gate MYNAME ": can't find reg entry for registers"); 416*0Sstevel@tonic-gate goto fail; 417*0Sstevel@tonic-gate } 418*0Sstevel@tonic-gate softc->fb_regno = vgatext_get_pci_reg_index(devi, 419*0Sstevel@tonic-gate PCI_REG_ADDR_M|PCI_REG_REL_M, 420*0Sstevel@tonic-gate PCI_ADDR_MEM32|PCI_RELOCAT_B, VGA_MEM_ADDR, 421*0Sstevel@tonic-gate &mem_offset); 422*0Sstevel@tonic-gate if (softc->fb_regno < 0) { 423*0Sstevel@tonic-gate cmn_err(CE_WARN, 424*0Sstevel@tonic-gate MYNAME ": can't find reg entry for memory"); 425*0Sstevel@tonic-gate goto fail; 426*0Sstevel@tonic-gate } 427*0Sstevel@tonic-gate softc->agp_master = (agp_master_softc_t *) 428*0Sstevel@tonic-gate kmem_zalloc(sizeof (agp_master_softc_t), KM_SLEEP); 429*0Sstevel@tonic-gate } else { 430*0Sstevel@tonic-gate cmn_err(CE_WARN, MYNAME ": unknown parent type \"%s\".", 431*0Sstevel@tonic-gate parent_type); 432*0Sstevel@tonic-gate goto fail; 433*0Sstevel@tonic-gate } 434*0Sstevel@tonic-gate ddi_prop_free(parent_type); 435*0Sstevel@tonic-gate parent_type = NULL; 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate error = ddi_regs_map_setup(devi, reg_rnumber, 438*0Sstevel@tonic-gate (caddr_t *)&softc->regs.addr, reg_offset, VGA_REG_SIZE, 439*0Sstevel@tonic-gate &dev_attr, &softc->regs.handle); 440*0Sstevel@tonic-gate if (error != DDI_SUCCESS) 441*0Sstevel@tonic-gate goto fail; 442*0Sstevel@tonic-gate softc->regs.mapped = B_TRUE; 443*0Sstevel@tonic-gate 444*0Sstevel@tonic-gate softc->fb_size = VGA_MEM_SIZE; 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate error = ddi_regs_map_setup(devi, softc->fb_regno, 447*0Sstevel@tonic-gate (caddr_t *)&softc->fb.addr, 448*0Sstevel@tonic-gate mem_offset, softc->fb_size, 449*0Sstevel@tonic-gate &dev_attr, &softc->fb.handle); 450*0Sstevel@tonic-gate if (error != DDI_SUCCESS) 451*0Sstevel@tonic-gate goto fail; 452*0Sstevel@tonic-gate softc->fb.mapped = B_TRUE; 453*0Sstevel@tonic-gate 454*0Sstevel@tonic-gate if (ddi_io_get8(softc->regs.handle, 455*0Sstevel@tonic-gate softc->regs.addr + VGA_MISC_R) & VGA_MISC_IOA_SEL) 456*0Sstevel@tonic-gate softc->text_base = (caddr_t)softc->fb.addr + VGA_COLOR_BASE; 457*0Sstevel@tonic-gate else 458*0Sstevel@tonic-gate softc->text_base = (caddr_t)softc->fb.addr + VGA_MONO_BASE; 459*0Sstevel@tonic-gate softc->current_base = softc->text_base; 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate (void) sprintf(buf, "text-%d", unit); 462*0Sstevel@tonic-gate error = ddi_create_minor_node(devi, buf, S_IFCHR, 463*0Sstevel@tonic-gate INST2NODE1(unit), DDI_NT_DISPLAY, NULL); 464*0Sstevel@tonic-gate if (error != DDI_SUCCESS) 465*0Sstevel@tonic-gate goto fail; 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate error = ddi_prop_create(makedevice(DDI_MAJOR_T_UNKNOWN, unit), 468*0Sstevel@tonic-gate devi, DDI_PROP_CANSLEEP, DDI_KERNEL_IOCTL, NULL, 0); 469*0Sstevel@tonic-gate if (error != DDI_SUCCESS) 470*0Sstevel@tonic-gate goto fail; 471*0Sstevel@tonic-gate 472*0Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 473*0Sstevel@tonic-gate DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) { 474*0Sstevel@tonic-gate if (strcmp(cons, "graphics") == 0) { 475*0Sstevel@tonic-gate happyface_boot = 1; 476*0Sstevel@tonic-gate vgatext_silent = 1; 477*0Sstevel@tonic-gate } 478*0Sstevel@tonic-gate ddi_prop_free(cons); 479*0Sstevel@tonic-gate } 480*0Sstevel@tonic-gate 481*0Sstevel@tonic-gate /* only do this if not in graphics mode */ 482*0Sstevel@tonic-gate if (vgatext_silent == 0) { 483*0Sstevel@tonic-gate vgatext_init(softc); 484*0Sstevel@tonic-gate vgatext_save_colormap(softc); 485*0Sstevel@tonic-gate } 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gate if (softc->agp_master != NULL) { /* is PCI */ 488*0Sstevel@tonic-gate if (agp_master_init(softc) != 0) { /* unsuccessful */ 489*0Sstevel@tonic-gate kmem_free(softc->agp_master, 490*0Sstevel@tonic-gate sizeof (agp_master_softc_t)); 491*0Sstevel@tonic-gate softc->agp_master = NULL; 492*0Sstevel@tonic-gate 493*0Sstevel@tonic-gate } 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate return (DDI_SUCCESS); 497*0Sstevel@tonic-gate 498*0Sstevel@tonic-gate fail: 499*0Sstevel@tonic-gate if (parent_type != NULL) 500*0Sstevel@tonic-gate ddi_prop_free(parent_type); 501*0Sstevel@tonic-gate (void) vgatext_detach(devi, DDI_DETACH); 502*0Sstevel@tonic-gate return (error); 503*0Sstevel@tonic-gate } 504*0Sstevel@tonic-gate 505*0Sstevel@tonic-gate static int 506*0Sstevel@tonic-gate vgatext_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 507*0Sstevel@tonic-gate { 508*0Sstevel@tonic-gate int instance = ddi_get_instance(devi); 509*0Sstevel@tonic-gate struct vgatext_softc *softc = getsoftc(instance); 510*0Sstevel@tonic-gate 511*0Sstevel@tonic-gate 512*0Sstevel@tonic-gate switch (cmd) { 513*0Sstevel@tonic-gate case DDI_DETACH: 514*0Sstevel@tonic-gate if (softc->agp_master != NULL) { /* agp initiated */ 515*0Sstevel@tonic-gate agp_master_end(softc->agp_master); 516*0Sstevel@tonic-gate 517*0Sstevel@tonic-gate kmem_free(softc->agp_master, 518*0Sstevel@tonic-gate sizeof (agp_master_softc_t)); 519*0Sstevel@tonic-gate softc->agp_master = NULL; 520*0Sstevel@tonic-gate 521*0Sstevel@tonic-gate } 522*0Sstevel@tonic-gate 523*0Sstevel@tonic-gate if (softc->fb.mapped) 524*0Sstevel@tonic-gate ddi_regs_map_free(&softc->fb.handle); 525*0Sstevel@tonic-gate if (softc->regs.mapped) 526*0Sstevel@tonic-gate ddi_regs_map_free(&softc->regs.handle); 527*0Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 528*0Sstevel@tonic-gate (void) ddi_soft_state_free(vgatext_softc_head, instance); 529*0Sstevel@tonic-gate return (DDI_SUCCESS); 530*0Sstevel@tonic-gate 531*0Sstevel@tonic-gate default: 532*0Sstevel@tonic-gate cmn_err(CE_WARN, "vgatext_detach: unknown cmd 0x%x\n", cmd); 533*0Sstevel@tonic-gate return (DDI_FAILURE); 534*0Sstevel@tonic-gate } 535*0Sstevel@tonic-gate } 536*0Sstevel@tonic-gate 537*0Sstevel@tonic-gate /*ARGSUSED*/ 538*0Sstevel@tonic-gate static int 539*0Sstevel@tonic-gate vgatext_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 540*0Sstevel@tonic-gate { 541*0Sstevel@tonic-gate dev_t dev; 542*0Sstevel@tonic-gate int error; 543*0Sstevel@tonic-gate int instance; 544*0Sstevel@tonic-gate struct vgatext_softc *softc; 545*0Sstevel@tonic-gate 546*0Sstevel@tonic-gate error = DDI_SUCCESS; 547*0Sstevel@tonic-gate 548*0Sstevel@tonic-gate dev = (dev_t)arg; 549*0Sstevel@tonic-gate instance = DEV2INST(dev); 550*0Sstevel@tonic-gate softc = getsoftc(instance); 551*0Sstevel@tonic-gate 552*0Sstevel@tonic-gate switch (infocmd) { 553*0Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 554*0Sstevel@tonic-gate if (softc == NULL || softc->devi == NULL) { 555*0Sstevel@tonic-gate error = DDI_FAILURE; 556*0Sstevel@tonic-gate } else { 557*0Sstevel@tonic-gate *result = (void *) softc->devi; 558*0Sstevel@tonic-gate error = DDI_SUCCESS; 559*0Sstevel@tonic-gate } 560*0Sstevel@tonic-gate break; 561*0Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 562*0Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 563*0Sstevel@tonic-gate error = DDI_SUCCESS; 564*0Sstevel@tonic-gate break; 565*0Sstevel@tonic-gate default: 566*0Sstevel@tonic-gate error = DDI_FAILURE; 567*0Sstevel@tonic-gate break; 568*0Sstevel@tonic-gate } 569*0Sstevel@tonic-gate return (error); 570*0Sstevel@tonic-gate } 571*0Sstevel@tonic-gate 572*0Sstevel@tonic-gate 573*0Sstevel@tonic-gate /*ARGSUSED*/ 574*0Sstevel@tonic-gate static int 575*0Sstevel@tonic-gate vgatext_open(dev_t *devp, int flag, int otyp, cred_t *cred) 576*0Sstevel@tonic-gate { 577*0Sstevel@tonic-gate struct vgatext_softc *softc = getsoftc(DEV2INST(*devp)); 578*0Sstevel@tonic-gate 579*0Sstevel@tonic-gate if (softc == NULL || otyp == OTYP_BLK) 580*0Sstevel@tonic-gate return (ENXIO); 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate return (0); 583*0Sstevel@tonic-gate } 584*0Sstevel@tonic-gate 585*0Sstevel@tonic-gate /*ARGSUSED*/ 586*0Sstevel@tonic-gate static int 587*0Sstevel@tonic-gate vgatext_close(dev_t devp, int flag, int otyp, cred_t *cred) 588*0Sstevel@tonic-gate { 589*0Sstevel@tonic-gate return (0); 590*0Sstevel@tonic-gate } 591*0Sstevel@tonic-gate 592*0Sstevel@tonic-gate /*ARGSUSED*/ 593*0Sstevel@tonic-gate static int 594*0Sstevel@tonic-gate vgatext_ioctl( 595*0Sstevel@tonic-gate dev_t dev, 596*0Sstevel@tonic-gate int cmd, 597*0Sstevel@tonic-gate intptr_t data, 598*0Sstevel@tonic-gate int mode, 599*0Sstevel@tonic-gate cred_t *cred, 600*0Sstevel@tonic-gate int *rval) 601*0Sstevel@tonic-gate { 602*0Sstevel@tonic-gate struct vgatext_softc *softc = getsoftc(DEV2INST(dev)); 603*0Sstevel@tonic-gate static char kernel_only[] = "vgatext_ioctl: %s is a kernel only ioctl"; 604*0Sstevel@tonic-gate int err; 605*0Sstevel@tonic-gate int kd_mode; 606*0Sstevel@tonic-gate 607*0Sstevel@tonic-gate switch (cmd) { 608*0Sstevel@tonic-gate case KDSETMODE: 609*0Sstevel@tonic-gate return (vgatext_kdsetmode(softc, (int)data)); 610*0Sstevel@tonic-gate 611*0Sstevel@tonic-gate case KDGETMODE: 612*0Sstevel@tonic-gate kd_mode = softc->mode; 613*0Sstevel@tonic-gate if (ddi_copyout(&kd_mode, (void *)data, sizeof (int), mode)) 614*0Sstevel@tonic-gate return (EFAULT); 615*0Sstevel@tonic-gate break; 616*0Sstevel@tonic-gate 617*0Sstevel@tonic-gate case VIS_GETIDENTIFIER: 618*0Sstevel@tonic-gate if (ddi_copyout(&text_ident, (void *)data, 619*0Sstevel@tonic-gate sizeof (struct vis_identifier), mode)) 620*0Sstevel@tonic-gate return (EFAULT); 621*0Sstevel@tonic-gate break; 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate case VIS_DEVINIT: 624*0Sstevel@tonic-gate 625*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 626*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "VIS_DEVINIT"); 627*0Sstevel@tonic-gate return (ENXIO); 628*0Sstevel@tonic-gate } 629*0Sstevel@tonic-gate 630*0Sstevel@tonic-gate err = vgatext_devinit(softc, (struct vis_devinit *)data); 631*0Sstevel@tonic-gate if (err != 0) { 632*0Sstevel@tonic-gate cmn_err(CE_WARN, 633*0Sstevel@tonic-gate "vgatext_ioctl: could not initialize console"); 634*0Sstevel@tonic-gate return (err); 635*0Sstevel@tonic-gate } 636*0Sstevel@tonic-gate break; 637*0Sstevel@tonic-gate 638*0Sstevel@tonic-gate case VIS_CONSCOPY: /* move */ 639*0Sstevel@tonic-gate { 640*0Sstevel@tonic-gate struct vis_conscopy pma; 641*0Sstevel@tonic-gate 642*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &pma, 643*0Sstevel@tonic-gate sizeof (struct vis_conscopy), mode)) 644*0Sstevel@tonic-gate return (EFAULT); 645*0Sstevel@tonic-gate 646*0Sstevel@tonic-gate vgatext_cons_copy(softc, &pma); 647*0Sstevel@tonic-gate break; 648*0Sstevel@tonic-gate } 649*0Sstevel@tonic-gate 650*0Sstevel@tonic-gate case VIS_CONSDISPLAY: /* display */ 651*0Sstevel@tonic-gate { 652*0Sstevel@tonic-gate struct vis_consdisplay display_request; 653*0Sstevel@tonic-gate 654*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &display_request, 655*0Sstevel@tonic-gate sizeof (display_request), mode)) 656*0Sstevel@tonic-gate return (EFAULT); 657*0Sstevel@tonic-gate 658*0Sstevel@tonic-gate vgatext_cons_display(softc, &display_request); 659*0Sstevel@tonic-gate break; 660*0Sstevel@tonic-gate } 661*0Sstevel@tonic-gate 662*0Sstevel@tonic-gate case VIS_CONSCURSOR: 663*0Sstevel@tonic-gate { 664*0Sstevel@tonic-gate struct vis_conscursor cursor_request; 665*0Sstevel@tonic-gate 666*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &cursor_request, 667*0Sstevel@tonic-gate sizeof (cursor_request), mode)) 668*0Sstevel@tonic-gate return (EFAULT); 669*0Sstevel@tonic-gate 670*0Sstevel@tonic-gate vgatext_cons_cursor(softc, &cursor_request); 671*0Sstevel@tonic-gate 672*0Sstevel@tonic-gate if (cursor_request.action == VIS_GET_CURSOR && 673*0Sstevel@tonic-gate ddi_copyout(&cursor_request, (void *)data, 674*0Sstevel@tonic-gate sizeof (cursor_request), mode)) 675*0Sstevel@tonic-gate return (EFAULT); 676*0Sstevel@tonic-gate break; 677*0Sstevel@tonic-gate } 678*0Sstevel@tonic-gate 679*0Sstevel@tonic-gate case VIS_GETCMAP: 680*0Sstevel@tonic-gate case VIS_PUTCMAP: 681*0Sstevel@tonic-gate case FBIOPUTCMAP: 682*0Sstevel@tonic-gate case FBIOGETCMAP: 683*0Sstevel@tonic-gate /* 684*0Sstevel@tonic-gate * At the moment, text mode is not considered to have 685*0Sstevel@tonic-gate * a color map. 686*0Sstevel@tonic-gate */ 687*0Sstevel@tonic-gate return (EINVAL); 688*0Sstevel@tonic-gate 689*0Sstevel@tonic-gate case FBIOGATTR: 690*0Sstevel@tonic-gate if (copyout(&vgatext_attr, (void *)data, 691*0Sstevel@tonic-gate sizeof (struct fbgattr))) 692*0Sstevel@tonic-gate return (EFAULT); 693*0Sstevel@tonic-gate break; 694*0Sstevel@tonic-gate 695*0Sstevel@tonic-gate case FBIOGTYPE: 696*0Sstevel@tonic-gate if (copyout(&vgatext_attr.fbtype, (void *)data, 697*0Sstevel@tonic-gate sizeof (struct fbtype))) 698*0Sstevel@tonic-gate return (EFAULT); 699*0Sstevel@tonic-gate break; 700*0Sstevel@tonic-gate 701*0Sstevel@tonic-gate #if 0 702*0Sstevel@tonic-gate case GLY_LD_GLYPH: 703*0Sstevel@tonic-gate { 704*0Sstevel@tonic-gate temstat_t *ap; 705*0Sstevel@tonic-gate da_t da; 706*0Sstevel@tonic-gate struct glyph g; 707*0Sstevel@tonic-gate int size; 708*0Sstevel@tonic-gate uchar_t *c; 709*0Sstevel@tonic-gate 710*0Sstevel@tonic-gate if (ddi_copyin(arg, &g, sizeof (g), flag)) 711*0Sstevel@tonic-gate return (EFAULT); 712*0Sstevel@tonic-gate 713*0Sstevel@tonic-gate size = g.width * g.height; 714*0Sstevel@tonic-gate c = kmem_alloc(size, KM_SLEEP); 715*0Sstevel@tonic-gate 716*0Sstevel@tonic-gate if (ddi_copyin(g.raster, c, size, flag)) { 717*0Sstevel@tonic-gate kmem_free(c, size); 718*0Sstevel@tonic-gate return (EFAULT); 719*0Sstevel@tonic-gate } 720*0Sstevel@tonic-gate ap = (temstat_t *)something; 721*0Sstevel@tonic-gate da.data = c; 722*0Sstevel@tonic-gate da.width = g.width; 723*0Sstevel@tonic-gate da.height = g.height; 724*0Sstevel@tonic-gate da.col = g.x_dest; 725*0Sstevel@tonic-gate da.row = g.y_dest; 726*0Sstevel@tonic-gate ap->a_fp.f_ad_display(ap->a_private, &da); 727*0Sstevel@tonic-gate kmem_free(c, size); 728*0Sstevel@tonic-gate return (0); 729*0Sstevel@tonic-gate } 730*0Sstevel@tonic-gate #endif 731*0Sstevel@tonic-gate case DEVICE_DETECT: 732*0Sstevel@tonic-gate { 733*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 734*0Sstevel@tonic-gate 735*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 736*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "DEVICE_DETECT"); 737*0Sstevel@tonic-gate return (ENXIO); 738*0Sstevel@tonic-gate } 739*0Sstevel@tonic-gate agp_master = softc->agp_master; 740*0Sstevel@tonic-gate ASSERT(agp_master); 741*0Sstevel@tonic-gate 742*0Sstevel@tonic-gate if (!agp_master) 743*0Sstevel@tonic-gate return (EINVAL); 744*0Sstevel@tonic-gate 745*0Sstevel@tonic-gate if (ddi_copyout(&agp_master->agpm_dev_type, 746*0Sstevel@tonic-gate (void *)data, sizeof (int), mode)) 747*0Sstevel@tonic-gate return (EFAULT); 748*0Sstevel@tonic-gate break; 749*0Sstevel@tonic-gate } 750*0Sstevel@tonic-gate case I8XX_GET_INFO: 751*0Sstevel@tonic-gate { 752*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 753*0Sstevel@tonic-gate 754*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 755*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_GET_INFO"); 756*0Sstevel@tonic-gate return (ENXIO); 757*0Sstevel@tonic-gate } 758*0Sstevel@tonic-gate agp_master = softc->agp_master; 759*0Sstevel@tonic-gate ASSERT(agp_master); 760*0Sstevel@tonic-gate 761*0Sstevel@tonic-gate if (!agp_master) 762*0Sstevel@tonic-gate return (EINVAL); 763*0Sstevel@tonic-gate ASSERT((agp_master->agpm_dev_type == DEVICE_IS_I810) || 764*0Sstevel@tonic-gate (agp_master->agpm_dev_type == DEVICE_IS_I830)); 765*0Sstevel@tonic-gate 766*0Sstevel@tonic-gate if ((agp_master->agpm_dev_type != DEVICE_IS_I810) && 767*0Sstevel@tonic-gate (agp_master->agpm_dev_type != DEVICE_IS_I830)) 768*0Sstevel@tonic-gate return (EINVAL); 769*0Sstevel@tonic-gate 770*0Sstevel@tonic-gate if (ddi_copyout(&agp_master->agpm_data.agpm_gtt.gtt_info, 771*0Sstevel@tonic-gate (void *)data, 772*0Sstevel@tonic-gate sizeof (igd_info_t), mode)) 773*0Sstevel@tonic-gate return (EFAULT); 774*0Sstevel@tonic-gate break; 775*0Sstevel@tonic-gate } 776*0Sstevel@tonic-gate case I810_SET_GTT_BASE: 777*0Sstevel@tonic-gate { 778*0Sstevel@tonic-gate uint32_t base; 779*0Sstevel@tonic-gate uint32_t addr; 780*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 781*0Sstevel@tonic-gate 782*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 783*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_SET_GTT_ADDR"); 784*0Sstevel@tonic-gate return (ENXIO); 785*0Sstevel@tonic-gate } 786*0Sstevel@tonic-gate agp_master = softc->agp_master; 787*0Sstevel@tonic-gate ASSERT(agp_master); 788*0Sstevel@tonic-gate if (!agp_master) 789*0Sstevel@tonic-gate return (EINVAL); 790*0Sstevel@tonic-gate ASSERT(agp_master->agpm_dev_type == DEVICE_IS_I810); 791*0Sstevel@tonic-gate if (agp_master->agpm_dev_type != DEVICE_IS_I810) 792*0Sstevel@tonic-gate return (EINVAL); 793*0Sstevel@tonic-gate 794*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &base, sizeof (uint32_t), mode)) 795*0Sstevel@tonic-gate return (EFAULT); 796*0Sstevel@tonic-gate 797*0Sstevel@tonic-gate /* enables page table */ 798*0Sstevel@tonic-gate addr = (base & GTT_BASE_MASK) | GTT_TABLE_VALID; 799*0Sstevel@tonic-gate 800*0Sstevel@tonic-gate ddi_put32(agp_master->agpm_data.agpm_gtt.gtt_mmio_handle, 801*0Sstevel@tonic-gate (uint32_t *)(agp_master->agpm_data.agpm_gtt.gtt_mmio_base + 802*0Sstevel@tonic-gate I8XX_PGTBL_CTL), 803*0Sstevel@tonic-gate addr); 804*0Sstevel@tonic-gate break; 805*0Sstevel@tonic-gate } 806*0Sstevel@tonic-gate case I8XX_ADD2GTT: 807*0Sstevel@tonic-gate { 808*0Sstevel@tonic-gate igd_gtt_seg_t seg; 809*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 810*0Sstevel@tonic-gate 811*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 812*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_ADD2GTT"); 813*0Sstevel@tonic-gate return (ENXIO); 814*0Sstevel@tonic-gate } 815*0Sstevel@tonic-gate agp_master = softc->agp_master; 816*0Sstevel@tonic-gate ASSERT(agp_master); 817*0Sstevel@tonic-gate if (!agp_master) 818*0Sstevel@tonic-gate return (EINVAL); 819*0Sstevel@tonic-gate ASSERT((agp_master->agpm_dev_type == DEVICE_IS_I810) || 820*0Sstevel@tonic-gate (agp_master->agpm_dev_type == DEVICE_IS_I830)); 821*0Sstevel@tonic-gate 822*0Sstevel@tonic-gate if ((agp_master->agpm_dev_type != DEVICE_IS_I810) && 823*0Sstevel@tonic-gate (agp_master->agpm_dev_type != DEVICE_IS_I830)) 824*0Sstevel@tonic-gate return (EINVAL); 825*0Sstevel@tonic-gate 826*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &seg, 827*0Sstevel@tonic-gate sizeof (igd_gtt_seg_t), mode)) 828*0Sstevel@tonic-gate return (EFAULT); 829*0Sstevel@tonic-gate 830*0Sstevel@tonic-gate if (i8xx_add_to_gtt(&agp_master->agpm_data.agpm_gtt, seg)) 831*0Sstevel@tonic-gate return (EINVAL); 832*0Sstevel@tonic-gate break; 833*0Sstevel@tonic-gate } 834*0Sstevel@tonic-gate case I8XX_REM_GTT: 835*0Sstevel@tonic-gate { 836*0Sstevel@tonic-gate igd_gtt_seg_t seg; 837*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 838*0Sstevel@tonic-gate 839*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 840*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_REM_GTT"); 841*0Sstevel@tonic-gate return (ENXIO); 842*0Sstevel@tonic-gate } 843*0Sstevel@tonic-gate agp_master = softc->agp_master; 844*0Sstevel@tonic-gate ASSERT(agp_master); 845*0Sstevel@tonic-gate if (!agp_master) 846*0Sstevel@tonic-gate return (EINVAL); 847*0Sstevel@tonic-gate ASSERT((agp_master->agpm_dev_type == DEVICE_IS_I810) || 848*0Sstevel@tonic-gate (agp_master->agpm_dev_type == DEVICE_IS_I830)); 849*0Sstevel@tonic-gate 850*0Sstevel@tonic-gate if ((agp_master->agpm_dev_type != DEVICE_IS_I810) && 851*0Sstevel@tonic-gate (agp_master->agpm_dev_type != DEVICE_IS_I830)) 852*0Sstevel@tonic-gate return (EINVAL); 853*0Sstevel@tonic-gate 854*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &seg, 855*0Sstevel@tonic-gate sizeof (igd_gtt_seg_t), mode)) 856*0Sstevel@tonic-gate return (EFAULT); 857*0Sstevel@tonic-gate 858*0Sstevel@tonic-gate i8xx_remove_from_gtt(&agp_master->agpm_data.agpm_gtt, seg); 859*0Sstevel@tonic-gate break; 860*0Sstevel@tonic-gate } 861*0Sstevel@tonic-gate case I8XX_UNCONFIG: 862*0Sstevel@tonic-gate { 863*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 864*0Sstevel@tonic-gate 865*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 866*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "I8XX_UNCONFIG"); 867*0Sstevel@tonic-gate return (ENXIO); 868*0Sstevel@tonic-gate } 869*0Sstevel@tonic-gate agp_master = softc->agp_master; 870*0Sstevel@tonic-gate ASSERT(agp_master); 871*0Sstevel@tonic-gate if (!agp_master) 872*0Sstevel@tonic-gate return (EINVAL); 873*0Sstevel@tonic-gate ASSERT((agp_master->agpm_dev_type == DEVICE_IS_I810) || 874*0Sstevel@tonic-gate (agp_master->agpm_dev_type == DEVICE_IS_I830)); 875*0Sstevel@tonic-gate 876*0Sstevel@tonic-gate if ((agp_master->agpm_dev_type != DEVICE_IS_I810) && 877*0Sstevel@tonic-gate (agp_master->agpm_dev_type != DEVICE_IS_I830)) 878*0Sstevel@tonic-gate return (EINVAL); 879*0Sstevel@tonic-gate 880*0Sstevel@tonic-gate if (agp_master->agpm_dev_type == DEVICE_IS_I810) 881*0Sstevel@tonic-gate ddi_put32( 882*0Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_mmio_handle, 883*0Sstevel@tonic-gate (uint32_t *) 884*0Sstevel@tonic-gate (agp_master->agpm_data.agpm_gtt.gtt_mmio_base + 885*0Sstevel@tonic-gate I8XX_PGTBL_CTL), 886*0Sstevel@tonic-gate 0); 887*0Sstevel@tonic-gate /* 888*0Sstevel@tonic-gate * may clear all gtt entries here for i830, 889*0Sstevel@tonic-gate * but may not be necessary 890*0Sstevel@tonic-gate */ 891*0Sstevel@tonic-gate break; 892*0Sstevel@tonic-gate } 893*0Sstevel@tonic-gate case AGP_MASTER_GETINFO: 894*0Sstevel@tonic-gate { 895*0Sstevel@tonic-gate agp_info_t info; 896*0Sstevel@tonic-gate uint32_t value; 897*0Sstevel@tonic-gate off_t cap; 898*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 899*0Sstevel@tonic-gate 900*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 901*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "AGP_MASTER_GETINFO"); 902*0Sstevel@tonic-gate return (ENXIO); 903*0Sstevel@tonic-gate } 904*0Sstevel@tonic-gate agp_master = softc->agp_master; 905*0Sstevel@tonic-gate ASSERT(agp_master); 906*0Sstevel@tonic-gate if (!agp_master) 907*0Sstevel@tonic-gate return (EINVAL); 908*0Sstevel@tonic-gate ASSERT(agp_master->agpm_dev_type == DEVICE_IS_AGP); 909*0Sstevel@tonic-gate if (agp_master->agpm_dev_type != DEVICE_IS_AGP) 910*0Sstevel@tonic-gate return (EINVAL); 911*0Sstevel@tonic-gate 912*0Sstevel@tonic-gate ASSERT(agp_master->agpm_data.agpm_acaptr); 913*0Sstevel@tonic-gate if (agp_master->agpm_data.agpm_acaptr == 0) 914*0Sstevel@tonic-gate return (EINVAL); 915*0Sstevel@tonic-gate 916*0Sstevel@tonic-gate cap = agp_master->agpm_data.agpm_acaptr; 917*0Sstevel@tonic-gate value = pci_config_get32(agp_master->agpm_acc_hdl, cap); 918*0Sstevel@tonic-gate info.agpi_version.agpv_major = (uint16_t)((value >> 20) & 0xf); 919*0Sstevel@tonic-gate info.agpi_version.agpv_minor = (uint16_t)((value >> 16) & 0xf); 920*0Sstevel@tonic-gate info.agpi_devid = agp_master->agpm_id; 921*0Sstevel@tonic-gate info.agpi_mode = pci_config_get32( 922*0Sstevel@tonic-gate agp_master->agpm_acc_hdl, cap + AGP_CONF_STATUS); 923*0Sstevel@tonic-gate 924*0Sstevel@tonic-gate if (ddi_copyout(&info, (void *)data, 925*0Sstevel@tonic-gate sizeof (agp_info_t), mode)) 926*0Sstevel@tonic-gate return (EFAULT); 927*0Sstevel@tonic-gate break; 928*0Sstevel@tonic-gate } 929*0Sstevel@tonic-gate case AGP_MASTER_SETCMD: 930*0Sstevel@tonic-gate { 931*0Sstevel@tonic-gate uint32_t command; 932*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 933*0Sstevel@tonic-gate 934*0Sstevel@tonic-gate if (!(mode & FKIOCTL)) { 935*0Sstevel@tonic-gate cmn_err(CE_CONT, kernel_only, "AGP_MASTER_SETCMD"); 936*0Sstevel@tonic-gate return (ENXIO); 937*0Sstevel@tonic-gate } 938*0Sstevel@tonic-gate agp_master = softc->agp_master; 939*0Sstevel@tonic-gate ASSERT(agp_master); 940*0Sstevel@tonic-gate if (!agp_master) 941*0Sstevel@tonic-gate return (EINVAL); 942*0Sstevel@tonic-gate ASSERT(agp_master->agpm_dev_type == DEVICE_IS_AGP); 943*0Sstevel@tonic-gate if (agp_master->agpm_dev_type != DEVICE_IS_AGP) 944*0Sstevel@tonic-gate return (EINVAL); 945*0Sstevel@tonic-gate 946*0Sstevel@tonic-gate ASSERT(agp_master->agpm_data.agpm_acaptr); 947*0Sstevel@tonic-gate if (agp_master->agpm_data.agpm_acaptr == 0) 948*0Sstevel@tonic-gate return (EINVAL); 949*0Sstevel@tonic-gate 950*0Sstevel@tonic-gate if (ddi_copyin((void *)data, &command, 951*0Sstevel@tonic-gate sizeof (uint32_t), mode)) 952*0Sstevel@tonic-gate return (EFAULT); 953*0Sstevel@tonic-gate 954*0Sstevel@tonic-gate pci_config_put32(agp_master->agpm_acc_hdl, 955*0Sstevel@tonic-gate agp_master->agpm_data.agpm_acaptr + AGP_CONF_COMMAND, 956*0Sstevel@tonic-gate command); 957*0Sstevel@tonic-gate break; 958*0Sstevel@tonic-gate 959*0Sstevel@tonic-gate } 960*0Sstevel@tonic-gate default: 961*0Sstevel@tonic-gate return (ENXIO); 962*0Sstevel@tonic-gate } 963*0Sstevel@tonic-gate return (0); 964*0Sstevel@tonic-gate } 965*0Sstevel@tonic-gate 966*0Sstevel@tonic-gate static int 967*0Sstevel@tonic-gate vgatext_kdsetmode(struct vgatext_softc *softc, int mode) 968*0Sstevel@tonic-gate { 969*0Sstevel@tonic-gate int i; 970*0Sstevel@tonic-gate 971*0Sstevel@tonic-gate if (mode == softc->mode) 972*0Sstevel@tonic-gate return (0); 973*0Sstevel@tonic-gate 974*0Sstevel@tonic-gate switch (mode) { 975*0Sstevel@tonic-gate case KD_TEXT: 976*0Sstevel@tonic-gate vgatext_init(softc); 977*0Sstevel@tonic-gate for (i = 0; i < sizeof (softc->shadow); i++) { 978*0Sstevel@tonic-gate softc->text_base[i] = softc->shadow[i]; 979*0Sstevel@tonic-gate } 980*0Sstevel@tonic-gate softc->current_base = softc->text_base; 981*0Sstevel@tonic-gate if (softc->cursor.visible) { 982*0Sstevel@tonic-gate vgatext_set_cursor(softc, 983*0Sstevel@tonic-gate softc->cursor.row, softc->cursor.col); 984*0Sstevel@tonic-gate } 985*0Sstevel@tonic-gate vgatext_restore_colormap(softc); 986*0Sstevel@tonic-gate break; 987*0Sstevel@tonic-gate 988*0Sstevel@tonic-gate case KD_GRAPHICS: 989*0Sstevel@tonic-gate if (vgatext_silent == 1) { 990*0Sstevel@tonic-gate extern void progressbar_stop(void); 991*0Sstevel@tonic-gate 992*0Sstevel@tonic-gate vgatext_silent = 0; 993*0Sstevel@tonic-gate progressbar_stop(); 994*0Sstevel@tonic-gate } 995*0Sstevel@tonic-gate for (i = 0; i < sizeof (softc->shadow); i++) { 996*0Sstevel@tonic-gate softc->shadow[i] = softc->text_base[i]; 997*0Sstevel@tonic-gate } 998*0Sstevel@tonic-gate softc->current_base = softc->shadow; 999*0Sstevel@tonic-gate #if defined(USE_BORDERS) 1000*0Sstevel@tonic-gate vgatext_init_graphics(softc); 1001*0Sstevel@tonic-gate #endif 1002*0Sstevel@tonic-gate break; 1003*0Sstevel@tonic-gate 1004*0Sstevel@tonic-gate default: 1005*0Sstevel@tonic-gate return (EINVAL); 1006*0Sstevel@tonic-gate } 1007*0Sstevel@tonic-gate softc->mode = mode; 1008*0Sstevel@tonic-gate return (0); 1009*0Sstevel@tonic-gate } 1010*0Sstevel@tonic-gate 1011*0Sstevel@tonic-gate /*ARGSUSED*/ 1012*0Sstevel@tonic-gate static int 1013*0Sstevel@tonic-gate vgatext_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len, 1014*0Sstevel@tonic-gate size_t *maplen, uint_t model) 1015*0Sstevel@tonic-gate { 1016*0Sstevel@tonic-gate struct vgatext_softc *softc; 1017*0Sstevel@tonic-gate int err; 1018*0Sstevel@tonic-gate size_t length; 1019*0Sstevel@tonic-gate 1020*0Sstevel@tonic-gate 1021*0Sstevel@tonic-gate softc = getsoftc(DEV2INST(dev)); 1022*0Sstevel@tonic-gate if (softc == NULL) { 1023*0Sstevel@tonic-gate cmn_err(CE_WARN, "vgatext: Can't find softstate"); 1024*0Sstevel@tonic-gate return (-1); 1025*0Sstevel@tonic-gate } 1026*0Sstevel@tonic-gate 1027*0Sstevel@tonic-gate if (!(off >= VGA_MMAP_FB_BASE && 1028*0Sstevel@tonic-gate off < VGA_MMAP_FB_BASE + softc->fb_size)) { 1029*0Sstevel@tonic-gate cmn_err(CE_WARN, "vgatext: Can't map offset 0x%llx", off); 1030*0Sstevel@tonic-gate return (-1); 1031*0Sstevel@tonic-gate } 1032*0Sstevel@tonic-gate 1033*0Sstevel@tonic-gate if (off + len > VGA_MMAP_FB_BASE + softc->fb_size) 1034*0Sstevel@tonic-gate length = VGA_MMAP_FB_BASE + softc->fb_size - off; 1035*0Sstevel@tonic-gate else 1036*0Sstevel@tonic-gate length = len; 1037*0Sstevel@tonic-gate 1038*0Sstevel@tonic-gate if ((err = devmap_devmem_setup(dhp, softc->devi, NULL, softc->fb_regno, 1039*0Sstevel@tonic-gate off - VGA_MMAP_FB_BASE, 1040*0Sstevel@tonic-gate length, PROT_ALL, 0, &dev_attr)) < 0) { 1041*0Sstevel@tonic-gate return (err); 1042*0Sstevel@tonic-gate } 1043*0Sstevel@tonic-gate 1044*0Sstevel@tonic-gate 1045*0Sstevel@tonic-gate *maplen = length; 1046*0Sstevel@tonic-gate return (0); 1047*0Sstevel@tonic-gate } 1048*0Sstevel@tonic-gate 1049*0Sstevel@tonic-gate 1050*0Sstevel@tonic-gate static int 1051*0Sstevel@tonic-gate vgatext_devinit(struct vgatext_softc *softc, struct vis_devinit *data) 1052*0Sstevel@tonic-gate { 1053*0Sstevel@tonic-gate /* initialize console instance */ 1054*0Sstevel@tonic-gate data->version = VIS_CONS_REV; 1055*0Sstevel@tonic-gate data->width = TEXT_COLS; 1056*0Sstevel@tonic-gate data->height = TEXT_ROWS; 1057*0Sstevel@tonic-gate data->linebytes = TEXT_COLS; 1058*0Sstevel@tonic-gate data->depth = 4; 1059*0Sstevel@tonic-gate data->mode = VIS_TEXT; 1060*0Sstevel@tonic-gate data->polledio = &softc->polledio; 1061*0Sstevel@tonic-gate 1062*0Sstevel@tonic-gate return (0); 1063*0Sstevel@tonic-gate } 1064*0Sstevel@tonic-gate 1065*0Sstevel@tonic-gate /* 1066*0Sstevel@tonic-gate * display a string on the screen at (row, col) 1067*0Sstevel@tonic-gate * assume it has been cropped to fit. 1068*0Sstevel@tonic-gate */ 1069*0Sstevel@tonic-gate 1070*0Sstevel@tonic-gate static void 1071*0Sstevel@tonic-gate vgatext_cons_display(struct vgatext_softc *softc, struct vis_consdisplay *da) 1072*0Sstevel@tonic-gate { 1073*0Sstevel@tonic-gate unsigned char *string; 1074*0Sstevel@tonic-gate int i; 1075*0Sstevel@tonic-gate unsigned char attr; 1076*0Sstevel@tonic-gate struct cgatext { 1077*0Sstevel@tonic-gate unsigned char ch; 1078*0Sstevel@tonic-gate unsigned char attr; 1079*0Sstevel@tonic-gate }; 1080*0Sstevel@tonic-gate struct cgatext *addr; 1081*0Sstevel@tonic-gate 1082*0Sstevel@tonic-gate if (vgatext_silent) 1083*0Sstevel@tonic-gate return; 1084*0Sstevel@tonic-gate /* 1085*0Sstevel@tonic-gate * Sanity checks. This is a last-ditch effort to avoid damage 1086*0Sstevel@tonic-gate * from brokenness or maliciousness above. 1087*0Sstevel@tonic-gate */ 1088*0Sstevel@tonic-gate if (da->row < 0 || da->row >= TEXT_ROWS || 1089*0Sstevel@tonic-gate da->col < 0 || da->col >= TEXT_COLS || 1090*0Sstevel@tonic-gate da->col + da->width > TEXT_COLS) 1091*0Sstevel@tonic-gate return; 1092*0Sstevel@tonic-gate 1093*0Sstevel@tonic-gate /* 1094*0Sstevel@tonic-gate * To be fully general, we should copyin the data. This is not 1095*0Sstevel@tonic-gate * really relevant for this text-only driver, but a graphical driver 1096*0Sstevel@tonic-gate * should support these ioctls from userland to enable simple 1097*0Sstevel@tonic-gate * system startup graphics. 1098*0Sstevel@tonic-gate */ 1099*0Sstevel@tonic-gate attr = (solaris_color_to_pc_color[da->bg_color & 0xf] << 4) 1100*0Sstevel@tonic-gate | solaris_color_to_pc_color[da->fg_color & 0xf]; 1101*0Sstevel@tonic-gate string = da->data; 1102*0Sstevel@tonic-gate addr = (struct cgatext *)softc->current_base 1103*0Sstevel@tonic-gate + (da->row * TEXT_COLS + da->col); 1104*0Sstevel@tonic-gate for (i = 0; i < da->width; i++) { 1105*0Sstevel@tonic-gate addr->ch = string[i]; 1106*0Sstevel@tonic-gate addr->attr = attr; 1107*0Sstevel@tonic-gate addr++; 1108*0Sstevel@tonic-gate } 1109*0Sstevel@tonic-gate } 1110*0Sstevel@tonic-gate 1111*0Sstevel@tonic-gate static void 1112*0Sstevel@tonic-gate vgatext_polled_display( 1113*0Sstevel@tonic-gate struct vis_polledio_arg *arg, 1114*0Sstevel@tonic-gate struct vis_consdisplay *da) 1115*0Sstevel@tonic-gate { 1116*0Sstevel@tonic-gate vgatext_cons_display((struct vgatext_softc *)arg, da); 1117*0Sstevel@tonic-gate } 1118*0Sstevel@tonic-gate 1119*0Sstevel@tonic-gate /* 1120*0Sstevel@tonic-gate * screen-to-screen copy 1121*0Sstevel@tonic-gate */ 1122*0Sstevel@tonic-gate 1123*0Sstevel@tonic-gate static void 1124*0Sstevel@tonic-gate vgatext_cons_copy(struct vgatext_softc *softc, struct vis_conscopy *ma) 1125*0Sstevel@tonic-gate { 1126*0Sstevel@tonic-gate unsigned short *from; 1127*0Sstevel@tonic-gate unsigned short *to; 1128*0Sstevel@tonic-gate int cnt; 1129*0Sstevel@tonic-gate screen_size_t chars_per_row; 1130*0Sstevel@tonic-gate unsigned short *to_row_start; 1131*0Sstevel@tonic-gate unsigned short *from_row_start; 1132*0Sstevel@tonic-gate screen_size_t rows_to_move; 1133*0Sstevel@tonic-gate unsigned short *base; 1134*0Sstevel@tonic-gate 1135*0Sstevel@tonic-gate if (vgatext_silent) 1136*0Sstevel@tonic-gate return; 1137*0Sstevel@tonic-gate 1138*0Sstevel@tonic-gate /* 1139*0Sstevel@tonic-gate * Sanity checks. Note that this is a last-ditch effort to avoid 1140*0Sstevel@tonic-gate * damage caused by broken-ness or maliciousness above. 1141*0Sstevel@tonic-gate */ 1142*0Sstevel@tonic-gate if (ma->s_col < 0 || ma->s_col >= TEXT_COLS || 1143*0Sstevel@tonic-gate ma->s_row < 0 || ma->s_row >= TEXT_ROWS || 1144*0Sstevel@tonic-gate ma->e_col < 0 || ma->e_col >= TEXT_COLS || 1145*0Sstevel@tonic-gate ma->e_row < 0 || ma->e_row >= TEXT_ROWS || 1146*0Sstevel@tonic-gate ma->t_col < 0 || ma->t_col >= TEXT_COLS || 1147*0Sstevel@tonic-gate ma->t_row < 0 || ma->t_row >= TEXT_ROWS || 1148*0Sstevel@tonic-gate ma->s_col > ma->e_col || 1149*0Sstevel@tonic-gate ma->s_row > ma->e_row) 1150*0Sstevel@tonic-gate return; 1151*0Sstevel@tonic-gate 1152*0Sstevel@tonic-gate /* 1153*0Sstevel@tonic-gate * Remember we're going to copy shorts because each 1154*0Sstevel@tonic-gate * character/attribute pair is 16 bits. 1155*0Sstevel@tonic-gate */ 1156*0Sstevel@tonic-gate chars_per_row = ma->e_col - ma->s_col + 1; 1157*0Sstevel@tonic-gate rows_to_move = ma->e_row - ma->s_row + 1; 1158*0Sstevel@tonic-gate 1159*0Sstevel@tonic-gate /* More sanity checks. */ 1160*0Sstevel@tonic-gate if (ma->t_row + rows_to_move > TEXT_ROWS || 1161*0Sstevel@tonic-gate ma->t_col + chars_per_row > TEXT_COLS) 1162*0Sstevel@tonic-gate return; 1163*0Sstevel@tonic-gate 1164*0Sstevel@tonic-gate base = (unsigned short *)softc->current_base; 1165*0Sstevel@tonic-gate 1166*0Sstevel@tonic-gate to_row_start = base + ((ma->t_row * TEXT_COLS) + ma->t_col); 1167*0Sstevel@tonic-gate from_row_start = base + ((ma->s_row * TEXT_COLS) + ma->s_col); 1168*0Sstevel@tonic-gate 1169*0Sstevel@tonic-gate if (to_row_start < from_row_start) { 1170*0Sstevel@tonic-gate while (rows_to_move-- > 0) { 1171*0Sstevel@tonic-gate to = to_row_start; 1172*0Sstevel@tonic-gate from = from_row_start; 1173*0Sstevel@tonic-gate to_row_start += TEXT_COLS; 1174*0Sstevel@tonic-gate from_row_start += TEXT_COLS; 1175*0Sstevel@tonic-gate for (cnt = chars_per_row; cnt-- > 0; ) 1176*0Sstevel@tonic-gate *to++ = *from++; 1177*0Sstevel@tonic-gate } 1178*0Sstevel@tonic-gate } else { 1179*0Sstevel@tonic-gate /* 1180*0Sstevel@tonic-gate * Offset to the end of the region and copy backwards. 1181*0Sstevel@tonic-gate */ 1182*0Sstevel@tonic-gate cnt = rows_to_move * TEXT_COLS + chars_per_row; 1183*0Sstevel@tonic-gate to_row_start += cnt; 1184*0Sstevel@tonic-gate from_row_start += cnt; 1185*0Sstevel@tonic-gate 1186*0Sstevel@tonic-gate while (rows_to_move-- > 0) { 1187*0Sstevel@tonic-gate to_row_start -= TEXT_COLS; 1188*0Sstevel@tonic-gate from_row_start -= TEXT_COLS; 1189*0Sstevel@tonic-gate to = to_row_start; 1190*0Sstevel@tonic-gate from = from_row_start; 1191*0Sstevel@tonic-gate for (cnt = chars_per_row; cnt-- > 0; ) 1192*0Sstevel@tonic-gate *--to = *--from; 1193*0Sstevel@tonic-gate } 1194*0Sstevel@tonic-gate } 1195*0Sstevel@tonic-gate } 1196*0Sstevel@tonic-gate 1197*0Sstevel@tonic-gate static void 1198*0Sstevel@tonic-gate vgatext_polled_copy( 1199*0Sstevel@tonic-gate struct vis_polledio_arg *arg, 1200*0Sstevel@tonic-gate struct vis_conscopy *ca) 1201*0Sstevel@tonic-gate { 1202*0Sstevel@tonic-gate vgatext_cons_copy((struct vgatext_softc *)arg, ca); 1203*0Sstevel@tonic-gate } 1204*0Sstevel@tonic-gate 1205*0Sstevel@tonic-gate 1206*0Sstevel@tonic-gate static void 1207*0Sstevel@tonic-gate vgatext_cons_cursor(struct vgatext_softc *softc, struct vis_conscursor *ca) 1208*0Sstevel@tonic-gate { 1209*0Sstevel@tonic-gate if (vgatext_silent) 1210*0Sstevel@tonic-gate return; 1211*0Sstevel@tonic-gate 1212*0Sstevel@tonic-gate switch (ca->action) { 1213*0Sstevel@tonic-gate case VIS_HIDE_CURSOR: 1214*0Sstevel@tonic-gate softc->cursor.visible = B_FALSE; 1215*0Sstevel@tonic-gate if (softc->current_base == softc->text_base) 1216*0Sstevel@tonic-gate vgatext_hide_cursor(softc); 1217*0Sstevel@tonic-gate break; 1218*0Sstevel@tonic-gate case VIS_DISPLAY_CURSOR: 1219*0Sstevel@tonic-gate /* 1220*0Sstevel@tonic-gate * Sanity check. This is a last-ditch effort to avoid 1221*0Sstevel@tonic-gate * damage from brokenness or maliciousness above. 1222*0Sstevel@tonic-gate */ 1223*0Sstevel@tonic-gate if (ca->col < 0 || ca->col >= TEXT_COLS || 1224*0Sstevel@tonic-gate ca->row < 0 || ca->row >= TEXT_ROWS) 1225*0Sstevel@tonic-gate return; 1226*0Sstevel@tonic-gate 1227*0Sstevel@tonic-gate softc->cursor.visible = B_TRUE; 1228*0Sstevel@tonic-gate softc->cursor.col = ca->col; 1229*0Sstevel@tonic-gate softc->cursor.row = ca->row; 1230*0Sstevel@tonic-gate if (softc->current_base == softc->text_base) 1231*0Sstevel@tonic-gate vgatext_set_cursor(softc, ca->row, ca->col); 1232*0Sstevel@tonic-gate break; 1233*0Sstevel@tonic-gate case VIS_GET_CURSOR: 1234*0Sstevel@tonic-gate if (softc->current_base == softc->text_base) { 1235*0Sstevel@tonic-gate vgatext_get_cursor(softc, &ca->row, &ca->col); 1236*0Sstevel@tonic-gate } 1237*0Sstevel@tonic-gate break; 1238*0Sstevel@tonic-gate } 1239*0Sstevel@tonic-gate } 1240*0Sstevel@tonic-gate 1241*0Sstevel@tonic-gate static void 1242*0Sstevel@tonic-gate vgatext_polled_cursor( 1243*0Sstevel@tonic-gate struct vis_polledio_arg *arg, 1244*0Sstevel@tonic-gate struct vis_conscursor *ca) 1245*0Sstevel@tonic-gate { 1246*0Sstevel@tonic-gate vgatext_cons_cursor((struct vgatext_softc *)arg, ca); 1247*0Sstevel@tonic-gate } 1248*0Sstevel@tonic-gate 1249*0Sstevel@tonic-gate 1250*0Sstevel@tonic-gate 1251*0Sstevel@tonic-gate /*ARGSUSED*/ 1252*0Sstevel@tonic-gate static void 1253*0Sstevel@tonic-gate vgatext_hide_cursor(struct vgatext_softc *softc) 1254*0Sstevel@tonic-gate { 1255*0Sstevel@tonic-gate /* Nothing at present */ 1256*0Sstevel@tonic-gate } 1257*0Sstevel@tonic-gate 1258*0Sstevel@tonic-gate static void 1259*0Sstevel@tonic-gate vgatext_set_cursor(struct vgatext_softc *softc, int row, int col) 1260*0Sstevel@tonic-gate { 1261*0Sstevel@tonic-gate short addr; 1262*0Sstevel@tonic-gate 1263*0Sstevel@tonic-gate if (vgatext_silent) 1264*0Sstevel@tonic-gate return; 1265*0Sstevel@tonic-gate 1266*0Sstevel@tonic-gate addr = row * TEXT_COLS + col; 1267*0Sstevel@tonic-gate 1268*0Sstevel@tonic-gate vga_set_crtc(&softc->regs, VGA_CRTC_CLAH, addr >> 8); 1269*0Sstevel@tonic-gate vga_set_crtc(&softc->regs, VGA_CRTC_CLAL, addr & 0xff); 1270*0Sstevel@tonic-gate } 1271*0Sstevel@tonic-gate 1272*0Sstevel@tonic-gate static int vga_row, vga_col; 1273*0Sstevel@tonic-gate 1274*0Sstevel@tonic-gate static void 1275*0Sstevel@tonic-gate vgatext_get_cursor(struct vgatext_softc *softc, 1276*0Sstevel@tonic-gate screen_pos_t *row, screen_pos_t *col) 1277*0Sstevel@tonic-gate { 1278*0Sstevel@tonic-gate short addr; 1279*0Sstevel@tonic-gate 1280*0Sstevel@tonic-gate addr = (vga_get_crtc(&softc->regs, VGA_CRTC_CLAH) << 8) + 1281*0Sstevel@tonic-gate vga_get_crtc(&softc->regs, VGA_CRTC_CLAL); 1282*0Sstevel@tonic-gate 1283*0Sstevel@tonic-gate vga_row = *row = addr / TEXT_COLS; 1284*0Sstevel@tonic-gate vga_col = *col = addr % TEXT_COLS; 1285*0Sstevel@tonic-gate } 1286*0Sstevel@tonic-gate 1287*0Sstevel@tonic-gate /* 1288*0Sstevel@tonic-gate * This code is experimental. It's only enabled if console is 1289*0Sstevel@tonic-gate * set to graphics, a preliminary implementation of happyface boot. 1290*0Sstevel@tonic-gate */ 1291*0Sstevel@tonic-gate static void 1292*0Sstevel@tonic-gate vgatext_set_text(struct vgatext_softc *softc) 1293*0Sstevel@tonic-gate { 1294*0Sstevel@tonic-gate int i; 1295*0Sstevel@tonic-gate 1296*0Sstevel@tonic-gate if (happyface_boot == 0) 1297*0Sstevel@tonic-gate return; 1298*0Sstevel@tonic-gate 1299*0Sstevel@tonic-gate /* we are in graphics mode, set to text 80X25 mode */ 1300*0Sstevel@tonic-gate 1301*0Sstevel@tonic-gate /* set misc registers */ 1302*0Sstevel@tonic-gate vga_set_reg(&softc->regs, VGA_MISC_W, VGA_MISC_TEXT); 1303*0Sstevel@tonic-gate 1304*0Sstevel@tonic-gate /* set sequencer registers */ 1305*0Sstevel@tonic-gate vga_set_seq(&softc->regs, VGA_SEQ_RST_SYN, 1306*0Sstevel@tonic-gate (vga_get_seq(&softc->regs, VGA_SEQ_RST_SYN) & 1307*0Sstevel@tonic-gate ~VGA_SEQ_RST_SYN_NO_SYNC_RESET)); 1308*0Sstevel@tonic-gate for (i = 1; i < NUM_SEQ_REG; i++) { 1309*0Sstevel@tonic-gate vga_set_seq(&softc->regs, i, VGA_SEQ_TEXT[i]); 1310*0Sstevel@tonic-gate } 1311*0Sstevel@tonic-gate vga_set_seq(&softc->regs, VGA_SEQ_RST_SYN, 1312*0Sstevel@tonic-gate (vga_get_seq(&softc->regs, VGA_SEQ_RST_SYN) | 1313*0Sstevel@tonic-gate VGA_SEQ_RST_SYN_NO_ASYNC_RESET | 1314*0Sstevel@tonic-gate VGA_SEQ_RST_SYN_NO_SYNC_RESET)); 1315*0Sstevel@tonic-gate 1316*0Sstevel@tonic-gate /* set crt controller registers */ 1317*0Sstevel@tonic-gate vga_set_crtc(&softc->regs, VGA_CRTC_VRE, 1318*0Sstevel@tonic-gate (vga_get_crtc(&softc->regs, VGA_CRTC_VRE) & 1319*0Sstevel@tonic-gate ~VGA_CRTC_VRE_LOCK)); 1320*0Sstevel@tonic-gate for (i = 0; i < NUM_CRTC_REG; i++) { 1321*0Sstevel@tonic-gate vga_set_crtc(&softc->regs, i, VGA_CRTC_TEXT[i]); 1322*0Sstevel@tonic-gate } 1323*0Sstevel@tonic-gate 1324*0Sstevel@tonic-gate /* set graphics controller registers */ 1325*0Sstevel@tonic-gate for (i = 0; i < NUM_GRC_REG; i++) { 1326*0Sstevel@tonic-gate vga_set_grc(&softc->regs, i, VGA_GRC_TEXT[i]); 1327*0Sstevel@tonic-gate } 1328*0Sstevel@tonic-gate 1329*0Sstevel@tonic-gate /* set attribute registers */ 1330*0Sstevel@tonic-gate for (i = 0; i < NUM_ATR_REG; i++) { 1331*0Sstevel@tonic-gate vga_set_atr(&softc->regs, i, VGA_ATR_TEXT[i]); 1332*0Sstevel@tonic-gate } 1333*0Sstevel@tonic-gate 1334*0Sstevel@tonic-gate /* set palette */ 1335*0Sstevel@tonic-gate for (i = 0; i < VGA_TEXT_CMAP_ENTRIES; i++) { 1336*0Sstevel@tonic-gate vga_put_cmap(&softc->regs, i, VGA_TEXT_PALETTES[i][0] << 2, 1337*0Sstevel@tonic-gate VGA_TEXT_PALETTES[i][1] << 2, 1338*0Sstevel@tonic-gate VGA_TEXT_PALETTES[i][2] << 2); 1339*0Sstevel@tonic-gate } 1340*0Sstevel@tonic-gate for (i = VGA_TEXT_CMAP_ENTRIES; i < VGA8_CMAP_ENTRIES; i++) { 1341*0Sstevel@tonic-gate vga_put_cmap(&softc->regs, i, 0, 0, 0); 1342*0Sstevel@tonic-gate } 1343*0Sstevel@tonic-gate 1344*0Sstevel@tonic-gate vgatext_save_colormap(softc); 1345*0Sstevel@tonic-gate } 1346*0Sstevel@tonic-gate 1347*0Sstevel@tonic-gate static void 1348*0Sstevel@tonic-gate vgatext_init(struct vgatext_softc *softc) 1349*0Sstevel@tonic-gate { 1350*0Sstevel@tonic-gate unsigned char atr_mode; 1351*0Sstevel@tonic-gate 1352*0Sstevel@tonic-gate atr_mode = vga_get_atr(&softc->regs, VGA_ATR_MODE); 1353*0Sstevel@tonic-gate if (atr_mode & VGA_ATR_MODE_GRAPH) 1354*0Sstevel@tonic-gate vgatext_set_text(softc); 1355*0Sstevel@tonic-gate atr_mode = vga_get_atr(&softc->regs, VGA_ATR_MODE); 1356*0Sstevel@tonic-gate atr_mode &= ~VGA_ATR_MODE_BLINK; 1357*0Sstevel@tonic-gate atr_mode &= ~VGA_ATR_MODE_9WIDE; 1358*0Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_MODE, atr_mode); 1359*0Sstevel@tonic-gate #if defined(USE_BORDERS) 1360*0Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR, 1361*0Sstevel@tonic-gate vga_get_atr(&softc->regs, VGA_BRIGHT_WHITE)); 1362*0Sstevel@tonic-gate #else 1363*0Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR, 1364*0Sstevel@tonic-gate vga_get_atr(&softc->regs, VGA_BLACK)); 1365*0Sstevel@tonic-gate #endif 1366*0Sstevel@tonic-gate vgatext_setfont(softc); /* need selectable font? */ 1367*0Sstevel@tonic-gate } 1368*0Sstevel@tonic-gate 1369*0Sstevel@tonic-gate #if defined(USE_BORDERS) 1370*0Sstevel@tonic-gate static void 1371*0Sstevel@tonic-gate vgatext_init_graphics(struct vgatext_softc *softc) 1372*0Sstevel@tonic-gate { 1373*0Sstevel@tonic-gate vga_set_atr(&softc->regs, VGA_ATR_BDR_CLR, 1374*0Sstevel@tonic-gate vga_get_atr(&softc->regs, VGA_BLACK)); 1375*0Sstevel@tonic-gate } 1376*0Sstevel@tonic-gate #endif 1377*0Sstevel@tonic-gate 1378*0Sstevel@tonic-gate static void 1379*0Sstevel@tonic-gate vgatext_setfont(struct vgatext_softc *softc) 1380*0Sstevel@tonic-gate { 1381*0Sstevel@tonic-gate extern unsigned char *ENCODINGS[]; 1382*0Sstevel@tonic-gate unsigned char *from; 1383*0Sstevel@tonic-gate unsigned char *to; 1384*0Sstevel@tonic-gate int i; 1385*0Sstevel@tonic-gate int j; 1386*0Sstevel@tonic-gate int bpc; 1387*0Sstevel@tonic-gate 1388*0Sstevel@tonic-gate /* Sync-reset the sequencer registers */ 1389*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x01); 1390*0Sstevel@tonic-gate /* 1391*0Sstevel@tonic-gate * enable write to plane2, since fonts 1392*0Sstevel@tonic-gate * could only be loaded into plane2 1393*0Sstevel@tonic-gate */ 1394*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x02, 0x04); 1395*0Sstevel@tonic-gate /* 1396*0Sstevel@tonic-gate * sequentially access data in the bit map being 1397*0Sstevel@tonic-gate * selected by MapMask register (index 0x02) 1398*0Sstevel@tonic-gate */ 1399*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x04, 0x07); 1400*0Sstevel@tonic-gate /* Sync-reset ended, and allow the sequencer to operate */ 1401*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x03); 1402*0Sstevel@tonic-gate 1403*0Sstevel@tonic-gate /* 1404*0Sstevel@tonic-gate * select plane 2 on Read Mode 0 1405*0Sstevel@tonic-gate */ 1406*0Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x04, 0x02); 1407*0Sstevel@tonic-gate /* 1408*0Sstevel@tonic-gate * system addresses sequentially access data, follow 1409*0Sstevel@tonic-gate * Memory Mode register bit 2 in the sequencer 1410*0Sstevel@tonic-gate */ 1411*0Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x05, 0x00); 1412*0Sstevel@tonic-gate /* 1413*0Sstevel@tonic-gate * set range of host memory addresses decoded by VGA 1414*0Sstevel@tonic-gate * hardware -- A0000h-BFFFFh (128K region) 1415*0Sstevel@tonic-gate */ 1416*0Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x06, 0x00); 1417*0Sstevel@tonic-gate 1418*0Sstevel@tonic-gate /* 1419*0Sstevel@tonic-gate * This assumes 8x16 characters, which yield the traditional 80x25 1420*0Sstevel@tonic-gate * screen. It really should support other character heights. 1421*0Sstevel@tonic-gate * 1422*0Sstevel@tonic-gate * plane2 may contain 8 font sets, we shouldn't touch font set 0, 1423*0Sstevel@tonic-gate * which is default font and kept in slot 0. we will load our own 1424*0Sstevel@tonic-gate * font in slot 2, which is 4*8K offset to slot 0; 1425*0Sstevel@tonic-gate */ 1426*0Sstevel@tonic-gate bpc = 16; 1427*0Sstevel@tonic-gate for (i = 0; i < 256; i++) { 1428*0Sstevel@tonic-gate from = ENCODINGS[i]; 1429*0Sstevel@tonic-gate to = (unsigned char *)softc->fb.addr + 32768 + i * 0x20; 1430*0Sstevel@tonic-gate for (j = 0; j < bpc; j++) 1431*0Sstevel@tonic-gate *to++ = *from++; 1432*0Sstevel@tonic-gate } 1433*0Sstevel@tonic-gate 1434*0Sstevel@tonic-gate /* Sync-reset the sequencer registers */ 1435*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x01); 1436*0Sstevel@tonic-gate /* enable write to plane 0 and 1 */ 1437*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x02, 0x03); 1438*0Sstevel@tonic-gate /* 1439*0Sstevel@tonic-gate * enable character map selection 1440*0Sstevel@tonic-gate * and odd/even addressing 1441*0Sstevel@tonic-gate */ 1442*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x04, 0x03); 1443*0Sstevel@tonic-gate /* 1444*0Sstevel@tonic-gate * select font map that resides in slot 2 1445*0Sstevel@tonic-gate * 010b -- font residing at 8000h - 9FFFh 1446*0Sstevel@tonic-gate */ 1447*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x03, 0x0a); 1448*0Sstevel@tonic-gate /* Sync-reset ended, and allow the sequencer to operate */ 1449*0Sstevel@tonic-gate vga_set_seq(&softc->regs, 0x00, 0x03); 1450*0Sstevel@tonic-gate 1451*0Sstevel@tonic-gate /* restore graphic registers */ 1452*0Sstevel@tonic-gate 1453*0Sstevel@tonic-gate /* select plane 0 */ 1454*0Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x04, 0x00); 1455*0Sstevel@tonic-gate /* enable odd/even addressing mode */ 1456*0Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x05, 0x10); 1457*0Sstevel@tonic-gate /* 1458*0Sstevel@tonic-gate * range of host memory addresses decoded by VGA 1459*0Sstevel@tonic-gate * hardware -- B8000h-BFFFFh (32K region) 1460*0Sstevel@tonic-gate */ 1461*0Sstevel@tonic-gate vga_set_grc(&softc->regs, 0x06, 0x0e); 1462*0Sstevel@tonic-gate /* enable all color plane */ 1463*0Sstevel@tonic-gate vga_set_atr(&softc->regs, 0x12, 0x0f); 1464*0Sstevel@tonic-gate 1465*0Sstevel@tonic-gate } 1466*0Sstevel@tonic-gate 1467*0Sstevel@tonic-gate static void 1468*0Sstevel@tonic-gate vgatext_save_colormap(struct vgatext_softc *softc) 1469*0Sstevel@tonic-gate { 1470*0Sstevel@tonic-gate int i; 1471*0Sstevel@tonic-gate 1472*0Sstevel@tonic-gate for (i = 0; i < VGA_ATR_NUM_PLT; i++) { 1473*0Sstevel@tonic-gate softc->attrib_palette[i] = vga_get_atr(&softc->regs, i); 1474*0Sstevel@tonic-gate } 1475*0Sstevel@tonic-gate for (i = 0; i < VGA8_CMAP_ENTRIES; i++) { 1476*0Sstevel@tonic-gate vga_get_cmap(&softc->regs, i, 1477*0Sstevel@tonic-gate &softc->colormap[i].red, 1478*0Sstevel@tonic-gate &softc->colormap[i].green, 1479*0Sstevel@tonic-gate &softc->colormap[i].blue); 1480*0Sstevel@tonic-gate } 1481*0Sstevel@tonic-gate } 1482*0Sstevel@tonic-gate 1483*0Sstevel@tonic-gate static void 1484*0Sstevel@tonic-gate vgatext_restore_colormap(struct vgatext_softc *softc) 1485*0Sstevel@tonic-gate { 1486*0Sstevel@tonic-gate int i; 1487*0Sstevel@tonic-gate 1488*0Sstevel@tonic-gate for (i = 0; i < VGA_ATR_NUM_PLT; i++) { 1489*0Sstevel@tonic-gate vga_set_atr(&softc->regs, i, softc->attrib_palette[i]); 1490*0Sstevel@tonic-gate } 1491*0Sstevel@tonic-gate for (i = 0; i < VGA8_CMAP_ENTRIES; i++) { 1492*0Sstevel@tonic-gate vga_put_cmap(&softc->regs, i, 1493*0Sstevel@tonic-gate softc->colormap[i].red, 1494*0Sstevel@tonic-gate softc->colormap[i].green, 1495*0Sstevel@tonic-gate softc->colormap[i].blue); 1496*0Sstevel@tonic-gate } 1497*0Sstevel@tonic-gate } 1498*0Sstevel@tonic-gate 1499*0Sstevel@tonic-gate /* 1500*0Sstevel@tonic-gate * search the entries of the "reg" property for one which has the desired 1501*0Sstevel@tonic-gate * combination of phys_hi bits and contains the desired address. 1502*0Sstevel@tonic-gate * 1503*0Sstevel@tonic-gate * This version searches a PCI-style "reg" property. It was prompted by 1504*0Sstevel@tonic-gate * issues surrounding the presence or absence of an entry for the ROM: 1505*0Sstevel@tonic-gate * (a) a transition problem with PowerPC Virtual Open Firmware 1506*0Sstevel@tonic-gate * (b) uncertainty as to whether an entry will be included on a device 1507*0Sstevel@tonic-gate * with ROM support (and so an "active" ROM base address register), 1508*0Sstevel@tonic-gate * but no ROM actually installed. 1509*0Sstevel@tonic-gate * 1510*0Sstevel@tonic-gate * See the note below on vgatext_get_isa_reg_index for the reasons for 1511*0Sstevel@tonic-gate * returning the offset. 1512*0Sstevel@tonic-gate * 1513*0Sstevel@tonic-gate * Note that this routine may not be fully general; it is intended for the 1514*0Sstevel@tonic-gate * specific purpose of finding a couple of particular VGA reg entries and 1515*0Sstevel@tonic-gate * may not be suitable for all reg-searching purposes. 1516*0Sstevel@tonic-gate */ 1517*0Sstevel@tonic-gate static int 1518*0Sstevel@tonic-gate vgatext_get_pci_reg_index( 1519*0Sstevel@tonic-gate dev_info_t *const devi, 1520*0Sstevel@tonic-gate unsigned long himask, 1521*0Sstevel@tonic-gate unsigned long hival, 1522*0Sstevel@tonic-gate unsigned long addr, 1523*0Sstevel@tonic-gate off_t *offset) 1524*0Sstevel@tonic-gate { 1525*0Sstevel@tonic-gate 1526*0Sstevel@tonic-gate int length, index; 1527*0Sstevel@tonic-gate pci_regspec_t *reg; 1528*0Sstevel@tonic-gate 1529*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 1530*0Sstevel@tonic-gate "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) { 1531*0Sstevel@tonic-gate return (-1); 1532*0Sstevel@tonic-gate } 1533*0Sstevel@tonic-gate 1534*0Sstevel@tonic-gate for (index = 0; index < length / sizeof (pci_regspec_t); index++) { 1535*0Sstevel@tonic-gate if ((reg[index].pci_phys_hi & himask) != hival) 1536*0Sstevel@tonic-gate continue; 1537*0Sstevel@tonic-gate if (reg[index].pci_size_hi != 0) 1538*0Sstevel@tonic-gate continue; 1539*0Sstevel@tonic-gate if (reg[index].pci_phys_mid != 0) 1540*0Sstevel@tonic-gate continue; 1541*0Sstevel@tonic-gate if (reg[index].pci_phys_low > addr) 1542*0Sstevel@tonic-gate continue; 1543*0Sstevel@tonic-gate if (reg[index].pci_phys_low + reg[index].pci_size_low <= addr) 1544*0Sstevel@tonic-gate continue; 1545*0Sstevel@tonic-gate 1546*0Sstevel@tonic-gate *offset = addr - reg[index].pci_phys_low; 1547*0Sstevel@tonic-gate kmem_free(reg, (size_t)length); 1548*0Sstevel@tonic-gate return (index); 1549*0Sstevel@tonic-gate } 1550*0Sstevel@tonic-gate kmem_free(reg, (size_t)length); 1551*0Sstevel@tonic-gate 1552*0Sstevel@tonic-gate return (-1); 1553*0Sstevel@tonic-gate } 1554*0Sstevel@tonic-gate 1555*0Sstevel@tonic-gate /* 1556*0Sstevel@tonic-gate * search the entries of the "reg" property for one which has the desired 1557*0Sstevel@tonic-gate * combination of phys_hi bits and contains the desired address. 1558*0Sstevel@tonic-gate * 1559*0Sstevel@tonic-gate * This version searches a ISA-style "reg" property. It was prompted by 1560*0Sstevel@tonic-gate * issues surrounding 8514/A support. By IEEE 1275 compatibility conventions, 1561*0Sstevel@tonic-gate * 8514/A registers should have been added after all standard VGA registers. 1562*0Sstevel@tonic-gate * Unfortunately, the Solaris/Intel device configuration framework 1563*0Sstevel@tonic-gate * (a) lists the 8514/A registers before the video memory, and then 1564*0Sstevel@tonic-gate * (b) also sorts the entries so that I/O entries come before memory 1565*0Sstevel@tonic-gate * entries. 1566*0Sstevel@tonic-gate * 1567*0Sstevel@tonic-gate * It returns the "reg" index and offset into that register set. 1568*0Sstevel@tonic-gate * The offset is needed because there exist (broken?) BIOSes that 1569*0Sstevel@tonic-gate * report larger ranges enclosing the standard ranges. One reports 1570*0Sstevel@tonic-gate * 0x3bf for 0x21 instead of 0x3c0 for 0x20, for instance. Using the 1571*0Sstevel@tonic-gate * offset adjusts for this difference in the base of the register set. 1572*0Sstevel@tonic-gate * 1573*0Sstevel@tonic-gate * Note that this routine may not be fully general; it is intended for the 1574*0Sstevel@tonic-gate * specific purpose of finding a couple of particular VGA reg entries and 1575*0Sstevel@tonic-gate * may not be suitable for all reg-searching purposes. 1576*0Sstevel@tonic-gate */ 1577*0Sstevel@tonic-gate static int 1578*0Sstevel@tonic-gate vgatext_get_isa_reg_index( 1579*0Sstevel@tonic-gate dev_info_t *const devi, 1580*0Sstevel@tonic-gate unsigned long hival, 1581*0Sstevel@tonic-gate unsigned long addr, 1582*0Sstevel@tonic-gate off_t *offset) 1583*0Sstevel@tonic-gate { 1584*0Sstevel@tonic-gate 1585*0Sstevel@tonic-gate int length, index; 1586*0Sstevel@tonic-gate struct regspec *reg; 1587*0Sstevel@tonic-gate 1588*0Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 1589*0Sstevel@tonic-gate "reg", (caddr_t)®, &length) != DDI_PROP_SUCCESS) { 1590*0Sstevel@tonic-gate return (-1); 1591*0Sstevel@tonic-gate } 1592*0Sstevel@tonic-gate 1593*0Sstevel@tonic-gate for (index = 0; index < length / sizeof (struct regspec); index++) { 1594*0Sstevel@tonic-gate if (reg[index].regspec_bustype != hival) 1595*0Sstevel@tonic-gate continue; 1596*0Sstevel@tonic-gate if (reg[index].regspec_addr > addr) 1597*0Sstevel@tonic-gate continue; 1598*0Sstevel@tonic-gate if (reg[index].regspec_addr + reg[index].regspec_size <= addr) 1599*0Sstevel@tonic-gate continue; 1600*0Sstevel@tonic-gate 1601*0Sstevel@tonic-gate *offset = addr - reg[index].regspec_addr; 1602*0Sstevel@tonic-gate kmem_free(reg, (size_t)length); 1603*0Sstevel@tonic-gate return (index); 1604*0Sstevel@tonic-gate } 1605*0Sstevel@tonic-gate kmem_free(reg, (size_t)length); 1606*0Sstevel@tonic-gate 1607*0Sstevel@tonic-gate return (-1); 1608*0Sstevel@tonic-gate } 1609*0Sstevel@tonic-gate 1610*0Sstevel@tonic-gate /* 1611*0Sstevel@tonic-gate * If AGP cap pointer is successfully found, none-zero value is returned. 1612*0Sstevel@tonic-gate * Otherwise 0 is returned. 1613*0Sstevel@tonic-gate */ 1614*0Sstevel@tonic-gate static off_t 1615*0Sstevel@tonic-gate agp_master_cap_find(ddi_acc_handle_t acc_handle) 1616*0Sstevel@tonic-gate { 1617*0Sstevel@tonic-gate off_t nextcap; 1618*0Sstevel@tonic-gate uint32_t ncapid; 1619*0Sstevel@tonic-gate uint8_t value; 1620*0Sstevel@tonic-gate 1621*0Sstevel@tonic-gate /* check if this device supports capibility pointer */ 1622*0Sstevel@tonic-gate value = (uint8_t)(pci_config_get16(acc_handle, PCI_CONF_STAT) 1623*0Sstevel@tonic-gate & PCI_CONF_CAP_MASK); 1624*0Sstevel@tonic-gate 1625*0Sstevel@tonic-gate if (!value) 1626*0Sstevel@tonic-gate return (0); 1627*0Sstevel@tonic-gate /* get the offset of the first capability pointer from CAPPTR */ 1628*0Sstevel@tonic-gate nextcap = (off_t)(pci_config_get8(acc_handle, AGP_CONF_CAPPTR)); 1629*0Sstevel@tonic-gate 1630*0Sstevel@tonic-gate /* check AGP capability from the first capability pointer */ 1631*0Sstevel@tonic-gate while (nextcap) { 1632*0Sstevel@tonic-gate ncapid = pci_config_get32(acc_handle, nextcap); 1633*0Sstevel@tonic-gate if ((ncapid & PCI_CONF_CAPID_MASK) 1634*0Sstevel@tonic-gate == AGP_CAP_ID) /* find AGP cap */ 1635*0Sstevel@tonic-gate break; 1636*0Sstevel@tonic-gate 1637*0Sstevel@tonic-gate nextcap = (off_t)((ncapid & PCI_CONF_NCAPID_MASK) >> 8); 1638*0Sstevel@tonic-gate } 1639*0Sstevel@tonic-gate 1640*0Sstevel@tonic-gate return (nextcap); 1641*0Sstevel@tonic-gate 1642*0Sstevel@tonic-gate } 1643*0Sstevel@tonic-gate 1644*0Sstevel@tonic-gate /* 1645*0Sstevel@tonic-gate * If i8xx device is successfully detected, 0 is returned. 1646*0Sstevel@tonic-gate * Otherwise -1 is returned. 1647*0Sstevel@tonic-gate */ 1648*0Sstevel@tonic-gate static int 1649*0Sstevel@tonic-gate detect_i8xx_device(agp_master_softc_t *master_softc) 1650*0Sstevel@tonic-gate { 1651*0Sstevel@tonic-gate 1652*0Sstevel@tonic-gate switch (master_softc->agpm_id) { 1653*0Sstevel@tonic-gate case INTEL_IGD_810: 1654*0Sstevel@tonic-gate case INTEL_IGD_810DC: 1655*0Sstevel@tonic-gate case INTEL_IGD_810E: 1656*0Sstevel@tonic-gate case INTEL_IGD_815: 1657*0Sstevel@tonic-gate master_softc->agpm_dev_type = DEVICE_IS_I810; 1658*0Sstevel@tonic-gate break; 1659*0Sstevel@tonic-gate case INTEL_IGD_830M: 1660*0Sstevel@tonic-gate case INTEL_IGD_845G: 1661*0Sstevel@tonic-gate case INTEL_IGD_855GM: 1662*0Sstevel@tonic-gate case INTEL_IGD_865G: 1663*0Sstevel@tonic-gate master_softc->agpm_dev_type = DEVICE_IS_I830; 1664*0Sstevel@tonic-gate break; 1665*0Sstevel@tonic-gate default: /* unknown id */ 1666*0Sstevel@tonic-gate return (-1); 1667*0Sstevel@tonic-gate } 1668*0Sstevel@tonic-gate 1669*0Sstevel@tonic-gate return (0); 1670*0Sstevel@tonic-gate } 1671*0Sstevel@tonic-gate 1672*0Sstevel@tonic-gate /* 1673*0Sstevel@tonic-gate * If agp master is succssfully detected, 0 is returned. 1674*0Sstevel@tonic-gate * Otherwise -1 is returned. 1675*0Sstevel@tonic-gate */ 1676*0Sstevel@tonic-gate static int 1677*0Sstevel@tonic-gate detect_agp_devcice(agp_master_softc_t *master_softc) 1678*0Sstevel@tonic-gate { 1679*0Sstevel@tonic-gate off_t cap; 1680*0Sstevel@tonic-gate 1681*0Sstevel@tonic-gate cap = agp_master_cap_find(master_softc->agpm_acc_hdl); 1682*0Sstevel@tonic-gate if (cap) { 1683*0Sstevel@tonic-gate master_softc->agpm_dev_type = DEVICE_IS_AGP; 1684*0Sstevel@tonic-gate master_softc->agpm_data.agpm_acaptr = cap; 1685*0Sstevel@tonic-gate return (0); 1686*0Sstevel@tonic-gate } else { 1687*0Sstevel@tonic-gate return (-1); 1688*0Sstevel@tonic-gate } 1689*0Sstevel@tonic-gate 1690*0Sstevel@tonic-gate } 1691*0Sstevel@tonic-gate 1692*0Sstevel@tonic-gate /* 1693*0Sstevel@tonic-gate * If agp master is successfully initialized, 0 is returned. 1694*0Sstevel@tonic-gate * Otherwise -1 is returned. 1695*0Sstevel@tonic-gate */ 1696*0Sstevel@tonic-gate static int 1697*0Sstevel@tonic-gate agp_master_init(struct vgatext_softc *softc) 1698*0Sstevel@tonic-gate { 1699*0Sstevel@tonic-gate dev_info_t *devi; 1700*0Sstevel@tonic-gate int instance; 1701*0Sstevel@tonic-gate int status; 1702*0Sstevel@tonic-gate agp_master_softc_t *agp_master; 1703*0Sstevel@tonic-gate uint32_t value; 1704*0Sstevel@tonic-gate off_t reg_size; 1705*0Sstevel@tonic-gate 1706*0Sstevel@tonic-gate 1707*0Sstevel@tonic-gate ASSERT(softc); 1708*0Sstevel@tonic-gate agp_master = softc->agp_master; 1709*0Sstevel@tonic-gate 1710*0Sstevel@tonic-gate devi = softc->devi; 1711*0Sstevel@tonic-gate 1712*0Sstevel@tonic-gate instance = ddi_get_instance(devi); 1713*0Sstevel@tonic-gate 1714*0Sstevel@tonic-gate status = pci_config_setup(devi, &agp_master->agpm_acc_hdl); 1715*0Sstevel@tonic-gate 1716*0Sstevel@tonic-gate if (status != DDI_SUCCESS) { 1717*0Sstevel@tonic-gate cmn_err(CE_WARN, "agp_master_init: pci_config_setup failed"); 1718*0Sstevel@tonic-gate return (-1); 1719*0Sstevel@tonic-gate } 1720*0Sstevel@tonic-gate 1721*0Sstevel@tonic-gate agp_master->agpm_id = 1722*0Sstevel@tonic-gate pci_config_get32(agp_master->agpm_acc_hdl, PCI_CONF_VENID); 1723*0Sstevel@tonic-gate 1724*0Sstevel@tonic-gate if (!detect_i8xx_device(agp_master)) { 1725*0Sstevel@tonic-gate /* map mmio register set */ 1726*0Sstevel@tonic-gate status = ddi_regs_map_setup(devi, I8XX_MMIO_REGSET, 1727*0Sstevel@tonic-gate &agp_master->agpm_data.agpm_gtt.gtt_mmio_base, 1728*0Sstevel@tonic-gate 0, 0, &i8xx_dev_access, 1729*0Sstevel@tonic-gate &agp_master->agpm_data.agpm_gtt.gtt_mmio_handle); 1730*0Sstevel@tonic-gate 1731*0Sstevel@tonic-gate if (status != DDI_SUCCESS) { 1732*0Sstevel@tonic-gate cmn_err(CE_WARN, 1733*0Sstevel@tonic-gate "agp_master_init: ddi_regs_map_setup failed"); 1734*0Sstevel@tonic-gate agp_master_end(agp_master); 1735*0Sstevel@tonic-gate return (-1); 1736*0Sstevel@tonic-gate } 1737*0Sstevel@tonic-gate /* get GTT range base offset */ 1738*0Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_addr = 1739*0Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_mmio_base + 1740*0Sstevel@tonic-gate I8XX_PTE_OFFSET; 1741*0Sstevel@tonic-gate /* get graphics memory size */ 1742*0Sstevel@tonic-gate status = ddi_dev_regsize(devi, I8XX_FB_REGSET, 1743*0Sstevel@tonic-gate ®_size); 1744*0Sstevel@tonic-gate /* 1745*0Sstevel@tonic-gate * if memory size is smaller than a certain value, it means 1746*0Sstevel@tonic-gate * the register set number for graphics memory range might 1747*0Sstevel@tonic-gate * be wrong 1748*0Sstevel@tonic-gate */ 1749*0Sstevel@tonic-gate if (status != DDI_SUCCESS || reg_size < 0x400000) { 1750*0Sstevel@tonic-gate cmn_err(CE_WARN, 1751*0Sstevel@tonic-gate "agp_master_init: ddi_dev_regsize error"); 1752*0Sstevel@tonic-gate agp_master_end(agp_master); 1753*0Sstevel@tonic-gate return (-1); 1754*0Sstevel@tonic-gate } 1755*0Sstevel@tonic-gate 1756*0Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_info.igd_apersize = 1757*0Sstevel@tonic-gate BYTES2MB(reg_size); 1758*0Sstevel@tonic-gate value = pci_config_get32(agp_master->agpm_acc_hdl, 1759*0Sstevel@tonic-gate I8XX_CONF_GMADR); 1760*0Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_info.igd_aperbase = 1761*0Sstevel@tonic-gate value & GTT_BASE_MASK; 1762*0Sstevel@tonic-gate agp_master->agpm_data.agpm_gtt.gtt_info.igd_devid = 1763*0Sstevel@tonic-gate agp_master->agpm_id; 1764*0Sstevel@tonic-gate } else if (detect_agp_devcice(agp_master)) { 1765*0Sstevel@tonic-gate /* 1766*0Sstevel@tonic-gate * non IGD or AGP devices, not error 1767*0Sstevel@tonic-gate */ 1768*0Sstevel@tonic-gate agp_master_end(agp_master); 1769*0Sstevel@tonic-gate return (-1); 1770*0Sstevel@tonic-gate } 1771*0Sstevel@tonic-gate 1772*0Sstevel@tonic-gate /* create extra minor node for IGD or AGP device */ 1773*0Sstevel@tonic-gate status = ddi_create_minor_node(softc->devi, AGPMASTER_NAME, 1774*0Sstevel@tonic-gate S_IFCHR, INST2NODE2(instance), DDI_NT_AGP_MASTER, 0); 1775*0Sstevel@tonic-gate 1776*0Sstevel@tonic-gate if (status != DDI_SUCCESS) { 1777*0Sstevel@tonic-gate cmn_err(CE_WARN, 1778*0Sstevel@tonic-gate "agp_master_init: create agpmaster node failed"); 1779*0Sstevel@tonic-gate agp_master_end(agp_master); 1780*0Sstevel@tonic-gate return (-1); 1781*0Sstevel@tonic-gate } 1782*0Sstevel@tonic-gate 1783*0Sstevel@tonic-gate return (0); 1784*0Sstevel@tonic-gate } 1785*0Sstevel@tonic-gate 1786*0Sstevel@tonic-gate /* 1787*0Sstevel@tonic-gate * Minor node is not removed here, since vgatext_detach is responsible 1788*0Sstevel@tonic-gate * for removing all nodes. 1789*0Sstevel@tonic-gate */ 1790*0Sstevel@tonic-gate static void 1791*0Sstevel@tonic-gate agp_master_end(agp_master_softc_t *master_softc) 1792*0Sstevel@tonic-gate { 1793*0Sstevel@tonic-gate ASSERT(master_softc); 1794*0Sstevel@tonic-gate 1795*0Sstevel@tonic-gate /* intel integrated device */ 1796*0Sstevel@tonic-gate if ((master_softc->agpm_dev_type == DEVICE_IS_I810) || 1797*0Sstevel@tonic-gate (master_softc->agpm_dev_type == DEVICE_IS_I830)) { 1798*0Sstevel@tonic-gate if (master_softc->agpm_data.agpm_gtt.gtt_mmio_handle != NULL) { 1799*0Sstevel@tonic-gate ddi_regs_map_free( 1800*0Sstevel@tonic-gate &master_softc->agpm_data.agpm_gtt.gtt_mmio_handle); 1801*0Sstevel@tonic-gate } 1802*0Sstevel@tonic-gate } 1803*0Sstevel@tonic-gate if (master_softc->agpm_acc_hdl != NULL) { 1804*0Sstevel@tonic-gate pci_config_teardown(&master_softc->agpm_acc_hdl); 1805*0Sstevel@tonic-gate } 1806*0Sstevel@tonic-gate 1807*0Sstevel@tonic-gate bzero(master_softc, sizeof (agp_master_softc_t)); 1808*0Sstevel@tonic-gate return; 1809*0Sstevel@tonic-gate 1810*0Sstevel@tonic-gate } 1811*0Sstevel@tonic-gate 1812*0Sstevel@tonic-gate /* 1813*0Sstevel@tonic-gate * Please refer to GART and GTT entry format table in agpdefs.h for 1814*0Sstevel@tonic-gate * intel GTT entry format. 1815*0Sstevel@tonic-gate */ 1816*0Sstevel@tonic-gate static int 1817*0Sstevel@tonic-gate phys2entry(uint32_t type, uint32_t physaddr, uint32_t *entry) 1818*0Sstevel@tonic-gate { 1819*0Sstevel@tonic-gate uint32_t value; 1820*0Sstevel@tonic-gate 1821*0Sstevel@tonic-gate switch (type) { 1822*0Sstevel@tonic-gate case AGP_PHYSICAL: 1823*0Sstevel@tonic-gate case AGP_NORMAL: 1824*0Sstevel@tonic-gate value = (physaddr & GTT_PTE_MASK) | GTT_PTE_VALID; 1825*0Sstevel@tonic-gate break; 1826*0Sstevel@tonic-gate default: 1827*0Sstevel@tonic-gate return (-1); 1828*0Sstevel@tonic-gate } 1829*0Sstevel@tonic-gate 1830*0Sstevel@tonic-gate *entry = value; 1831*0Sstevel@tonic-gate 1832*0Sstevel@tonic-gate return (0); 1833*0Sstevel@tonic-gate } 1834*0Sstevel@tonic-gate 1835*0Sstevel@tonic-gate static int 1836*0Sstevel@tonic-gate i8xx_add_to_gtt(gtt_impl_t *gtt, igd_gtt_seg_t seg) 1837*0Sstevel@tonic-gate { 1838*0Sstevel@tonic-gate int i; 1839*0Sstevel@tonic-gate uint32_t *paddr; 1840*0Sstevel@tonic-gate uint32_t entry; 1841*0Sstevel@tonic-gate uint32_t maxpages; 1842*0Sstevel@tonic-gate 1843*0Sstevel@tonic-gate maxpages = gtt->gtt_info.igd_apersize; 1844*0Sstevel@tonic-gate maxpages = GTT_MB_TO_PAGES(maxpages); 1845*0Sstevel@tonic-gate 1846*0Sstevel@tonic-gate paddr = seg.igs_phyaddr; 1847*0Sstevel@tonic-gate 1848*0Sstevel@tonic-gate /* 1849*0Sstevel@tonic-gate * check if gtt max pages reached 1850*0Sstevel@tonic-gate */ 1851*0Sstevel@tonic-gate if ((seg.igs_pgstart + seg.igs_npage) > maxpages) 1852*0Sstevel@tonic-gate return (-1); 1853*0Sstevel@tonic-gate 1854*0Sstevel@tonic-gate paddr = seg.igs_phyaddr; 1855*0Sstevel@tonic-gate for (i = seg.igs_pgstart; i < (seg.igs_pgstart + seg.igs_npage); 1856*0Sstevel@tonic-gate i++, paddr++) { 1857*0Sstevel@tonic-gate if (phys2entry(seg.igs_type, *paddr, &entry)) 1858*0Sstevel@tonic-gate return (-1); 1859*0Sstevel@tonic-gate ddi_put32(gtt->gtt_mmio_handle, 1860*0Sstevel@tonic-gate (uint32_t *)(gtt->gtt_addr + i * sizeof (uint32_t)), 1861*0Sstevel@tonic-gate entry); 1862*0Sstevel@tonic-gate } 1863*0Sstevel@tonic-gate 1864*0Sstevel@tonic-gate return (0); 1865*0Sstevel@tonic-gate } 1866*0Sstevel@tonic-gate 1867*0Sstevel@tonic-gate static void 1868*0Sstevel@tonic-gate i8xx_remove_from_gtt(gtt_impl_t *gtt, igd_gtt_seg_t seg) 1869*0Sstevel@tonic-gate { 1870*0Sstevel@tonic-gate int i; 1871*0Sstevel@tonic-gate uint32_t maxpages; 1872*0Sstevel@tonic-gate 1873*0Sstevel@tonic-gate maxpages = gtt->gtt_info.igd_apersize; 1874*0Sstevel@tonic-gate maxpages = GTT_MB_TO_PAGES(maxpages); 1875*0Sstevel@tonic-gate 1876*0Sstevel@tonic-gate /* 1877*0Sstevel@tonic-gate * check if gtt max pages reached 1878*0Sstevel@tonic-gate */ 1879*0Sstevel@tonic-gate if ((seg.igs_pgstart + seg.igs_npage) > maxpages) 1880*0Sstevel@tonic-gate return; 1881*0Sstevel@tonic-gate 1882*0Sstevel@tonic-gate for (i = seg.igs_pgstart; i < (seg.igs_pgstart + seg.igs_npage); i++) { 1883*0Sstevel@tonic-gate ddi_put32(gtt->gtt_mmio_handle, 1884*0Sstevel@tonic-gate (uint32_t *)(gtt->gtt_addr + 1885*0Sstevel@tonic-gate i * sizeof (uint32_t)), 1886*0Sstevel@tonic-gate 0); 1887*0Sstevel@tonic-gate } 1888*0Sstevel@tonic-gate } 1889