📄 matcd.c
字号:
/*matcd.c-------------------------------------------------------------------- Matsushita(Panasonic) / Creative CD-ROM Driver (matcd) Authored by Frank Durda IV Copyright 1994, 1995 Frank Durda IV. All rights reserved. "FDIV" is a trademark of Frank Durda IV. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice positioned at the very beginning of this file without modification, all copyright strings, all related programming codes that display the copyright strings, this list of conditions and the following disclaimer. 2. Redistributions in binary form must contain all copyright strings and related programming code that display the copyright strings. 3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 4. All advertising materials mentioning features or use of this software must display the following acknowledgement: "The Matsushita/Panasonic CD-ROM driver was developed by Frank Durda IV for use with "FreeBSD" and similar operating systems." "Similar operating systems" includes mainly non-profit oriented systems for research and education, including but not restricted to "NetBSD", "386BSD", and "Mach" (by CMU). The wording of the acknowledgement (in electronic form or printed text) may not be changed without permission from the author. 5. Absolutely no warranty of function, fitness or purpose is made by the author Frank Durda IV. 6. Neither the name of the author nor the name "FreeBSD" may be used to endorse or promote products derived from this software without specific prior written permission. (The author can be reached at bsdmail@nemesis.lonestar.org) 7. The product containing this software must meet all of these conditions even if it is unsupported, not a complete system and/or does not contain compiled code. 8. These conditions will be in force for the full life of the copyright. 9. If all the above conditions are met, modifications to other parts of this file may be freely made, although any person or persons making changes do not receive the right to add their name or names to the copyright strings and notices in this software. Persons making changes are encouraged to insert edit history in matcd.c and to put your name and details of the change there. 10. You must have prior written permission from the author to deviate from these terms. Vendors who produce product(s) containing this code are encouraged (but not required) to provide copies of the finished product(s) to the author and to correspond with the author about development activity relating to this code. Donations of development hardware and/or software are also welcome. (This is one of the faster ways to get a driver developed for a device.) THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-----------------------------------------------------------------------------Dedicated to: My family, my Grandfather, and Max, my Golden RetrieverThanks to: Jordan Hubbard (jkh) for getting me ramped-up to 2.x system quickly enough to make the 2.1 release. He put up with plenty of silly questions and might get the post of ambassador some day.and The people who donated equipment and other material to make development of this driver possible. Donations and sponsors for projects are appreciated.-----No changes are allowed above this line------------------------------------Edit History - (should be in sync with any source control log entries) Never seen one of these before? Ok, here is how it works. Every time you change the code, you increment the edit number, that number over there in the <%d> and in the (%d) in the version string. You never set this number lower than it is. Near, or preferably on lines that change, insert the edit number. If there is a number there already, you can replace it with a newer one. This makes searches for code changes very fast. In the edit history, start with the edit number, and a good description of what changes were made. Then follow it with the date, your name and an EMAIL address where you can be reached. Please follow this practice; it helps leave understandable code in your wake. FYI, you have major and minor release codes. Major releases numbered 1 thru n. Major feature additions should get a new major release number. Minor releases start with a null and then letters A thru Z. So 3A(456) is Major release 3, Minor release 1, Edit 456 (in Microsoft-ese that would be 03.01.456), and 5(731) is Major release 5, Minor release 0, Edit 731. Typically only the author will change the major and minor release codes in small projects. EDIT edit Edit HISTORY history History<1> This initial version is to get basic filesystem I/O working using the SoundBlaster 16 interface. The stand-alone adapter card doesn't work yet. December 1994 Frank Durda IV bsdmail@nemesis.lonestar.org<2> Corrections to resolve a race condition when multiple drives on the same controller was active. Fixed drive 1 & 2 swap problem. See selectdrive(). 21-Jan-95 Frank Durda IV bsdmail@nemesis.lonestar.org<3> Added automatic probing and support for all Creative Labs sound cards with the Creative/Panasonic interface and the stand-alone interface adapters. See AUTOHUNT and FULLCONFIG conditionals for more information. 21-Jan-95 Frank Durda IV bsdmail@nemesis.lonestar.org<4> Rebundled debug conditionals. 14-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.org<5> Changes needed to work on FreeBSD 2.1. Also added draincmd since some conditions cause the drive to produce surprise data. See setmode and draincmd 19-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.org<6> Got rid of some redundant error code by creating chk_error(). Also built a nice generic bus-lock function. 20-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.org<7> Improved comments, general structuring. Fixed a problem with disc eject not working if LOCKDRIVE was set. Apparently the drive will reject an EJECT command if the drive is LOCKED. 21-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.orgEdit number code marking begins here - earlier edits were during development.<8> Final device name selected and actually made to compile under >2.0. For newer systems, it is "matcd", for older it is "mat". 24-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.org<9> Added some additional disk-related ioctl functions that didn't make it into earlier versions. 26-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.org<10> Updated some conditionals so the code will compile under 1.1.5.1, although this is not the supported platform. Also found that some other devices probe code was changing the settings for the port 0x302 debug board, so added code to set it to a sane state before we use it. 26-Feb-95 Frank Durda IV bsdmail@nemesis.lonestar.org<11> The Copyright and Use statement has been replaced in all files with a new version. 1-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org<12> Added ioctls having to do with audio volume, routing and playback speed. Also added some code I think is for dynamic loading. 12-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org<13> Added ioctls to return TOC headers and entries. 19-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org<14> More ioctls to finish out general audio support and some clean-up. Also fixed a bug in open where CD label information would not always be cleared after a disc change. Added a check to block attempts to resume audio if already playing. The resulting sound is a cross between Kryten and Max Headroom. But, if you *want* this "feature", enable #define KRYTEN in options.h. So it is not BSD-ish enough, eh? What, too many comments? :-) 21-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org<15> LOCKDRIVE has been modified so that a new series of minor numbers are created. When these are opened, the selected drive will have its door locked and the device must be completely closed to unlock the media. The EJECT ioctl will be refused when the drive is locked this way. This is useful for servers and other places where the media needs to remain in the drive. Bit 7 of the minor number controls locking. As of this edit, the code compiles with no warnings with -Wall set. 22-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org<16> Added a new check in the probe code that looks for the drive interface being in an idle state after issuing a reset. If this isn't the case, then the device at this location isn't a Matsushita CD-ROM drive. This will prevent hangs in draincmd later. Added the tray close ioctl. This required modifications to open to allow the character devices to be "partially" opened so that the close ioctl could be issued when the open would otherwise fail. Close also delays slightly after completing because the drive doesn't update its disc and media status instantly. Also created the capability ioctl that lets an application find out up front what things a drive can do. Fixed a global spelling error. Changed matcddriver structure to simply say "matcd". The original string "matcd interface " broke the kernel -c boot mechanism. Updated the #includes in response to a complaint in first release. Updated and tested conditionals so that driver will still compile under FreeBSD 1.1.5.1 as well as 2.0 and early 2.1. 4-Apr-95 Frank Durda IV bsdmail@nemesis.lonestar.org<17> The function matcd_toc_entries which is executed in response to the CDIOREADTOCENTRYS ioctl didn't cope with programs that only requested part of the TOC. This change is based on code submitted by Doug Robson (dfr@render.com). (This change was introduced out of order and exists in FreeBSD 2.0.5 without the version stamp being updated. I.N.M.F.) 1-Jun-95 Frank Durda IV bsdmail@nemesis.lonestar.org<18> While working on the TEAC CD-ROM driver (teaccd) that is reusing chunks of code from this driver, I discovered several functions, arrays and other things that should have been declared 'static'. These changes are necessary if the TEAC CD-ROM driver is to be present at the same time as matcd. Also fixed the residual buss vs bus symbols and strings. There are no functional code changes in this edit. 2-May-95 Frank Durda IV bsdmail@nemesis.lonestar.org<19> Creative has changed the Status port slightly in their sound boards based on the Vibra-16 (and probably the Vibra-16S) chipset. This change masks some unused bits that were formally on all the time and are doing different things in this design. The changes are transparent to all other supported boards. 20-Jun-95 Frank Durda IV bsdmail@nemesis.lonestar.org<20> Code was added to detect non-Creative (SoundBlaster) host interfaces, and the driver will switch to code compatible with the detected host interface. This should add support for MediaVision, IBM, Reveal, and other compatible adapters with split data/status-ports. This code allows a mix of SoundBlaster (Type 0) and non-SoundBlaster (Type 1) boards in the same system with no special configuration. I also updated the attach code to display the interface type and changed the host interface probe messages to reflect the "c" for controller in controller-specific messages as the existing messages were confusing when a second card was in place . The kernel -c tables have been updated accordingly, so you now have a matcdc%d controller to change settings on. 24-Jun-95 Frank Durda IV bsdmail@nemesis.lonestar.org<21> Added interface handling code in two of those "this should not happen" routines, draincmd and get_stat. Since these routines are called by functions during probing that may not know what type interface is out there, the code assumes that a given adapter is both a type 0 and a type 1 adapter at the same time. Plus, this code gets executed once in a very long time so the cost of assuming both host adapter types is not significant. 4-Jul-95 Frank Durda IV bsdmail@nemesis.lonestar.org<22> Four external interface prototypes were altered by someone else. I believe these changes are for making GCC and/or the linker shut-up when building some other part of the system since matcd already compiles -Wall with no warnings... 8-Sep-95 Frank Durda IV bsdmail@nemesis.lonestar.org<23> This change implements the ioctls for preventing media removal and allowing media removal. Currently, these calls will work according to the following rules: No "l" devs opened Any "l" dev open CDALLOW accepted always rejected always CDPREVENT accepted always accepted always One refinement might be to allow CDALLOW/CDPREVENT to always work if UID 0 issued the ioctl, but that will wait for later. I also made a change to the information that the toc_entry code returns so that xcdplayer won't malfunction. (It would not play the last track on a non-mixed mode audio CD.) Unlike cdplayer, xcdplayer asks for track information one track at a time, and calls for information on the lead-out track by its official number (0xaa), rather than referring to the "after last" (n+1) track as cdplayer does. Anyway, this change should make both players happy. 16-Sep-95 Frank Durda IV bsdmail@nemesis.lonestar.org<24> In Edit 15 when the extra devs were created for selective locking, the door locking was broken if a non-locking dev on the drive is closed. The problem was caused by not tracking locked devs and non-locking devs as being different partitions. The change is to simply use the locking dev bit to flag a set of shadow partitions when it comes to lock operations. All other operations treat the locked and unlocked partitions as being identical. 18-Sep-95 Frank Durda IV bsdmail@nemesis.lonestar.org<25> During work on Edit 23, I noted that on slow and very busy systems, sometimes the driver would go to sleep forever. The problem appears to have been a race condition caused by doing separate timeout/sleep calls without using SPL first. The change here is to use tsleep which provides the equivalent of timeout/sleep timeout/tsleep if the last paremeter is tsleep is set to the time value that would have been given to timeout. I also fixed some duplicate location strings in the tsleep calls. 24-Sep-95 Frank Durda IV bsdmail@nemesis.lonestar.org<26> Moved a function declaration that generated two warnings with the FULLCONFIG/FULLDRIVER conditionals disabled. Updated the igot function so that it correctly reports limited functions when a sub-set driver is compiled. Eliminated FULLCONFIG conditional and now set controller counts based on the NMATCD #define produced by the config process. Also, disable the audio-related ioctls based on the BOOTMFS conditional to help make the boot floppy kernel smaller. 18-Oct-95 Frank Durda IV bsdmail@nemesis.lonestar.org<27> Incorporated changes needed to move the cdevsw and bdevsw entries into the drivers (including this one). Also include a quick first pass cut at DEVFS suppport.---------------------------------------------------------------------------*//*Match this format: Version_dc(d)__dd-mmm-yy */static char MATCDVERSION[]="Version 1(26) 18-Oct-95";/* The following strings may not be changed*/static char MATCDCOPYRIGHT[] = "Matsushita CD-ROM driver, Copr. 1994,1995 Frank Durda IV";/* The proceeding strings may not be changed*//* $FreeBSD: src/sys/i386/isa/matcd/matcd.c,v 1.20.2.3 1999/09/05 08:14:02 peter Exp $ *//*--------------------------------------------------------------------------- Include declarations---------------------------------------------------------------------------*/#include "matcd.h"#include <sys/param.h>#include <sys/systm.h>#include <sys/buf.h>#include <sys/dkbad.h>#include <sys/cdio.h>#include <sys/disklabel.h>#include <sys/file.h>#include <sys/ioctl.h>#include <sys/proc.h>#include "i386/isa/matcd/options.h" /*Conditional compile options and probe port hints*/#include "i386/isa/matcd/matcddrv.h" /*Drive-related defs & strings*/#include "i386/isa/matcd/creative.h" /*Host interface related defs*/#include <sys/conf.h>#include <sys/kernel.h>#ifdef DEVFS#include <sys/devfsext.h>#endif /*DEVFS*//*--------------------------------------------------------------------------- Defines and structures---------------------------------------------------------------------------*/#define DRIVESPERC 4 /*This is a constant*/#define TOTALDRIVES NUMCTRLRS*DRIVESPERC /*Max possible drives*/#define TICKRES 10 /*Our coarse timer resolution*/#define ISABUSKHZ 8330 /*Number of IN/OUT ISA/sec*/#define MAXTRKS 101 /*Maximum possible tracks*/#define RAW_DEVICE 46 /*<16>Dev number for raw device*/#define MATCDBLK 2048 /*Standard block size*/#define MATCDRBLK 2352 /*Raw and/or DA block size*/#define MATCD_RETRYS 5 /*Number of retries for read ops*/#define MATCD_READ_1 0x80 /*Read state machine defines*/#define MATCD_READ_2 0x90 /*Read state machine defines*/struct matcd_volinfo {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -