biosdisk.c (292682) | biosdisk.c (298230) |
---|---|
1/*- 2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/boot/pc98/libpc98/biosdisk.c 292682 2015-12-24 06:22:41Z jhb $"); | 28__FBSDID("$FreeBSD: head/sys/boot/pc98/libpc98/biosdisk.c 298230 2016-04-18 23:09:22Z allanjude $"); |
29 30/* 31 * BIOS disk device handling. 32 * 33 * Ideas and algorithms from: 34 * 35 * - NetBSD libi386/biosdisk.c 36 * - FreeBSD biosboot/disk.c --- 54 unchanged lines hidden (view full) --- 91 * BIOS unit number. 92 */ 93static struct bdinfo 94{ 95 int bd_unit; /* BIOS unit number */ 96 int bd_flags; 97 int bd_type; /* BIOS 'drive type' (floppy only) */ 98 int bd_da_unit; /* kernel unit number for da */ | 29 30/* 31 * BIOS disk device handling. 32 * 33 * Ideas and algorithms from: 34 * 35 * - NetBSD libi386/biosdisk.c 36 * - FreeBSD biosboot/disk.c --- 54 unchanged lines hidden (view full) --- 91 * BIOS unit number. 92 */ 93static struct bdinfo 94{ 95 int bd_unit; /* BIOS unit number */ 96 int bd_flags; 97 int bd_type; /* BIOS 'drive type' (floppy only) */ 98 int bd_da_unit; /* kernel unit number for da */ |
99 int bd_open; /* reference counter */ 100 void *bd_bcache; /* buffer cache data */ |
|
99} bdinfo [MAXBDDEV]; 100static int nbdinfo = 0; 101 | 101} bdinfo [MAXBDDEV]; 102static int nbdinfo = 0; 103 |
104#define BD(dev) (bdinfo[(dev)->d_unit]) 105 |
|
102static int bd_getgeom(struct open_disk *od); 103static int bd_read(struct open_disk *od, daddr_t dblk, int blks, 104 caddr_t dest); 105static int bd_write(struct open_disk *od, daddr_t dblk, int blks, 106 caddr_t dest); 107 108static int bd_int13probe(struct bdinfo *bd); 109 --- 61 unchanged lines hidden (view full) --- 171bd_init(void) 172{ 173 int base, unit; 174 int da_drive=0, n=-0x10; 175 176 /* sequence 0x90, 0x80, 0xa0 */ 177 for (base = 0x90; base <= 0xa0; base += n, n += 0x30) { 178 for (unit = base; (nbdinfo < MAXBDDEV) || ((unit & 0x0f) < 4); unit++) { | 106static int bd_getgeom(struct open_disk *od); 107static int bd_read(struct open_disk *od, daddr_t dblk, int blks, 108 caddr_t dest); 109static int bd_write(struct open_disk *od, daddr_t dblk, int blks, 110 caddr_t dest); 111 112static int bd_int13probe(struct bdinfo *bd); 113 --- 61 unchanged lines hidden (view full) --- 175bd_init(void) 176{ 177 int base, unit; 178 int da_drive=0, n=-0x10; 179 180 /* sequence 0x90, 0x80, 0xa0 */ 181 for (base = 0x90; base <= 0xa0; base += n, n += 0x30) { 182 for (unit = base; (nbdinfo < MAXBDDEV) || ((unit & 0x0f) < 4); unit++) { |
183 bdinfo[nbdinfo].bd_open = 0; 184 bdinfo[nbdinfo].bd_bcache = NULL; |
|
179 bdinfo[nbdinfo].bd_unit = unit; 180 bdinfo[nbdinfo].bd_flags = (unit & 0xf0) == 0x90 ? BD_FLOPPY : 0; 181 182 if (!bd_int13probe(&bdinfo[nbdinfo])){ 183 if (((unit & 0xf0) == 0x90 && (unit & 0x0f) < 4) || 184 ((unit & 0xf0) == 0xa0 && (unit & 0x0f) < 6)) 185 continue; /* Target IDs are not contiguous. */ 186 else --- 13 unchanged lines hidden (view full) --- 200 bdinfo[nbdinfo].bd_da_unit = da_drive++; 201 } 202 /* XXX we need "disk aliases" to make this simpler */ 203 printf("BIOS drive %c: is disk%d\n", 204 'A' + nbdinfo, nbdinfo); 205 nbdinfo++; 206 } 207 } | 185 bdinfo[nbdinfo].bd_unit = unit; 186 bdinfo[nbdinfo].bd_flags = (unit & 0xf0) == 0x90 ? BD_FLOPPY : 0; 187 188 if (!bd_int13probe(&bdinfo[nbdinfo])){ 189 if (((unit & 0xf0) == 0x90 && (unit & 0x0f) < 4) || 190 ((unit & 0xf0) == 0xa0 && (unit & 0x0f) < 6)) 191 continue; /* Target IDs are not contiguous. */ 192 else --- 13 unchanged lines hidden (view full) --- 206 bdinfo[nbdinfo].bd_da_unit = da_drive++; 207 } 208 /* XXX we need "disk aliases" to make this simpler */ 209 printf("BIOS drive %c: is disk%d\n", 210 'A' + nbdinfo, nbdinfo); 211 nbdinfo++; 212 } 213 } |
214 bcache_add_dev(nbdinfo); |
|
208 return(0); 209} 210 211/* 212 * Try to detect a device supported by the legacy int13 BIOS 213 */ 214static int 215bd_int13probe(struct bdinfo *bd) --- 206 unchanged lines hidden (view full) --- 422 int error; 423 424 va_start(ap, f); 425 dev = va_arg(ap, struct i386_devdesc *); 426 va_end(ap); 427 if ((error = bd_opendisk(&od, dev))) 428 return(error); 429 | 215 return(0); 216} 217 218/* 219 * Try to detect a device supported by the legacy int13 BIOS 220 */ 221static int 222bd_int13probe(struct bdinfo *bd) --- 206 unchanged lines hidden (view full) --- 429 int error; 430 431 va_start(ap, f); 432 dev = va_arg(ap, struct i386_devdesc *); 433 va_end(ap); 434 if ((error = bd_opendisk(&od, dev))) 435 return(error); 436 |
437 BD(dev).bd_open++; 438 if (BD(dev).bd_bcache == NULL) 439 BD(dev).bd_bcache = bcache_allocate(); 440 |
|
430 /* 431 * Save our context 432 */ 433 ((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data = od; 434 DEBUG("open_disk %p, partition at 0x%x", od, od->od_boff); 435 return(0); 436} 437 --- 253 unchanged lines hidden (view full) --- 691 } 692 } 693 return (prefslice); 694} 695 696static int 697bd_close(struct open_file *f) 698{ | 441 /* 442 * Save our context 443 */ 444 ((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data = od; 445 DEBUG("open_disk %p, partition at 0x%x", od, od->od_boff); 446 return(0); 447} 448 --- 253 unchanged lines hidden (view full) --- 702 } 703 } 704 return (prefslice); 705} 706 707static int 708bd_close(struct open_file *f) 709{ |
699 struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data); | 710 struct i386_devdesc *dev = f->f_devdata; 711 struct open_disk *od = (struct open_disk *)(dev->d_kind.biosdisk.data); |
700 | 712 |
713 BD(dev).bd_open--; 714 if (BD(dev).bd_open == 0) { 715 bcache_free(BD(dev).bd_bcache); 716 BD(dev).bd_bcache = NULL; 717 } 718 |
|
701 bd_closedisk(od); 702 return(0); 703} 704 705static void 706bd_closedisk(struct open_disk *od) 707{ 708 DEBUG("open_disk %p", od); 709#if 0 710 /* XXX is this required? (especially if disk already open...) */ 711 if (od->od_flags & BD_FLOPPY) 712 delay(3000000); 713#endif 714 free(od); 715} 716 717static int | 719 bd_closedisk(od); 720 return(0); 721} 722 723static void 724bd_closedisk(struct open_disk *od) 725{ 726 DEBUG("open_disk %p", od); 727#if 0 728 /* XXX is this required? (especially if disk already open...) */ 729 if (od->od_flags & BD_FLOPPY) 730 delay(3000000); 731#endif 732 free(od); 733} 734 735static int |
718bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) | 736bd_strategy(void *devdata, int rw, daddr_t dblk, size_t offset, size_t size, 737 char *buf, size_t *rsize) |
719{ 720 struct bcache_devdata bcd; | 738{ 739 struct bcache_devdata bcd; |
721 struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data); | 740 struct i386_devdesc *dev = f->f_devdata; 741 struct open_disk *od = (struct open_disk *)(dev->d_kind.biosdisk.data); |
722 723 bcd.dv_strategy = bd_realstrategy; 724 bcd.dv_devdata = devdata; | 742 743 bcd.dv_strategy = bd_realstrategy; 744 bcd.dv_devdata = devdata; |
725 return(bcache_strategy(&bcd, od->od_unit, rw, dblk+od->od_boff, size, buf, rsize)); | 745 bcd.dv_cache = BD(dev).bd_bcache; 746 return(bcache_strategy(&bcd, od->od_unit, rw, dblk+od->od_boff, offset, 747 size, buf, rsize)); |
726} 727 728static int | 748} 749 750static int |
729bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) | 751bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t offset, 752 size_t size, char *buf, size_t *rsize) |
730{ 731 struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data); 732 int blks; 733#ifdef BD_SUPPORT_FRAGS 734 char fragbuf[BIOSDISK_SECSIZE]; 735 size_t fragsize; 736 737 fragsize = size % BIOSDISK_SECSIZE; --- 348 unchanged lines hidden --- | 753{ 754 struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data); 755 int blks; 756#ifdef BD_SUPPORT_FRAGS 757 char fragbuf[BIOSDISK_SECSIZE]; 758 size_t fragsize; 759 760 fragsize = size % BIOSDISK_SECSIZE; --- 348 unchanged lines hidden --- |