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