fdc.c (702c623a8a808303614b191707676909b9e40fbb) | fdc.c (922006325bc565925fdcc293af63e34527194384) |
---|---|
1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Don Ahn. 7 * 8 * Portions Copyright (c) 1993, 1994 by --- 26 unchanged lines hidden (view full) --- 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 | 1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Don Ahn. 7 * 8 * Portions Copyright (c) 1993, 1994 by --- 26 unchanged lines hidden (view full) --- 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 * from: @(#)fd.c 7.4 (Berkeley) 5/25/91 |
43 * $Id: fd.c,v 1.32 1994/09/25 06:04:21 phk Exp $ | 43 * $Id: fd.c,v 1.33 1994/10/10 01:12:25 phk Exp $ |
44 * 45 */ 46 47#include "ft.h" 48#if NFT < 1 49#undef NFDC 50#endif 51#include "fd.h" --- 9 unchanged lines hidden (view full) --- 61#include <sys/ioctl.h> 62#include <machine/ioctl_fd.h> 63#include <sys/disklabel.h> 64#include <sys/buf.h> 65#include <sys/uio.h> 66#include <sys/malloc.h> 67#include <sys/proc.h> 68#include <sys/syslog.h> | 44 * 45 */ 46 47#include "ft.h" 48#if NFT < 1 49#undef NFDC 50#endif 51#include "fd.h" --- 9 unchanged lines hidden (view full) --- 61#include <sys/ioctl.h> 62#include <machine/ioctl_fd.h> 63#include <sys/disklabel.h> 64#include <sys/buf.h> 65#include <sys/uio.h> 66#include <sys/malloc.h> 67#include <sys/proc.h> 68#include <sys/syslog.h> |
69#include <sys/devconf.h> 70#include <sys/dkstat.h> |
|
69#include <i386/isa/isa.h> 70#include <i386/isa/isa_device.h> 71#include <i386/isa/fdreg.h> 72#include <i386/isa/fdc.h> 73#include <i386/isa/rtc.h> 74#if NFT > 0 75#include <sys/ftape.h> 76#include <i386/isa/ftreg.h> 77#endif 78 | 71#include <i386/isa/isa.h> 72#include <i386/isa/isa_device.h> 73#include <i386/isa/fdreg.h> 74#include <i386/isa/fdc.h> 75#include <i386/isa/rtc.h> 76#if NFT > 0 77#include <sys/ftape.h> 78#include <i386/isa/ftreg.h> 79#endif 80 |
81static int fd_goaway(struct kern_devconf *, int); 82static int fdc_goaway(struct kern_devconf *, int); 83static int fd_externalize(struct proc *, struct kern_devconf *, void *, size_t); 84static int fdc_externalize(struct proc *, struct kern_devconf *, void *, size_t); 85 86/* 87 * Templates for the kern_devconf structures used when we attach. 88 */ 89static struct kern_devconf kdc_fd_template = { 90 0, 0, 0, /* filled in by kern_devconf.c */ 91 "fd", 0, { "fdc0", MDDT_DISK, 0 }, 92 fd_externalize, 0, fd_goaway, DISK_EXTERNALLEN 93}; 94 95static struct kern_devconf kdc_fdc_template = { 96 0, 0, 0, /* filled in by kern_devconf.c */ 97 "fdc", 0, { "isa0", MDDT_ISA, 0 }, 98 fdc_externalize, 0, fdc_goaway, ISA_EXTERNALLEN 99}; 100 101static inline void 102fd_registerdev(int ctlr, int unit) 103{ 104 struct kern_devconf *kdc; 105 106 MALLOC(kdc, struct kern_devconf *, sizeof *kdc, M_TEMP, M_NOWAIT); 107 if(!kdc) return; 108 *kdc = kdc_fd_template; 109 kdc->kdc_unit = unit; 110 sprintf(kdc->kdc_md.mddc_parent, "fdc%d", ctlr); 111 dev_attach(kdc); 112} 113 114static int 115fdc_goaway(struct kern_devconf *kdc, int force) 116{ 117 if(force) { 118 dev_detach(kdc); 119 FREE(kdc, M_TEMP); 120 return 0; 121 } else { 122 return EBUSY; /* XXX fix */ 123 } 124} 125 126static int 127fd_goaway(struct kern_devconf *kdc, int force) 128{ 129 dev_detach(kdc); 130 FREE(kdc, M_TEMP); 131 return 0; 132} 133 |
|
79#define RAW_PART 2 80#define b_cylin b_resid 81 82/* misuse a flag to identify format operation */ 83#define B_FORMAT B_XXX 84 85/* 86 * this biotab field doubles as a field for the physical unit number --- 62 unchanged lines hidden (view full) --- 149#define FD_OPEN 0x01 /* it's open */ 150#define FD_ACTIVE 0x02 /* it's active */ 151#define FD_MOTOR 0x04 /* motor should be on */ 152#define FD_MOTOR_WAIT 0x08 /* motor coming up */ 153 int skip; 154 int hddrv; 155 int track; /* where we think the head is */ 156 int options; /* user configurable options, see ioctl_fd.h */ | 134#define RAW_PART 2 135#define b_cylin b_resid 136 137/* misuse a flag to identify format operation */ 138#define B_FORMAT B_XXX 139 140/* 141 * this biotab field doubles as a field for the physical unit number --- 62 unchanged lines hidden (view full) --- 204#define FD_OPEN 0x01 /* it's open */ 205#define FD_ACTIVE 0x02 /* it's active */ 206#define FD_MOTOR 0x04 /* motor should be on */ 207#define FD_MOTOR_WAIT 0x08 /* motor coming up */ 208 int skip; 209 int hddrv; 210 int track; /* where we think the head is */ 211 int options; /* user configurable options, see ioctl_fd.h */ |
212 int dkunit; /* disk stats unit number */ |
|
157} fd_data[NFD]; 158 159/***********************************************************************\ 160* Throughout this file the following conventions will be used: * 161* fd is a pointer to the fd_data struct for the drive in question * 162* fdc is a pointer to the fdc_data struct for the controller * 163* fdu is the floppy drive unit number * 164* fdcu is the floppy controller unit number * --- 77 unchanged lines hidden (view full) --- 242int fd_debug = 0; 243#define TRACE0(arg) if(fd_debug) printf(arg) 244#define TRACE1(arg1, arg2) if(fd_debug) printf(arg1, arg2) 245#else /* DEBUG */ 246#define TRACE0(arg) 247#define TRACE1(arg1, arg2) 248#endif /* DEBUG */ 249 | 213} fd_data[NFD]; 214 215/***********************************************************************\ 216* Throughout this file the following conventions will be used: * 217* fd is a pointer to the fd_data struct for the drive in question * 218* fdc is a pointer to the fdc_data struct for the controller * 219* fdu is the floppy drive unit number * 220* fdcu is the floppy controller unit number * --- 77 unchanged lines hidden (view full) --- 298int fd_debug = 0; 299#define TRACE0(arg) if(fd_debug) printf(arg) 300#define TRACE1(arg1, arg2) if(fd_debug) printf(arg1, arg2) 301#else /* DEBUG */ 302#define TRACE0(arg) 303#define TRACE1(arg1, arg2) 304#endif /* DEBUG */ 305 |
306struct isa_device *fdcdevs[NFDC]; 307 308/* 309 * Provide hw.devconf information. 310 */ 311static int 312fd_externalize(struct proc *p, struct kern_devconf *kdc, void *userp, size_t len) 313{ 314 return disk_externalize(fd_data[kdc->kdc_unit].fdsu, userp, &len); 315} 316 317static int 318fdc_externalize(struct proc *p, struct kern_devconf *kdc, void *userp, size_t len) 319{ 320 return isa_externalize(fdcdevs[kdc->kdc_unit], userp, &len); 321} 322 |
|
250/****************************************************************************/ 251/* autoconfiguration stuff */ 252/****************************************************************************/ 253struct isa_driver fdcdriver = { 254 fdprobe, fdattach, "fdc", 255}; 256 257/* --- 5 unchanged lines hidden (view full) --- 263{ 264 fdcu_t fdcu = dev->id_unit; 265 if(fdc_data[fdcu].flags & FDC_ATTACHED) 266 { 267 printf("fdc: same unit (%d) used multiple times\n", fdcu); 268 return 0; 269 } 270 | 323/****************************************************************************/ 324/* autoconfiguration stuff */ 325/****************************************************************************/ 326struct isa_driver fdcdriver = { 327 fdprobe, fdattach, "fdc", 328}; 329 330/* --- 5 unchanged lines hidden (view full) --- 336{ 337 fdcu_t fdcu = dev->id_unit; 338 if(fdc_data[fdcu].flags & FDC_ATTACHED) 339 { 340 printf("fdc: same unit (%d) used multiple times\n", fdcu); 341 return 0; 342 } 343 |
344 fdcdevs[fdcu] = dev; |
|
271 fdc_data[fdcu].baseport = dev->id_iobase; 272 273 /* First - lets reset the floppy controller */ 274 outb(dev->id_iobase+FDOUT, 0); 275 DELAY(100); 276 outb(dev->id_iobase+FDOUT, FDO_FRST); 277 278 /* see if it can handle a command */ --- 15 unchanged lines hidden (view full) --- 294{ 295 unsigned fdt; 296 fdu_t fdu; 297 fdcu_t fdcu = dev->id_unit; 298 fdc_p fdc = fdc_data + fdcu; 299 fd_p fd; 300 int fdsu, st0, i; 301 struct isa_device *fdup; | 345 fdc_data[fdcu].baseport = dev->id_iobase; 346 347 /* First - lets reset the floppy controller */ 348 outb(dev->id_iobase+FDOUT, 0); 349 DELAY(100); 350 outb(dev->id_iobase+FDOUT, FDO_FRST); 351 352 /* see if it can handle a command */ --- 15 unchanged lines hidden (view full) --- 368{ 369 unsigned fdt; 370 fdu_t fdu; 371 fdcu_t fdcu = dev->id_unit; 372 fdc_p fdc = fdc_data + fdcu; 373 fd_p fd; 374 int fdsu, st0, i; 375 struct isa_device *fdup; |
376 struct kern_devconf *kdc; |
|
302 | 377 |
378 MALLOC(kdc, struct kern_devconf *, sizeof *kdc, M_TEMP, M_NOWAIT); 379 if(!kdc) 380 return 0; 381 *kdc = kdc_fdc_template; 382 kdc->kdc_unit = fdcu; 383 dev_attach(kdc); 384 |
|
303 fdc->fdcu = fdcu; 304 fdc->flags |= FDC_ATTACHED; 305 fdc->dmachan = dev->id_drq; 306 fdc->state = DEVIDLE; 307 /* reset controller, turn motor off, clear fdout mirror reg */ 308 outb(fdc->baseport + FDOUT, ((fdc->fdout = 0))); 309 printf("fdc%d:", fdcu); 310 --- 98 unchanged lines hidden (view full) --- 409 printf("720KB 3.5in]"); 410 fd->type = FD_720; 411 break; 412 default: 413 printf("unknown]"); 414 fd->type = NO_TYPE; 415 break; 416 } | 385 fdc->fdcu = fdcu; 386 fdc->flags |= FDC_ATTACHED; 387 fdc->dmachan = dev->id_drq; 388 fdc->state = DEVIDLE; 389 /* reset controller, turn motor off, clear fdout mirror reg */ 390 outb(fdc->baseport + FDOUT, ((fdc->fdout = 0))); 391 printf("fdc%d:", fdcu); 392 --- 98 unchanged lines hidden (view full) --- 491 printf("720KB 3.5in]"); 492 fd->type = FD_720; 493 break; 494 default: 495 printf("unknown]"); 496 fd->type = NO_TYPE; 497 break; 498 } |
499 fd_registerdev(fdcu, fdu); 500 if(dk_ndrive < DK_NDRIVE) { 501 sprintf(dk_names[dk_ndrive], "fd%d", fdu); 502 dk_wpms[dk_ndrive] = (500 * 1024 / 2) / 1000; 503 fd->dkunit = dk_ndrive++; 504 } else { 505 fd->dkunit = -1; 506 } |
|
417 } 418 printf("\n"); 419 420 return (1); 421} 422 423int 424fdsize(dev) --- 1044 unchanged lines hidden --- | 507 } 508 printf("\n"); 509 510 return (1); 511} 512 513int 514fdsize(dev) --- 1044 unchanged lines hidden --- |