1 /* $NetBSD: isa_io.c,v 1.8 2007/01/21 23:19:57 macallan Exp $ */ 2 3 /* 4 * Copyright 1997 5 * Digital Equipment Corporation. All rights reserved. 6 * 7 * This software is furnished under license and may be used and 8 * copied only in accordance with the following terms and conditions. 9 * Subject to these conditions, you may download, copy, install, 10 * use, modify and distribute this software in source and/or binary 11 * form. No title or ownership is transferred hereby. 12 * 13 * 1) Any source code used, modified or distributed must reproduce 14 * and retain this copyright notice and list of conditions as 15 * they appear in the source file. 16 * 17 * 2) No right is granted to use any trade name, trademark, or logo of 18 * Digital Equipment Corporation. Neither the "Digital Equipment 19 * Corporation" name nor any trademark or logo of Digital Equipment 20 * Corporation may be used to endorse or promote products derived 21 * from this software without the prior written permission of 22 * Digital Equipment Corporation. 23 * 24 * 3) This software is provided "AS-IS" and any express or implied 25 * warranties, including but not limited to, any implied warranties 26 * of merchantability, fitness for a particular purpose, or 27 * non-infringement are disclaimed. In no event shall DIGITAL be 28 * liable for any damages whatsoever, and in particular, DIGITAL 29 * shall not be liable for special, indirect, consequential, or 30 * incidental damages or damages for lost profits, loss of 31 * revenue or loss of use, whether such damages arise in contract, 32 * negligence, tort, under statute, in equity, at law or otherwise, 33 * even if advised of the possibility of such damage. 34 */ 35 36 /* 37 * bus_space I/O functions for isa 38 */ 39 40 #include <sys/cdefs.h> 41 __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.8 2007/01/21 23:19:57 macallan Exp $"); 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <machine/bus.h> 46 #include <machine/pio.h> 47 #include <machine/isa_machdep.h> 48 #include <machine/ofw.h> 49 #include "igsfb_ofbus.h" 50 51 #if NIGSFB_OFBUS > 0 52 extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr; 53 extern paddr_t igsfb_mem_paddr; 54 #endif 55 56 /* Proto types for all the bus_space structure functions */ 57 58 bs_protos(isa); 59 bs_protos(bs_notimpl); 60 61 /* 62 * Declare the isa bus space tags 63 * The IO and MEM structs are identical, except for the cookies, 64 * which contain the address space bases. 65 */ 66 67 /* 68 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF 69 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO! 70 */ 71 struct bus_space isa_io_bs_tag = { 72 /* cookie */ 73 NULL, /* initialized below */ 74 75 /* mapping/unmapping */ 76 isa_bs_map, 77 isa_bs_unmap, 78 isa_bs_subregion, 79 80 /* allocation/deallocation */ 81 isa_bs_alloc, 82 isa_bs_free, 83 84 /* get kernel virtual address */ 85 isa_bs_vaddr, 86 87 /* mmap bus space for userland */ 88 isa_bs_mmap, 89 90 /* barrier */ 91 isa_bs_barrier, 92 93 /* read (single) */ 94 isa_bs_r_1, 95 isa_bs_r_2, 96 isa_bs_r_4, 97 bs_notimpl_bs_r_8, 98 99 /* read multiple */ 100 isa_bs_rm_1, 101 isa_bs_rm_2, 102 isa_bs_rm_4, 103 bs_notimpl_bs_rm_8, 104 105 /* read region */ 106 isa_bs_rr_1, 107 isa_bs_rr_2, 108 isa_bs_rr_4, 109 bs_notimpl_bs_rr_8, 110 111 /* write (single) */ 112 isa_bs_w_1, 113 isa_bs_w_2, 114 isa_bs_w_4, 115 bs_notimpl_bs_w_8, 116 117 /* write multiple */ 118 isa_bs_wm_1, 119 isa_bs_wm_2, 120 isa_bs_wm_4, 121 bs_notimpl_bs_wm_8, 122 123 /* write region */ 124 isa_bs_wr_1, 125 isa_bs_wr_2, 126 isa_bs_wr_4, 127 bs_notimpl_bs_wr_8, 128 129 /* set multiple */ 130 bs_notimpl_bs_sm_1, 131 bs_notimpl_bs_sm_2, 132 bs_notimpl_bs_sm_4, 133 bs_notimpl_bs_sm_8, 134 135 /* set region */ 136 bs_notimpl_bs_sr_1, 137 isa_bs_sr_2, 138 bs_notimpl_bs_sr_4, 139 bs_notimpl_bs_sr_8, 140 141 /* copy */ 142 bs_notimpl_bs_c_1, 143 isa_bs_c_2, 144 bs_notimpl_bs_c_4, 145 bs_notimpl_bs_c_8, 146 147 /* stream methods are identical to regular read/write here */ 148 /* read stream single */ 149 isa_bs_r_1, 150 isa_bs_r_2, 151 isa_bs_r_4, 152 bs_notimpl_bs_r_8, 153 154 /* read stream multiple */ 155 isa_bs_rm_1, 156 isa_bs_rm_2, 157 isa_bs_rm_4, 158 bs_notimpl_bs_rm_8, 159 160 /* read region stream */ 161 isa_bs_rr_1, 162 isa_bs_rr_2, 163 isa_bs_rr_4, 164 bs_notimpl_bs_rr_8, 165 166 /* write stream single */ 167 isa_bs_w_1, 168 isa_bs_w_2, 169 isa_bs_w_4, 170 bs_notimpl_bs_w_8, 171 172 /* write stream multiple */ 173 isa_bs_wm_1, 174 isa_bs_wm_2, 175 isa_bs_wm_4, 176 bs_notimpl_bs_wm_8, 177 178 /* write region stream */ 179 isa_bs_wr_1, 180 isa_bs_wr_2, 181 isa_bs_wr_4, 182 bs_notimpl_bs_wr_8, 183 184 }; 185 186 /* 187 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF 188 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY! 189 */ 190 struct bus_space isa_mem_bs_tag = { 191 /* cookie */ 192 NULL, /* initialized below */ 193 194 /* mapping/unmapping */ 195 isa_bs_map, 196 isa_bs_unmap, 197 isa_bs_subregion, 198 199 /* allocation/deallocation */ 200 isa_bs_alloc, 201 isa_bs_free, 202 203 /* get kernel virtual address */ 204 isa_bs_vaddr, 205 206 /* mmap bus space for userland */ 207 isa_bs_mmap, 208 209 /* barrier */ 210 isa_bs_barrier, 211 212 /* read (single) */ 213 isa_bs_r_1, 214 isa_bs_r_2, 215 isa_bs_r_4, 216 bs_notimpl_bs_r_8, 217 218 /* read multiple */ 219 isa_bs_rm_1, 220 isa_bs_rm_2, 221 isa_bs_rm_4, 222 bs_notimpl_bs_rm_8, 223 224 /* read region */ 225 isa_bs_rr_1, 226 isa_bs_rr_2, 227 isa_bs_rr_4, 228 bs_notimpl_bs_rr_8, 229 230 /* write (single) */ 231 isa_bs_w_1, 232 isa_bs_w_2, 233 isa_bs_w_4, 234 bs_notimpl_bs_w_8, 235 236 /* write multiple */ 237 isa_bs_wm_1, 238 isa_bs_wm_2, 239 isa_bs_wm_4, 240 bs_notimpl_bs_wm_8, 241 242 /* write region */ 243 isa_bs_wr_1, 244 isa_bs_wr_2, 245 isa_bs_wr_4, 246 bs_notimpl_bs_wr_8, 247 248 /* set multiple */ 249 bs_notimpl_bs_sm_1, 250 bs_notimpl_bs_sm_2, 251 bs_notimpl_bs_sm_4, 252 bs_notimpl_bs_sm_8, 253 254 /* set region */ 255 bs_notimpl_bs_sr_1, 256 isa_bs_sr_2, 257 bs_notimpl_bs_sr_4, 258 bs_notimpl_bs_sr_8, 259 260 /* copy */ 261 bs_notimpl_bs_c_1, 262 isa_bs_c_2, 263 bs_notimpl_bs_c_4, 264 bs_notimpl_bs_c_8, 265 266 /* stream methods are identical to regular read/write here */ 267 /* read stream single */ 268 isa_bs_r_1, 269 isa_bs_r_2, 270 isa_bs_r_4, 271 bs_notimpl_bs_r_8, 272 273 /* read stream multiple */ 274 isa_bs_rm_1, 275 isa_bs_rm_2, 276 isa_bs_rm_4, 277 bs_notimpl_bs_rm_8, 278 279 /* read region stream */ 280 isa_bs_rr_1, 281 isa_bs_rr_2, 282 isa_bs_rr_4, 283 bs_notimpl_bs_rr_8, 284 285 /* write stream single */ 286 isa_bs_w_1, 287 isa_bs_w_2, 288 isa_bs_w_4, 289 bs_notimpl_bs_w_8, 290 291 /* write stream multiple */ 292 isa_bs_wm_1, 293 isa_bs_wm_2, 294 isa_bs_wm_4, 295 bs_notimpl_bs_wm_8, 296 297 /* write region stream */ 298 isa_bs_wr_1, 299 isa_bs_wr_2, 300 isa_bs_wr_4, 301 bs_notimpl_bs_wr_8, 302 }; 303 304 /* bus space functions */ 305 306 void 307 isa_io_init(isa_io_addr, isa_mem_addr) 308 vaddr_t isa_io_addr; 309 vaddr_t isa_mem_addr; 310 { 311 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr; 312 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr; 313 } 314 315 /* 316 * break the abstraction: sometimes, other parts of the system 317 * (e.g. X servers) need to map ISA space directly. use these 318 * functions sparingly! 319 */ 320 vaddr_t 321 isa_io_data_vaddr(void) 322 { 323 return (vaddr_t)isa_io_bs_tag.bs_cookie; 324 } 325 326 vaddr_t 327 isa_mem_data_vaddr(void) 328 { 329 return (vaddr_t)isa_mem_bs_tag.bs_cookie; 330 } 331 332 int 333 isa_bs_map(t, bpa, size, cacheable, bshp) 334 void *t; 335 bus_addr_t bpa; 336 bus_size_t size; 337 int cacheable; 338 bus_space_handle_t *bshp; 339 { 340 *bshp = bpa + (bus_addr_t)t; 341 return(0); 342 } 343 344 void 345 isa_bs_unmap(t, bsh, size) 346 void *t; 347 bus_space_handle_t bsh; 348 bus_size_t size; 349 { 350 /* Nothing to do. */ 351 } 352 353 paddr_t 354 isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot, 355 int flags) 356 { 357 paddr_t paddr, ret; 358 359 #ifdef OFISA_DEBUG 360 printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off); 361 #endif 362 #if NIGSFB_OFBUS > 0 363 if ((vaddr_t)cookie == igsfb_mem_vaddr) { 364 paddr = igsfb_mem_paddr; 365 } else 366 #endif 367 paddr = ofw_gettranslation((vaddr_t)cookie); 368 369 if (paddr == -1) { 370 #ifdef OFISA_DEBUG 371 printf(" no translation\n"); 372 #endif 373 return -1; 374 } 375 ret = paddr + addr + off; 376 #ifdef OFISA_DEBUG 377 printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret); 378 #endif 379 return arm_btop(ret); 380 } 381 382 int 383 isa_bs_subregion(t, bsh, offset, size, nbshp) 384 void *t; 385 bus_space_handle_t bsh; 386 bus_size_t offset, size; 387 bus_space_handle_t *nbshp; 388 { 389 /* printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n", 390 t, bsh, offset, size);*/ 391 *nbshp = bsh + offset; 392 return(0); 393 } 394 395 int 396 isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable, 397 bpap, bshp) 398 void *t; 399 bus_addr_t rstart, rend; 400 bus_size_t size, alignment, boundary; 401 int cacheable; 402 bus_addr_t *bpap; 403 bus_space_handle_t *bshp; 404 { 405 panic("isa_alloc(): Help!"); 406 } 407 408 void 409 isa_bs_free(t, bsh, size) 410 void *t; 411 bus_space_handle_t bsh; 412 bus_size_t size; 413 { 414 panic("isa_free(): Help!"); 415 } 416 417 void * 418 isa_bs_vaddr(t, bsh) 419 void *t; 420 bus_space_handle_t bsh; 421 { 422 423 return ((void *)bsh); 424 } 425 426 void 427 isa_bs_barrier(t, bsh, offset, len, flags) 428 void *t; 429 bus_space_handle_t bsh; 430 bus_size_t offset, len; 431 int flags; 432 { 433 /* just return */ 434 } 435