pc98_machdep.c revision 39246
1/* 2 * Copyright (c) KATO Takenori, 1996, 1997. 3 * 4 * All rights reserved. Unpublished rights reserved under the copyright 5 * laws of Japan. 6 * 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer as 13 * the first lines of this file unmodified. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include "opt_pc98.h" 33 34#include <sys/param.h> 35#include <sys/systm.h> 36 37#include <cam/cam.h> 38#include <cam/cam_ccb.h> 39 40#include <pc98/pc98/pc98.h> 41#include <pc98/pc98/pc98_machdep.h> 42 43extern int Maxmem; 44extern int Maxmem_under16M; 45 46#ifdef notyet 47static void init_cpu_accel_mem __P((void)); 48#endif 49 50/* 51 * Initialize DMA controller 52 */ 53void 54pc98_init_dmac(void) 55{ 56 outb(0x439, (inb(0x439) & 0xfb)); /* DMA Accsess Control over 1MB */ 57 outb(0x29, (0x0c | 0)); /* Bank Mode Reg. 16M mode */ 58 outb(0x29, (0x0c | 1)); /* Bank Mode Reg. 16M mode */ 59 outb(0x29, (0x0c | 2)); /* Bank Mode Reg. 16M mode */ 60 outb(0x29, (0x0c | 3)); /* Bank Mode Reg. 16M mode */ 61 outb(0x11, 0x50); 62} 63 64#ifdef EPSON_MEMWIN 65static void init_epson_memwin __P((void)); 66 67/* 68 * Disconnect phisical memory in 15-16MB region. 69 * 70 * EPSON PC-486GR, P, SR, SE, HX, HG and HA only. Other system support 71 * this feature with software DIP switch. 72 */ 73static void 74init_epson_memwin(void) 75{ 76 77 if (pc98_machine_type & M_EPSON_PC98) { 78 if (Maxmem > 3840) { 79 if (Maxmem == Maxmem_under16M) { 80 Maxmem = 3840; 81 Maxmem_under16M = 3840; 82 } else if (Maxmem_under16M > 3840) { 83 Maxmem_under16M = 3840; 84 } 85 } 86 87 /* Disable 15MB-16MB caching. */ 88 switch (epson_machine_id) { 89 case 0x34: /* PC486HX */ 90 case 0x35: /* PC486HG */ 91 case 0x3B: /* PC486HA */ 92 /* Cache control start. */ 93 outb(0x43f, 0x42); 94 outw(0xc40, 0x0033); 95 96 /* Disable 0xF00000-0xFFFFFF. */ 97 outb(0xc48, 0x49); 98 outb(0xc4c, 0x00); 99 outb(0xc48, 0x48); 100 outb(0xc4c, 0xf0); 101 outb(0xc48, 0x4d); 102 outb(0xc4c, 0x00); 103 outb(0xc48, 0x4c); 104 outb(0xc4c, 0xff); 105 outb(0xc48, 0x4f); 106 outb(0xc4c, 0x00); 107 108 /* Cache control end. */ 109 outb(0x43f, 0x40); 110 break; 111 112 case 0x2B: /* PC486GR/GF */ 113 case 0x30: /* PC486P */ 114 case 0x31: /* PC486GRSuper */ 115 case 0x32: /* PC486GR+ */ 116 case 0x37: /* PC486SE */ 117 case 0x38: /* PC486SR */ 118 /* Disable 0xF00000-0xFFFFFF. */ 119 outb(0x43f, 0x42); 120 outb(0x467, 0xe0); 121 outb(0x567, 0xd8); 122 123 outb(0x43f, 0x40); 124 outb(0x467, 0xe0); 125 outb(0x567, 0xe0); 126 break; 127 } 128 129 /* Disable 15MB-16MB RAM and enable memory window. */ 130 outb(0x43b, inb(0x43b) & 0xfd); /* Clear bit1. */ 131 } 132} 133#endif 134 135#ifdef notyet 136static void init_cpu_accel_mem(void); 137 138static void 139init_cpu_accel_mem(void) 140{ 141 u_int target_page; 142 /* 143 * Certain 'CPU accelerator' supports over 16MB memory on 144 * the machines whose BIOS doesn't store true size. 145 * To support this, we don't trust BIOS values if Maxmem < 4096. 146 */ 147 if (Maxmem < 4096) { 148 for (target_page = ptoa(4096); /* 16MB */ 149 target_page < ptoa(32768); /* 128MB */ 150 target_page += 256 * PAGE_SIZE /* 1MB step */) { 151 u_int tmp, page_bad = FALSE, OrigMaxmem = Maxmem; 152 153 *(int *)CMAP1 = PG_V | PG_RW | PG_N | target_page; 154 invltlb(); 155 156 tmp = *(u_int *)CADDR1; 157 /* 158 * Test for alternating 1's and 0's 159 */ 160 *(volatile u_int *)CADDR1 = 0xaaaaaaaa; 161 if (*(volatile u_int *)CADDR1 != 0xaaaaaaaa) { 162 page_bad = TRUE; 163 } 164 /* 165 * Test for alternating 0's and 1's 166 */ 167 *(volatile u_int *)CADDR1 = 0x55555555; 168 if (*(volatile u_int *)CADDR1 != 0x55555555) { 169 page_bad = TRUE; 170 } 171 /* 172 * Test for all 1's 173 */ 174 *(volatile u_int *)CADDR1 = 0xffffffff; 175 if (*(volatile u_int *)CADDR1 != 0xffffffff) { 176 page_bad = TRUE; 177 } 178 /* 179 * Test for all 0's 180 */ 181 *(volatile u_int *)CADDR1 = 0x0; 182 if (*(volatile u_int *)CADDR1 != 0x0) { 183 /* 184 * test of page failed 185 */ 186 page_bad = TRUE; 187 } 188 /* 189 * Restore original value. 190 */ 191 *(u_int *)CADDR1 = tmp; 192 if (page_bad == TRUE) { 193 Maxmem = atop(target_page) + 256; 194 } else 195 break; 196 } 197 *(int *)CMAP1 = 0; 198 invltlb(); 199 } 200} 201#endif 202 203/* 204 * Get physical memory size 205 */ 206void 207pc98_getmemsize(void) 208{ 209 unsigned char under16, over16; 210 211 /* available protected memory size under 16MB / 128KB */ 212 under16 = PC98_SYSTEM_PARAMETER(0x401); 213 /* available protected memory size over 16MB / 1MB */ 214 over16 = PC98_SYSTEM_PARAMETER(0x594); 215 /* add conventional memory size (1024KB / 128KB = 8) */ 216 under16 += 8; 217 218 Maxmem = Maxmem_under16M = under16 * 128 * 1024 / PAGE_SIZE; 219 Maxmem += (over16 * 1024 * 1024 / PAGE_SIZE); 220#ifdef EPSON_MEMWIN 221 init_epson_memwin(); 222#endif 223} 224 225#include "da.h" 226 227#if NDA > 0 228/* 229 * Read a geometry information of SCSI HDD from BIOS work area. 230 * 231 * XXX - Before reading BIOS work area, we should check whether 232 * host adapter support it. 233 */ 234int 235scsi_da_bios_params(struct ccb_calc_geometry *ccg) 236{ 237 u_char *tmp; 238 int target; 239 int bus; 240 241 target = ccg->ccb_h.target_id; 242 bus = 0; /* If your really need to know, send a PathInq CCB */ 243 244 tmp = (u_char *)&PC98_SYSTEM_PARAMETER(0x460 + target*4); 245 if ((PC98_SYSTEM_PARAMETER(0x482) & ((1 << target)&0xff)) != 0) { 246 ccg->secs_per_track = *tmp; 247 ccg->cylinders = ((*(tmp+3)<<8)|*(tmp+2))&0xfff; 248#if 0 249 switch (*(tmp + 3) & 0x30) { 250 case 0x00: 251 disk_parms->secsiz = 256; 252 printf("Warning!: not supported.\n"); 253 break; 254 case 0x10: 255 disk_parms->secsiz = 512; 256 break; 257 case 0x20: 258 disk_parms->secsiz = 1024; 259 break; 260 default: 261 disk_parms->secsiz = 512; 262 printf("Warning!: not supported. But force to 512\n"); 263 break; 264 } 265#endif 266 if (*(tmp+3) & 0x40) { 267 ccg->cylinders += (*(tmp+1)&0xf0)<<8; 268 ccg->heads = *(tmp+1)&0x0f; 269 } else { 270 ccg->heads = *(tmp+1); 271 } 272 return 1; 273 } 274 return 0; 275} 276#endif 277