pc98_machdep.c revision 158359
1148771Scperciva/*- 2148771Scperciva * Copyright (c) KATO Takenori, 1996, 1997. 3148771Scperciva * 4148771Scperciva * All rights reserved. Unpublished rights reserved under the copyright 5148771Scperciva * laws of Japan. 6148771Scperciva * 7148771Scperciva * 8148771Scperciva * Redistribution and use in source and binary forms, with or without 9148771Scperciva * modification, are permitted provided that the following conditions 10148771Scperciva * are met: 11148771Scperciva * 1. Redistributions of source code must retain the above copyright 12148771Scperciva * notice, this list of conditions and the following disclaimer as 13148771Scperciva * the first lines of this file unmodified. 14148771Scperciva * 2. Redistributions in binary form must reproduce the above copyright 15148771Scperciva * notice, this list of conditions and the following disclaimer in the 16148771Scperciva * documentation and/or other materials provided with the distribution. 17148771Scperciva * 3. The name of the author may not be used to endorse or promote products 18148771Scperciva * derived from this software without specific prior written permission. 19148771Scperciva * 20148771Scperciva * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21148771Scperciva * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22148771Scperciva * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23148771Scperciva * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24148771Scperciva * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25148771Scperciva * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26148771Scperciva * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27148771Scperciva * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28148771Scperciva * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29148771Scperciva * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30152573Sru * 31148771Scperciva * $FreeBSD: head/sys/pc98/pc98/pc98_machdep.c 158359 2006-05-08 12:05:04Z nyan $ 32148771Scperciva */ 33152573Sru 34148771Scperciva#include "opt_pc98.h" 35148771Scperciva 36152573Sru#include <sys/param.h> 37148771Scperciva#include <sys/systm.h> 38152573Sru 39148771Scperciva#include <cam/cam.h> 40152573Sru#include <cam/cam_ccb.h> 41148771Scperciva#include <pc98/pc98/pc98_machdep.h> 42152573Sru 43148771Scperciva/* 44152573Sru * Initialize DMA controller 45148771Scperciva */ 46152573Sruvoid 47152573Srupc98_init_dmac(void) 48152573Sru{ 49148771Scperciva outb(0x439, (inb(0x439) & 0xfb)); /* DMA Accsess Control over 1MB */ 50152573Sru outb(0x29, (0x0c | 0)); /* Bank Mode Reg. 16M mode */ 51148771Scperciva outb(0x29, (0x0c | 1)); /* Bank Mode Reg. 16M mode */ 52152573Sru outb(0x29, (0x0c | 2)); /* Bank Mode Reg. 16M mode */ 53148771Scperciva outb(0x29, (0x0c | 3)); /* Bank Mode Reg. 16M mode */ 54148771Scperciva outb(0x11, 0x50); 55148771Scperciva} 56148771Scperciva 57148771Scperciva#ifdef EPSON_MEMWIN 58152573Sru/* 59148771Scperciva * Disconnect phisical memory in 15-16MB region. 60152573Sru * 61152573Sru * EPSON PC-486GR, P, SR, SE, HX, HG and HA only. Other system support 62152573Sru * this feature with software DIP switch. 63148771Scperciva */ 64152573Srustatic void 65152573Sruinit_epson_memwin(void) 66148771Scperciva{ 67148771Scperciva /* Disable 15MB-16MB caching. */ 68208027Suqs switch (epson_machine_id) { 69208027Suqs case EPSON_PC486_HX: 70198671Scperciva case EPSON_PC486_HG: 71198671Scperciva case EPSON_PC486_HA: 72198671Scperciva /* Cache control start. */ 73198671Scperciva outb(0x43f, 0x42); 74198671Scperciva outw(0xc40, 0x0033); 75233648Seadler 76198671Scperciva /* Disable 0xF00000-0xFFFFFF. */ 77198671Scperciva outb(0xc48, 0x49); 78198671Scperciva outb(0xc4c, 0x00); 79198671Scperciva outb(0xc48, 0x48); 80198671Scperciva outb(0xc4c, 0xf0); 81198671Scperciva outb(0xc48, 0x4d); 82198671Scperciva outb(0xc4c, 0x00); 83198671Scperciva outb(0xc48, 0x4c); 84198671Scperciva outb(0xc4c, 0xff); 85198671Scperciva outb(0xc48, 0x4f); 86198671Scperciva outb(0xc4c, 0x00); 87198671Scperciva 88198671Scperciva /* Cache control end. */ 89 outb(0x43f, 0x40); 90 break; 91 92 case EPSON_PC486_GR: 93 case EPSON_PC486_P: 94 case EPSON_PC486_GR_SUPER: 95 case EPSON_PC486_GR_PLUS: 96 case EPSON_PC486_SE: 97 case EPSON_PC486_SR: 98 /* Disable 0xF00000-0xFFFFFF. */ 99 outb(0x43f, 0x42); 100 outb(0x467, 0xe0); 101 outb(0x567, 0xd8); 102 103 outb(0x43f, 0x40); 104 outb(0x467, 0xe0); 105 outb(0x567, 0xe0); 106 break; 107 } 108 109 /* Disable 15MB-16MB RAM and enable memory window. */ 110 outb(0x43b, inb(0x43b) & 0xfd); /* Clear bit1. */ 111} 112#endif 113 114/* 115 * Get physical memory size 116 */ 117unsigned int 118pc98_getmemsize(unsigned int *base, unsigned int *ext) 119{ 120 unsigned int under16, over16; 121 122 /* available conventional memory size */ 123 *base = ((PC98_SYSTEM_PARAMETER(0x501) & 7) + 1) * 128; 124 125 /* available protected memory size under 16MB */ 126 under16 = PC98_SYSTEM_PARAMETER(0x401) * 128 + 1024; 127#ifdef EPSON_MEMWIN 128 if (pc98_machine_type & M_EPSON_PC98) { 129 if (under16 > (15 * 1024)) 130 /* chop under16 memory to 15MB */ 131 under16 = 15 * 1024; 132 init_epson_memwin(); 133 } 134#endif 135 136 /* available protected memory size over 16MB / 1MB */ 137 over16 = PC98_SYSTEM_PARAMETER(0x594); 138 over16 += PC98_SYSTEM_PARAMETER(0x595) * 256; 139 140 if (over16 > 0) 141 *ext = (16 + over16) * 1024 - 1024; 142 else 143 *ext = under16 - 1024; 144 145 return (under16); 146} 147 148/* 149 * Read a geometry information of SCSI HDD from BIOS work area. 150 * 151 * XXX - Before reading BIOS work area, we should check whether 152 * host adapter support it. 153 */ 154int 155scsi_da_bios_params(struct ccb_calc_geometry *ccg) 156{ 157 u_char *tmp; 158 int target; 159 160 target = ccg->ccb_h.target_id; 161 tmp = (u_char *)&PC98_SYSTEM_PARAMETER(0x460 + target*4); 162 if ((PC98_SYSTEM_PARAMETER(0x482) & ((1 << target)&0xff)) != 0) { 163 ccg->secs_per_track = *tmp; 164 ccg->cylinders = ((*(tmp+3)<<8)|*(tmp+2))&0xfff; 165#if 0 166 switch (*(tmp + 3) & 0x30) { 167 case 0x00: 168 disk_parms->secsiz = 256; 169 printf("Warning!: not supported.\n"); 170 break; 171 case 0x10: 172 disk_parms->secsiz = 512; 173 break; 174 case 0x20: 175 disk_parms->secsiz = 1024; 176 break; 177 default: 178 disk_parms->secsiz = 512; 179 printf("Warning!: not supported. But force to 512\n"); 180 break; 181 } 182#endif 183 if (*(tmp+3) & 0x40) { 184 ccg->cylinders += (*(tmp+1)&0xf0)<<8; 185 ccg->heads = *(tmp+1)&0x0f; 186 } else { 187 ccg->heads = *(tmp+1); 188 } 189 return (1); 190 } 191 192 return (0); 193} 194