Squashed commit of the following:
commit 8646fb1e83ab28403b022b57681340d1cc0ccf46
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 20:24:25 2013 +0200
3.3.0 sync fixes
Change-Id: Ic91e326623f6dbad58754152c4a632e4406f1117
commit 63108441f284ea07a47dc899f8774ba0e0ccd9c7
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Oct 2 13:37:49 2013 +0200
keymaps: improve keypad slash support
Now that the keymaps can distinguish between the regular slash key
and the slash key on the numeric keypad, we can avoid localization
of the latter.
Change-Id: I20ead7d26a9baa82f5a522562524fd75d44efb42
commit 3c406fb627b8f38efd6796ab4df48b07ca1d1330
Author: Mikal Villa <mikal.villa@gmail.com>
Date: Wed Oct 2 12:30:03 2013 +0200
Norwegian keymap
Change-Id: I181234afc8f1a058e92af6c1fe88979463aaff45
commit 1878c8160e755ada0976f7786f00cbad5abc89d5
Author: Thomas Cort <tcort@minix3.org>
Date: Fri Sep 6 21:40:42 2013 -0400
Importing usr.bin/uname
Change-Id: I4c316221e288edd839e26a2af4cb59f28bf722c1
commit 7e885159803dd37c4c4d9780f8d00fe2f09637f4
Author: Thomas Cort <tcort@minix3.org>
Date: Fri Sep 6 21:40:31 2013 -0400
uname: normalize release and version
Most systems provide the full version number in the
'release' field and the kernel version in 'version'.
Minix used to split the full version number between
release and version which caused problems for pkgsrc
and other applications. This patch brings Minix's
uname in line with other systems such as NetBSD.
It also brings the getty banner in line with NetBSD.
Old Minix uname:
sysname->Minix
nodename->10.0.2.15
release->3
version->2.1
machine->i686
New Minix uname:
sysname->Minix
nodename->10.0.2.15
release->3.2.1
version->Minix 3.2.1 (GENERIC)
machine->i686
Change-Id: I966633dfdcf2f9485966bb0d0d042afc45bbeb7d
commit 2009480d378df66cb06410a8826692d1da7568fa
Author: Lionel Sambuc <lionel@minix3.org>
Date: Thu Sep 19 10:57:10 2013 +0200
Replacing timer_t by netbsd's timer_t
* Renamed struct timer to struct minix_timer
* Renamed timer_t to minix_timer_t
* Ensured all the code uses the minix_timer_t typedef
* Removed ifdef around _BSD_TIMER_T
* Removed include/timers.h and merged it into include/minix/timers.h
* Resolved prototype conflict by renaming kernel's (re)set_timer
to (re)set_kernel_timer.
Change-Id: I56f0f30dfed96e1a0575d92492294cf9a06468a5
commit 4ca61b56bc2ee3a92a3c263ee087a4285cb59e23
Author: Lionel Sambuc <lionel@minix3.org>
Date: Wed Oct 2 10:56:24 2013 +0200
ARM serial driver: Comment termios_baud_rate.
The B0-B115200 defines are flags, and not the actual speed they
represent.
This fixes an incoherency for B0 handling, and documents why it is
required to call the function again after changing the speed flag.
DFL_BAUD is set to one of the flag, so to translate it to an actual
speed, the function calls itself again, which will always be able to
finish without inducing another recursive call.
Change-Id: I04ebfaefee31a88d05f0b726352d1581a966147b
commit faa74cbd048e0a88e88069371c16d3e94cb0d416
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Oct 1 23:25:01 2013 +0200
TTY: skip /dev/log checks if console is serial
It is unclear why /dev/log has its own open/close rules, but those
rules conflict with serial console redirection. This does not solve
the root of the problem, but it puts back in place more or less the
same workaround that was already in place before the TTY overhaul.
Change-Id: Ib53abbc28a76c1f2b0befc8448aeed0173bc96a5
commit ebe655e3eaa75d699c0ddd779d2d933f6a633536
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 19:45:42 2013 +0200
Corrections to keep VFS ABI-compatible
Change-Id: Id8a53a687577c1b6f83c11c2e5fb0b8ed1cd2a08
commit e84ddc012c46e8ff9a0d28845802bf8bacafe69d
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 19:35:11 2013 +0200
Remove support for obsolete 3.2.1 ABI
Change-Id: I76b4960bda41f55d9c42f8c99c5beae3424ca851
commit ec33810903eb97304def78622512eae77a030813
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Aug 31 22:59:44 2013 +0200
Fix various file system warnings
Change-Id: Ied10498c3ae14f9f2fd06914f23239df330fa296
commit 8aa6eb34ef649be235eaea0c5790993dd0d25cc6
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 19:22:13 2013 +0200
VFS/FS: replace protocol version with flag field
The main motivation for this change is that only Loris supports
multithreading, and Loris supports dynamic thread allocation, so the
number of supported threads can be implemented as a bit flag (i.e.,
either 1 or "at least as many as VFS has"). The ABI break obviates the
need to support file system versioning at this time, and several
other aspects are better implemented as flags as well. Other changes:
- replace peek/bpeek test upon mount with FS flag as well;
- mark libsffs as 64-bit file size capable;
- remove old (3.2.1) getdents support.
Change-Id: I313eace9c50ed816656c31cd47d969033d952a03
commit 238277f6362c53f6ebbdf5c5a1a1f9e0d2d064f7
Author: Lionel Sambuc <lionel@minix3.org>
Date: Fri Apr 19 13:16:51 2013 +0200
usr.bin/stat Update
Change-Id: I029160c73baab1b3465bc5397a36c55886db225b
commit 43b5aee7aed02dde0a4492281018dcac5bb03960
Author: Lionel Sambuc <lionel@minix3.org>
Date: Fri Apr 19 09:54:51 2013 +0200
almost aligned ioctl prototype
Change-Id: I7f3eaa99d2a9767f71e8387cea5c7f56dcb28f99
commit db4481b36d7a1fc9af693a9723a4db75b6a05cad
Author: Lionel Sambuc <lionel@minix3.org>
Date: Thu Apr 18 14:42:15 2013 +0200
32 to 64 bits fsblkcnt_t and fsfilcnt_t.
Change-Id: I432229143c85cd178262b802a76ac606801ac59a
commit c12a12d3a34c0404b7ec7894fc9af76b78e9a060
Author: Lionel Sambuc <lionel@minix3.org>
Date: Thu Apr 18 11:08:16 2013 +0200
moving prototypes to lib.h
Change-Id: If53d3f5ee761b10e0f3d4346a0c5b39ba7901c65
commit 9faa3c17db034876f3be63730ae6af30abf788da
Author: Lionel Sambuc <lionel@minix3.org>
Date: Thu Apr 18 11:07:44 2013 +0200
struct uucred
Change-Id: Ia97cb6c38bb566be30d568a252ae7b76142a21dd
commit 30af4bde8a0a19b70045456e2beae76af0bc6e6a
Author: Lionel Sambuc <lionel@minix3.org>
Date: Tue Apr 16 11:48:54 2013 +0200
Alignement on netbsd types, part 1
The following types are modified (old -> new):
* _BSD_USECONDS_T_ int -> unsigned int
* __socklen_t __int32_t -> __uint32_t
* blksize_t uint32_t -> int32_t
* rlim_t uint32_t -> uint64_t
On ARM:
* _BSD_CLOCK_T_ int -> unsigned int
On Intel:
* _BSD_CLOCK_T_ int -> unsigned long
bin/cat is also updated in order to fix warnings.
_BSD_TIMER_T_ has still to be aligned.
Change-Id: I2b4fda024125a19901120546c4e22e443ba5e9d7
commit ab33eaee106a01e573a538aa02beb40dcc34fcb7
Author: Lionel Sambuc <lionel@minix3.org>
Date: Fri Aug 23 20:27:27 2013 +0200
Adapt the type used for adjtime_delta
clock_t is currently a signed type, but in NetBSD this is not the
case. As we plan on aligning our types we have to change this as this
prevents negative delta from being correctly used.
Change-Id: I9bccdee2b41626b0262471dc1900de505a1991a7
commit 8493229abca046bbb3af93196450d80d10839051
Author: Lionel Sambuc <lionel@minix3.org>
Date: Wed Apr 17 13:01:55 2013 +0200
fix sysroot clang
Change-Id: I63adf8460e7fdbe3d9d5ad6c828ae5758cb1643c
commit 23dfcbfb12a6e9f2589e10377a2ae926745f281d
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 19:01:19 2013 +0200
Butchered version of "Bumping version.."
Change-Id: Ieb5f31fe037bcf45cc86a906f983a0ab3f636468
commit bfd7276abd1ec5e6f4af7f8276e97036faf2f621
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 18:57:04 2013 +0200
Trimmed version of "VFS: use 64-bit file..."
Change-Id: I1b53ef05e939f6afed97f507d443a1d60ed81a21
commit f3fe36d509fda37908b86a64e045e6e098a6642b
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Oct 5 18:37:39 2013 +0200
Trimmed version of "stat.h: remove some big_ types"
Change-Id: I6c17d6e5e9d2ab4c1bbf33e461cec4c37b870266
commit 102318751f05b39cc8b21c1e63b04c4980d0363b
Author: Thomas Veerman <thomas@minix3.org>
Date: Thu Mar 7 14:46:21 2013 +0000
Define protocol version of {mode,ino,uid,gid}_t
Change-Id: Ia2027749f2ce55a561d19eb895a5618505e9a2ac
commit 987b05d80433dd5cdc1ccca348c1156f68698394
Author: Thomas Veerman <thomas@minix3.org>
Date: Mon Mar 25 21:09:10 2013 +0000
VFS-FS protocol: add versioning
Change-Id: Ice6fbfd4b535b7435653fa08b27a3378d1cfdbf8
commit 59d748a0c59b0b0b335deaddc48d64f4075768be
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Sep 28 14:46:21 2013 +0200
Input infrastructure, INPUT server, PCKBD driver
This commit separates the low-level keyboard driver from TTY, putting
it in a separate driver (PCKBD). The commit also separates management
of raw input devices from TTY, and puts it in a separate server
(INPUT). All keyboard and mouse input from hardware is sent by drivers
to the INPUT server, which either sends it to a process that has
opened a raw input device, or otherwise forwards it to TTY for
standard processing.
Design by Dirk Vogt. Prototype by Uli Kastlunger.
Additional changes made to the prototype:
- the event communication is now based on USB HID codes; all input
drivers have to use USB codes to describe events;
- all TTY keymaps have been converted to USB format, with the effect
that a single keymap covers all keys; there is no (static) escaped
keymap anymore;
- further keymap tweaks now allow remapping of literally all keys;
- input device renumbering and protocol rewrite;
- INPUT server rewrite, with added support for cancel and select;
- PCKBD reimplementation, including PC/AT-to-USB translation;
- support for manipulating keyboard LEDs has been added;
- keyboard and mouse multiplexer devices have been added to INPUT,
primarily so that an X server need only open two devices;
- a new "libinputdriver" library abstracts away protocol details from
input drivers, and should be used by all future input drivers;
- both INPUT and PCKBD can be restarted;
- TTY is now scheduled by KERNEL, so that it won't be punished for
running a lot; without this, simply running "yes" on the console
kills the system;
- the KIOCBELL IOCTL has been moved to /dev/console;
- support for the SCANCODES termios setting has been removed;
- obsolete keymap compression has been removed;
- the obsolete Olivetti M24 keymap has been removed.
Change-Id: I3a672fb8c4fd566734e4b46d3994b4b7fc96d578
commit fff12f52f32208f3cc97d0f39080eb3e19288b57
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Sep 27 11:56:29 2013 +0000
TTY: allow selecting on translated minors
Due to the existence of /dev/console and /dev/log, and the new
"console=" setting, it is now possible that a single non-PTY object
(e.g. serial) is accessible through two different minor numbers. This
poses a problem when sending late select replies (CDEV_SEL2_REPLY),
because the object's minor number can not be used to identify the
device. Since selecting on such objects through translated minor
numbers is actually required, we now save the minor number used to
initiate the select query in order to send a late reply.
The solution is suboptimal, as it is not possible to use two different
minors to select on the same object at once. In the future, there
should be at least one select record for each minor that can be used
with each object.
Change-Id: I4d39681d2ffd68b4047daf933d45b7bafe3c885e
commit 09cd72d9d415fd83f7bc0c652ba54ac9936916b8
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Sep 21 17:35:15 2013 +0200
Take LOG out of the boot image
Change-Id: Id2629776b53aae46629b04a42c15cbbacac9b949
commit 717b780db6338a136a97bb1ea1464933b7cef90e
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Sep 21 15:03:20 2013 +0200
Kernel: make SIGKMESS target process list dynamic
The set of processes to which a SIGKMESS signal is sent whenever new
diagnostics messages are added to the kernel's message buffer, is now
no longer hardcoded. Instead, processes can (un)register themselves
to receive such notifications, by means of sys_diagctl().
Change-Id: I9d6ac006a5d9bbfad2757587a068fc1ec3cc083e
commit bdf6de1805fcdb3c1b706a8f980e4b65a65e085a
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Sep 21 00:58:46 2013 +0200
Rename SYSCTL kernel call to DIAGCTL
Change-Id: I1b17373f01808d887dcbeab493838946fbef4ef6
commit 0270b4ac40f985bb3c3dcca9ff9c6c030755a017
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 20:13:59 2013 +0200
Prevent Jenkins from breaking on old df(1)
Change-Id: Ie8e1758bd9de4d5c95c597302f80d568058fbb68
commit e17a2a5337d16d451bdcb0cbc7d1dfb05b1cc383
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 14:09:47 2013 +0200
Add testvnd.sh test script
As part of this, change the "run" script to allow certain scripts to
be run as root only.
Change-Id: I846e41037f9d4f6c7fc0b5ea8250303a7bd72f5d
commit b2528b7a6f782fd45e16f75016c32f1543e32a08
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 14:06:46 2013 +0200
Import NetBSD vndconfig(8)
The tool has been changed heavily to match our VND driver model.
NetBSD is in the process of renaming it from vnconfig(8) to
vndconfig(8). To keep things in sync, we have to play along.
Change-Id: Ie86df184f03ab00573ea76b43c9caa0412e8321d
commit 2d73d3838881f14c3fe1817103e1b91e9674f33c
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 14:02:17 2013 +0200
Add VND driver, providing loopback devices
Change-Id: I40fa695e28c67477a75383e6f1550e451afcab41
commit 976a539cafddfe3c802a9e361bebd8cf45635e7d
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 13:55:15 2013 +0200
VFS: add dupfrom(2) call
This call copies a file descriptor from a remote process into the
calling process. The call is for the VND driver only, and in the
future, ACLs will prevent any other process from using this call.
Change-Id: Ib16fdd1f1a12cb38a70d7e441dad91bc86898f6d
commit 524aa989d316c33be15087f7865570bad6382dd0
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 11:46:08 2013 +0200
tests: do not skip installed shell tests
When installed, the test scripts lose their ".sh" suffix, causing them
to be skipped by the "run" script. With this patch, the tests are no
longer specified with ".sh" suffix in the run script, and the suffix
is added automatically as necessary.
Change-Id: I0b72312e79992b9818559c6546a0e52cd95184c2
commit e4da523dd76a4fafb2c756a85a7abf5b0def91b9
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 13:41:56 2013 +0200
blocktest: prepare to be run as part of tests
- fail SEF initialization if any of the subtests failed, so that the
party invoking the "service up" can tell whether the test succeeded;
- add "nocontig" option, because VM isn't particularly good at
allocating contiguous memory;
- add "silent" option, because it floods the console otherwise;
- allow the device size to be smaller than the maximum transfer size;
- install files to installed test directory.
Change-Id: I45c818f817c11d90c5f94ae26a2fc49e36e6761e
commit e1494963470e8fb83db31bba836f00e2e8e74f57
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 18 13:38:36 2013 +0200
Enable devname(3)
There is no support for a device name database yet, so this call is
expected to be fairly slow.
Change-Id: I73aa5f267e2b6921b7d3bbdcc4beac463931132c
commit b993fcb1ace807ad5c0718dac891efa4bc9b5097
Author: David van Moolenbroek <david@minix3.org>
Date: Sun Sep 15 13:09:00 2013 +0200
libbdev: be less noisy about clean driver restarts
Change-Id: Ie02a459c9b544d361ab00bac431ef99de53b0c5f
commit 896eb4d7df19ac1f3b4ad6475fd95c544054e9c2
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Sep 14 14:43:53 2013 +0200
Straighten ioctl.h
- include all ioctl subheaders, properly listing all letters;
- change FBD's ioctl calls to use 'B' instead of 'F', in
preparation of the VND driver.
Change-Id: Ia718979568cc057f47cf505a89238d5b3b6695d4
commit b1339cb33d20d9e5e6409b84bec7defa7a8bac21
Author: David van Moolenbroek <david@minix3.org>
Date: Sun Sep 15 18:55:42 2013 +0200
VM: readd support for forgetting cached FS blocks
Not all services involved in block I/O go through VM to access the
blocks they need. As a result, the blocks in VM may become stale,
possibly causing corruption when the stale copy is restored by a
service that does go through VM later on. This patch restores support
for forgetting cached blocks that belong to a particular device, and
makes the relevant file systems use this functionality 1) when
requested by VFS through REQ_FLUSH, and 2) upon unmount.
Change-Id: I0758c5ed8fe4b5ba81d432595d2113175776aff8
commit a8ca37a5eb1456777125fed7de0fedb1a78e5078
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 11 14:50:18 2013 +0200
filter: use libblockdriver
Change-Id: Ifbca2482e996ddca58036d45f557165e636fb3fa
commit 4bfc7de552a592b7784f330939a91dc67e2e6ee9
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 10 20:25:01 2013 +0200
Rewrite character driver protocol
As a side effect, remove the clone style, as the normal device style
supports device cloning now.
Change-Id: Ie82d1ef0385514a04a8faa139129a617895780b5
commit 70382bd94fb84be40c7b4ed31c4ea0e8e36a1bc8
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 10 16:06:37 2013 +0200
Remove support for reopening character devices
Previously, VFS would reopen a character device after a driver crash
if the associated file descriptor was opened with the O_REOPEN flag.
This patch removes support for this feature. The code was complex,
full of uncovered corner cases, and hard to test. Moreover, it did not
actually hide the crash from user applications: they would get an
error code to indicate that something went wrong, and have to decide
based on the nature of the underlying device how to continue.
- remove support for O_REOPEN, and make playwave(1) reopen its device;
- remove support for the DEV_REOPEN protocol message;
- remove all code in VFS related to reopening character devices;
- no longer change VFS filp reference count and FD bitmap upon filp
invalidation; instead, make get_filp* fail all calls on invalidated
FDs except when obtained with the locktype VNODE_OPCL which is used
by close_fd only;
- remove the VFS fproc file descriptor bitmap entirely, returning to
the situation that a FD is in use if its slot points to a filp; use
FILP_CLOSED as single means of marking a filp as invalidated.
Change-Id: I34f6bc69a036b3a8fc667c1f80435ff3af56558f
commit 772e09daec0d3fef3e6e7954cead545af5fa1c80
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 10 12:19:08 2013 +0200
VFS: rework device code
- block the calling thread on character device close;
- fully separate block and character open/close routines;
- reuse generic open/close code for the cloning case;
- zero all messages to drivers before filling them;
- use appropriate types for major/minor device numbers.
Change-Id: Ia90e6fe5688f212f835c5ee1bfca831cb249cf51
commit 39e49a673d2710d291ae7d7936da74b7cf082f9a
Author: David van Moolenbroek <david@minix3.org>
Date: Mon Sep 9 00:04:12 2013 +0200
Make PFS backcalls regular VFS calls
- prefix them with VFS_ as they are going to VFS;
- give these calls normal call numbers;
- give them their own set of message field aliases;
- also make do_mapdriver a regular call.
Change-Id: I2140439f288b06d699a1f65438bd8306509b259e
commit 317bafb80c03a081475a49b7a17adfefb1e235ac
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 11 12:48:10 2013 +0200
TTY: use libchardriver; clean up
- writing to a PTY master side blocks if there is not already a
blocked reader on the slave side, and select now reflects this;
- internally, TTY now uses a test based on "caller != NONE" rather
than "grant != GRANT_INVALID" to identify whether a call is
currently ongoing;
- "offset" fields have been removed as they equal the corresponding
"cum" fields;
- improved variable typing and function naming here and there;
- various other small fixes.
Change-Id: I6b51452888942e864b4e034e8c8490576184a23e
commit c371bff479200bb97f7b27e89709f77c4b975e5e
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 11 01:13:59 2013 +0200
VFS: select(2) fixes
- check each file descriptor's open access mode (filp_mode);
- treat an error returned by a character driver as a select error;
- check all filps in each set before finishing select;
- do not copy back file descriptor sets if an error occurred;
- remove the hardcoded list of supported character major devices,
since all drivers should now be capable of responding properly;
- add tests to test40 and fix its error count aggregation.
Change-Id: I57ef58d3afb82640fc50b59c859ee4b25f02db17
commit 70195f8d567829c409c58f1d5b8b92c9e775df72
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 11 01:07:28 2013 +0200
Retire EBADIOCTL in favor of ENOTTY
Change-Id: I6bd0e301d21ab7f2336e350e7e6e15d238c2c93d
commit 9e863893aef0e0c559dc7789b180d84bff73f6eb
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 4 15:42:36 2013 +0000
libnetsock: use libchardriver
Change-Id: Ia5b780cad0b0c636db9bd866c7223da0d38ef6ea
commit 55765275729397486365e2656fa1c5f0476eeb28
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 11 00:50:36 2013 +0200
LWIP: move chardev message parsing into libnetsock
Change-Id: Ie23fd003c9fa35811548f388c8e9b55e8d9de8d7
commit 883472c8d1ba8cc9990202af1105c13eb81216f7
Author: David van Moolenbroek <david@minix3.org>
Date: Mon Sep 9 14:53:28 2013 +0000
INET: use libchardriver
Change-Id: Icf8a1a5769ce0aede1cc28da99b9daf7d328182c
commit daff5f2ac40d7fd0866d19af91526da66bab523d
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 3 02:00:20 2013 +0200
PFS: use libchardriver; clean up
- simplify and repair UDS request handling state machine;
- simplify interface used between internal modules;
- implement missing support for nonblocking I/O;
- fix select implementation;
- clean up global variables.
Change-Id: Ia82c5c6f05cc3f0a498efc9a26de14b1cde6eace
commit e17e4ed7a0c6dcb975041fd144df17037c96281a
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 3 01:59:20 2013 +0200
libaudiodriver: use libchardriver
Change-Id: I299d58d110ad14b69076276ba46c4325875c34ca
commit 6be0c5d8bc6b7ce6cc4af506e12f0f3cc0bcf307
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 3 01:57:41 2013 +0200
printer: use libchardriver
Change-Id: Ifa3cabeada74c32df2613b8279c00f86e831c775
commit 0ccb2597747ec1e495623e149cbe2bb9301c91ec
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 3 01:49:38 2013 +0200
libchardriver: full API rewrite
The new API now covers the entire character driver protocol, while
hiding all the message details. It should therefore be used by all
new character drivers. All existing drivers that already made use of
libchardriver have been changed to use the new API.
As one of the most important API changes, support for scatter and
gather transfers has been removed, as several key drivers already
did not support this, and it could be supported at the safecopy
level instead (for a future readv/writev).
Additional changes include:
- respond to block device open requests to avoid hanging VFS threads;
- add support for sef_cancel.
Change-Id: I1bab6c1cb66916c71b87aeb1db54a9bdf171fe6b
commit b96fbc55af87c31a76cc95c7962758f1cf1d9c18
Author: David van Moolenbroek <david@minix3.org>
Date: Thu Aug 1 18:20:33 2013 +0200
blocktest: add support for no alignment
Some block drivers do not impose any alignment requirements, and this
patch allows such block drivers to pass the test set. As a side effect,
minimal support for min_write is added, but this part of blocktest is
in need of further improvement.
commit 993c1060f876de2b7ef2169a79957d709ff1137e
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Apr 18 00:04:28 2012 +0200
libutil: let opendisk(3) try /dev
If a device node is given without path, and opening the node fails
initially, prepend "/dev/" to the node name and try opening again.
This is more in line with NetBSD behavior.
commit 0aba92d3d77f635308ca422e7c72b4410dce4816
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 10 23:57:32 2013 +0200
Block drivers: make IOCTL request unsigned long
The block driver protocol and libblockdriver's bdr_ioctl hook are
changed, as well as the users of this hook. Other parts of the system
are expected to change accordingly eventually, since the ioctl(2)
prototype has been aligned with NetBSD's.
Change-Id: Ide46245b22cfa89ed267a38088fb0ab7696eba92
commit d96dbd5c64cfcb609845aff224b914a672c9b8cb
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Jul 27 00:49:49 2013 +0200
Block protocol: add user endpoint to IOCTL request
I/O control requests now come with the endpoint of the user process
that initiated the ioctl(2) call. It is stored in a new BDEV_USER
field, which is an alias for BDEV_FLAGS. The contents of this field
are to be used only in highly specific situations. It should be
preserved (not replaced!) by services that forward IOCTL requests,
and may be set to NONE for service-initiated IOCTL requests.
Change-Id: I68a01b9ce43eca00e61b985a9cf87f55ba683de4
commit c86d0cdf09efc6d596a9d390b7ce71193ee716a1
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Jul 27 00:49:49 2013 +0200
Block protocol: use own [RW]_BIT definitions
The original R_BIT and W_BIT definitions have nothing to do with the
way these bits are used. Their distinct usage is more apparent when
they have different names.
Change-Id: Ia984457f900078b2e3502ceed565fead4e5bb965
commit e7e243cbb6cefc29c28bc7412ebd58a968ba8ad0
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Sep 10 23:35:15 2013 +0200
libblockdriver: expose BLOCKDRIVER_MAX_DEVICES
This constant determines the range of valid device_id_t values that
a block driver can return from the bdr_device hook: a value between
0 and (BLOCKDRIVER_MAX_DEVICES - 1) inclusive.
Change-Id: I80fac469e88ac13d4b869007e6f2c2f7569da433
commit 8cdecd40a59bcd267de5379125f00ed2548ce260
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Sep 11 13:33:00 2013 +0200
libblockdriver: various updates
- internal structure rearrangement;
- respond to char device open requests to avoid hanging VFS threads;
- make drivers use designated initializers;
- use devminor_t for all minor device numbers;
- change bdr_other hook to take ipc_status and return nothing;
- fix default geometry computation;
- add support for sef_cancel.
Change-Id: Ia063a136a3ddb2b78de36180feda870605753d70
commit 4fcf5cb40702a0157ab7609053eb871515d834b5
Author: David van Moolenbroek <david@minix3.org>
Date: Sun Sep 1 14:34:17 2013 +0200
Block drivers: reply ENOTTY to unknown IOCTLs
Change-Id: Ie2e82d2491d546f4dd73b009100646e249a147b5
commit 6e1eaef728d42dcfb606c0c375ad6cca11eb7495
Author: David van Moolenbroek <david@minix3.org>
Date: Sun Jul 28 14:03:07 2013 +0200
Move SUB_PER_DRIVE definition into minix/drvlib.h
commit 6720bd98fd9975fb40b3f195680c3414093479f0
Author: David van Moolenbroek <david@minix3.org>
Date: Mon Sep 2 17:34:44 2013 +0200
VFS: update filp_pos on chardev I/O (workaround)
Previously, reading from or writing to a character device would not
update the file position on the corresponding filp object. Performing
this update correctly is not trivial: during and after the I/O
operation, the filp object must not be locked. Ideally, read/write
requests on a filp that is already involved in a read/write operation,
should be queued. For now, we optimistically update the file position
at the start of the I/O; this works under the assumptions listed in
the corresponding comment.
Change-Id: I172a61781850423709924390ae3df1f2d1f94707
commit 3fac54b08b9034f6f3506632b07e31c90fd630cf
Author: David van Moolenbroek <david@minix3.org>
Date: Mon Sep 2 13:45:02 2013 +0200
I2C: change BUSC_I2C_xxx to use own protocol
Previously it would use bits of the character driver protocol, which
will change heavily. In the new situation, the BUSC_I2C_xxx requests
use a protocol more in line with the PCI protocol, with the reply code
in m_type.
Change-Id: I51597b3f191078c8178ce17372de123031f7a4c4
commit 96e365d6e440c7a9885da17b9552c21415770d65
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Aug 31 16:13:37 2013 +0200
tests: add test77 for opening/closing PTYs
Change-Id: I30e3418f75137aa08037fa6581ff3d4cce32a114
commit 46a0bba56f3317acee4b1dbebc3a2a829926198f
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Aug 31 16:08:25 2013 +0200
TTY: fix for PTY open/close logic
Opening and closing the master side of a pseudo terminal without
opening the slave side would result in the pseudo terminal becoming
permanently unavailable. In addition, reopening the slave side
would be possible but not allow for I/O. Finally, attempting to
open an in-use master would wipe its I/O state. These issues have
been resolved.
Change-Id: I9235e3d9aba321803f9280b86b6b5e3646ad5ef3
commit 5fe976c95b584d8d37362c28efd074993b4273fc
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 18:48:56 2013 +0200
tests: remove select subdirectory
This test set has been obsoleted by test40.
Change-Id: I55439152824906778ad07d409dfb327ac10bea70
commit fbcc5fd0878cf1a74f4e75c62bf4f9ee32fc601e
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 18:43:23 2013 +0200
tests: add test76 for interrupting VFS operations
Change-Id: Ic436cac61de8c42e0c7ee2d442c647528654cde9
commit a33a803a70ca467e4bc1ee684aa468815344c785
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Aug 28 13:08:16 2013 +0200
VFS: fix interruption of blocking pipe operations
POSIX states that when interrupted, partially successful pipe
operations should return the partial result rather than EINTR. VFS
previously wouldn't look at the partial result, and not clear it
either, which would result in a panic upon the next pipe operation.
Change-Id: Ia1eb72b4b77394051444e63a1390d49bb315eb04
commit 20d872e753b796c315f5cd7f66ac92f592d000db
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 00:57:16 2013 +0200
libmthread: do not dump stack for free threads
Change-Id: Ic438a252f5bddaf1513f554c71173e6fffb0c674
commit 7c8902e360a0b2ca4d411196a64227117defdc6b
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 14:00:50 2013 +0200
VFS: worker thread model overhaul
The main purpose of this patch is to fix handling of unpause calls
from PM while another call is ongoing. The solution to this problem
sparked a full revision of the threading model, consisting of a large
number of related changes:
- all active worker threads are now always associated with a process,
and every process has at most one active thread working for it;
- the process lock is always held by a process's worker thread;
- a process can now have both normal work and postponed PM work
associated to it;
- timer expiry and non-postponed PM work is done from the main thread;
- filp garbage collection is done from a thread associated with VFS;
- reboot calls from PM are now done from a thread associated with PM;
- the DS events handler is protected from starting multiple threads;
- support for a system worker thread has been removed;
- the deadlock recovery thread has been replaced by a parameter to the
worker_start() function; the number of worker threads has
consequently been increased by one;
- saving and restoring of global but per-thread variables is now
centralized in worker_suspend() and worker_resume(); err_code is now
saved and restored in all cases;
- the concept of jobs has been removed, and job_m_in now points to a
message stored in the worker thread structure instead;
- the PM lock has been removed;
- the separate exec lock has been replaced by a lock on the VM
process, which was already being locked for exec calls anyway;
- PM_UNPAUSE is now processed as a postponed PM request, from a thread
associated with the target process;
- the FP_DROP_WORK flag has been removed, since it is no longer more
than just an optimization and only applied to processes operating on
a pipe when getting killed;
- assignment to "fp" now takes place only when obtaining new work in
the main thread or a worker thread, when resuming execution of a
thread, and in the special case of exiting processes during reboot;
- there are no longer special cases where the yield() call is used to
force a thread to run.
Change-Id: I7a97b9b95c2450454a9b5318dfa0e6150d4e6858
commit 07c7bf859263dd44effd6fbefc065cd1ddafafe8
Author: David van Moolenbroek <david@minix3.org>
Date: Wed Aug 28 15:58:30 2013 +0200
Retire ptrace(T_DUMPCORE), dumpcore(1), gcore(1)
The T_DUMPCORE implementation was not only broken - it would currently
produce a coredump of the tracer process rather than the traced
process - but also deeply flawed, and fixing it would require serious
alteration of PM's internal state machine. It should be possible to
implement the same functionality in userland, and that is now the
suggested way forward. For now, also remove the (identical) utilities
using T_DUMPCORE: dumpcore(1) and gcore(1).
Change-Id: I1d51be19c739362b8a5833de949b76382a1edbcc
commit 63d7dd8fd0da01b217e57b137724a0d79c715432
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 13:42:51 2013 +0200
VFS: process char driver replies from main thread
Previously, processing of some replies coming from character drivers
could block on locks, and therefore, such processing was done from
threads that were associated to the character driver process. The
hidden consequence of this was that if all threads were in use, VFS
could drop replies coming from the driver. This patch returns VFS to
a situation where the replies from character drivers are processed
instantly from the main thread, by removing the situations that may
cause VFS to block while handling those replies.
- change the locking model for select, so that it will never block
on any processing that happens after the select call has been set
up, in particular processing of character driver select replies;
- clearly mark all select routines that may never block;
- protect against race conditions in do_select as result of the
locking that still does happen there (as is required for pipes);
- also handle select timers from the main thread;
- move processing of character driver replies into device.c.
Change-Id: I4dc8e69f265cbd178de0fbf321d35f58f067cc57
commit 3afa0ff4b95928cd25a82e13740018a4c702120d
Author: David van Moolenbroek <david@minix3.org>
Date: Sun Aug 25 00:26:38 2013 +0200
VFS: properly cancel select queries on unpause
Change-Id: I16e71db3f5c1bcc7ba6045bc9f02b13d71dc31eb
commit 36453271e54fbdf0917219163107fb16f03b89ec
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 13:33:56 2013 +0200
VFS: remove support for sync char driver protocol
Change-Id: I57cc870a053b813b3a3fc45da46606ea84fe4cb1
commit acdbe00dc78feb4d453943d1e98d335e8cff0240
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 13:00:44 2013 +0200
VFS: remove FP_BLOCKED_ON_DOPEN
These days, DEV_OPEN calls to character drivers block the calling
thread until completion or failure, and thus never return SUSPEND to
the caller. The same already applied to BDEV_OPEN calls to block
drivers. It has thus become impossible for a process to enter a state
of being blocked on a device open call.
There is currently no support for restarting device open calls to
restarted character drivers. This support was present in the _DOPEN
logic, but was already no longer triggering. In the future, this case
should be handled by the thread performing the open request.
Change-Id: I6cc1e7b4c9ed116c6ce160b315e6e060124dce00
commit 5b4173a09a354fba3c0e9caf2746228e3980159a
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 12:18:27 2013 +0200
PFS: remember request information for IOCTLs
Not doing so caused PFS to commit protocol violations by relying on
stale information when sending replies. This stale information always
happened to be correct, which is why the problem went unnoticed.
Change-Id: Ia42ca670718d6e731193cd2c34a3ff455f8a94d3
commit c58bdb3a337dfff55998d9f9722e63886c803fac
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 11:14:03 2013 +0200
Retire the synchronous character driver protocol
- change all sync char drivers into async drivers;
- retire support for the sync protocol in libchardev;
- remove async dev style, as this is now the default;
- remove dev_status from VFS;
- clean up now-unused protocol messages.
Change-Id: I6aacff712292f6b29f2ccd51bc1e7d7003723e87
commit a349640fa6bb49b30a1b704004180113fa2c0ee7
Author: David van Moolenbroek <david@minix3.org>
Date: Fri Aug 30 10:48:34 2013 +0200
Sync char protocol: add nonblocking transfer flag
The async char protocol already has this, so this patch closes the
gap between the two protocols a bit. Support for this flag has been
added to all sync char drivers that support CANCEL at all.
The LOG driver was already using the asynchronous protocol, but it
did not support the nonblocking transfer flag. This has been fixed
as well.
Change-Id: Ia55432c9f102765b59ad3feb45a8bd47a782c93f
commit c1a0e4f59c24e899e5dd9858856a3363f418b93c
Author: David van Moolenbroek <david@minix3.org>
Date: Sat Aug 24 12:29:39 2013 +0200
VFS: set w_drv_sendrec only when needed
As with w_task, this ensures that the field remains cleared if it is
not used. Without this, worker_stop could mistakenly identify a thread
as talking to a device driver rather than a (crashed) file server.
Change-Id: I7d3ebed3efc3cd4f5c891f61c67a6463109b6376
commit 1d481920bb981c095fd8b5a69926bc3726a1e06f
Author: Thomas Veerman <thomas@minix3.org>
Date: Sat Aug 24 12:23:41 2013 +0200
VFS: set w_task only when needed
It was always set, but not always cleared, when talking to asynchronous
drivers. This could cause erratic behavior upon a driver crash.
Normally, a worker thread's w_task field is set when it's about to
communicate with a driver or FS. Then upon receiving a reply we can
do sanity checks (that the thread we want to wake up was actually
waiting for a reply). Also, when a driver/FS crashes, we can identify
which worker threads were talking to the crashed endpoint and handle
the error gracefully.
Asynchronous drivers are a bit special, though. In most cases, the
sender of the request is not interested in the reply (the sender was
suspended and only wants to know whether the request was successfully
caried out or not). However, the open request is special, as the reply
carries information needed by the sender. This is the only request
where a worker thread actually yields and waits for the result. This is
also the only case where we're interested in setting w_task for
asynchronous drivers.
Change-Id: Ia1ce2747937df376122b5e13b6a069de27fcc379
commit 5f765ae525474824f5c5ead2c960bca167beb160
Author: David van Moolenbroek <david@minix3.org>
Date: Mon Aug 19 20:34:15 2013 +0200
Import NetBSD df(1)
Change-Id: Ia60f8b23b961e4132efece1e7e38f0d63597c13b
commit d5859394ded95c5f0609072d605a2c47aaca4f22
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 01:33:43 2013 +0200
Enable getmntinfo(3)
Change-Id: Id9d11a67cdcad331a52030127f7c7ead3c847919
commit d120973fa9b8a014c5606bd257dd0f305c6dbe63
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 00:49:07 2013 +0200
test55: add tests for getvfsstat(2)
Change-Id: Iad4567068a82bb0e780891a478ba5a06b63f1d48
commit 885cd5462015d5a5137b8e5e2a946d4bebdef19a
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 01:28:23 2013 +0200
Implement support for [f]statvfs1(2)
The [f]statvfs(3) calls now use [f]statvfs1(2).
Change-Id: I56c92fe1c70670f476631c4a50e47351562712c6
commit 5de979e5ddd2f8e1be84748ea7071a3f52c458ae
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 01:39:47 2013 +0200
Implement support for getvfsstat(2)
Change-Id: I4680c071b94fa855edfb6220b03cff6b20f3c1c9
commit 17edae161bda15f5e2a0f7228a8f08c2ec0a7d84
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 01:37:18 2013 +0200
Redo mount(2)/umount(2) ABI
- pass in file system type through mount(2), and return this type in
statvfs structures as generated by [f]statvfs(2);
- align mount flags field with NetBSD's, splitting out service flags
which are not to be passed to VFS;
- remove limitation of mount ABI to 16-byte labels, so that labels
can be made larger in the future;
- introduce new m11 message union type for mount(2) as side effect.
Change-Id: Ia9ed4566d88af5239749c57274312be26bb61448
commit ec063ff840f9717f86b2c36802c3cd1d07bdf360
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 01:35:35 2013 +0200
Align "struct statvfs" with NetBSD
This is a requirement for implementing calls such as getmntinfo(3).
VFS is now responsible for filling in some of the structure's fields.
Change-Id: I457b463c70ea2f326b9c50de954a91cfefba0065
commit ca09db743f192508b7078e9adef85f1b7cf11073
Author: David van Moolenbroek <david@minix3.org>
Date: Tue Aug 20 00:55:49 2013 +0200
VFS/FS: remove fstatfs(2) and REQ_FSTATFS
The fstatfs(3) call now uses fstatvfs(2).
Change-Id: Ic6bbb040e1a8f01aaffe1a6a809dd4c7a2eae2f6
Change-Id: I14141beaf9804e10d9cf3de706bdc9b9d9cc947b
1357 lines
47 KiB
C
1357 lines
47 KiB
C
/* This file contains the device dependent part of the driver for the Floppy
|
|
* Disk Controller (FDC) using the NEC PD765 chip.
|
|
*
|
|
* The file contains two entry points:
|
|
*
|
|
* floppy_task: main entry when system is brought up
|
|
*
|
|
* Changes:
|
|
* Sep 11, 2005 code cleanup (Andy Tanenbaum)
|
|
* Dec 01, 2004 floppy driver moved to user-space (Jorrit N. Herder)
|
|
* Sep 15, 2004 sync alarms/ local timer management (Jorrit N. Herder)
|
|
* Aug 12, 2003 null seek no interrupt fix (Mike Haertel)
|
|
* May 14, 2000 d-d/i rewrite (Kees J. Bot)
|
|
* Apr 04, 1992 device dependent/independent split (Kees J. Bot)
|
|
* Mar 27, 1992 last details on density checking (Kees J. Bot)
|
|
* Feb 14, 1992 check drive density on opens only (Andy Tanenbaum)
|
|
* 1991 len[] / motors / reset / step rate / ... (Bruce Evans)
|
|
* May 13, 1991 renovated the errors loop (Don Chapman)
|
|
* 1989 I/O vector to keep up with 1-1 interleave (Bruce Evans)
|
|
* Jan 06, 1988 allow 1.44 MB diskettes (Al Crew)
|
|
* Nov 28, 1986 better resetting for 386 (Peter Kay)
|
|
* Oct 27, 1986 fdc_results fixed for 8 MHz (Jakob Schripsema)
|
|
*/
|
|
|
|
#include "floppy.h"
|
|
#include <minix/timers.h>
|
|
#include <machine/diskparm.h>
|
|
#include <minix/sysutil.h>
|
|
#include <minix/syslib.h>
|
|
#include <minix/endpoint.h>
|
|
#include <stdio.h>
|
|
|
|
/* I/O Ports used by floppy disk task. */
|
|
#define DOR 0x3F2 /* motor drive control bits */
|
|
#define FDC_STATUS 0x3F4 /* floppy disk controller status register */
|
|
#define FDC_DATA 0x3F5 /* floppy disk controller data register */
|
|
#define FDC_RATE 0x3F7 /* transfer rate register */
|
|
#define DMA_ADDR 0x004 /* port for low 16 bits of DMA address */
|
|
#define DMA_TOP 0x081 /* port for top 8 bits of 24-bit DMA addr */
|
|
#define DMA_COUNT 0x005 /* port for DMA count (count = bytes - 1) */
|
|
#define DMA_FLIPFLOP 0x00C /* DMA byte pointer flip-flop */
|
|
#define DMA_MODE 0x00B /* DMA mode port */
|
|
#define DMA_INIT 0x00A /* DMA init port */
|
|
#define DMA_RESET_VAL 0x006
|
|
|
|
#define DMA_ADDR_MASK 0xFFFFFF /* mask to verify DMA address is 24-bit */
|
|
|
|
/* Status registers returned as result of operation. */
|
|
#define ST0 0x00 /* status register 0 */
|
|
#define ST1 0x01 /* status register 1 */
|
|
#define ST2 0x02 /* status register 2 */
|
|
#define ST3 0x00 /* status register 3 (return by DRIVE_SENSE) */
|
|
#define ST_CYL 0x03 /* slot where controller reports cylinder */
|
|
#define ST_HEAD 0x04 /* slot where controller reports head */
|
|
#define ST_SEC 0x05 /* slot where controller reports sector */
|
|
#define ST_PCN 0x01 /* slot where controller reports present cyl */
|
|
|
|
/* Fields within the I/O ports. */
|
|
/* Main status register. */
|
|
#define CTL_BUSY 0x10 /* bit is set when read or write in progress */
|
|
#define DIRECTION 0x40 /* bit is set when reading data reg is valid */
|
|
#define MASTER 0x80 /* bit is set when data reg can be accessed */
|
|
|
|
/* Digital output port (DOR). */
|
|
#define MOTOR_SHIFT 4 /* high 4 bits control the motors in DOR */
|
|
#define ENABLE_INT 0x0C /* used for setting DOR port */
|
|
|
|
/* ST0. */
|
|
#define ST0_BITS_TRANS 0xD8 /* check 4 bits of status */
|
|
#define TRANS_ST0 0x00 /* 4 bits of ST0 for READ/WRITE */
|
|
#define ST0_BITS_SEEK 0xF8 /* check top 5 bits of seek status */
|
|
#define SEEK_ST0 0x20 /* top 5 bits of ST0 for SEEK */
|
|
|
|
/* ST1. */
|
|
#define BAD_SECTOR 0x05 /* if these bits are set in ST1, recalibrate */
|
|
#define WRITE_PROTECT 0x02 /* bit is set if diskette is write protected */
|
|
|
|
/* ST2. */
|
|
#define BAD_CYL 0x1F /* if any of these bits are set, recalibrate */
|
|
|
|
/* ST3 (not used). */
|
|
#define ST3_FAULT 0x80 /* if this bit is set, drive is sick */
|
|
#define ST3_WR_PROTECT 0x40 /* set when diskette is write protected */
|
|
#define ST3_READY 0x20 /* set when drive is ready */
|
|
|
|
/* Floppy disk controller command bytes. */
|
|
#define FDC_SEEK 0x0F /* command the drive to seek */
|
|
#define FDC_READ 0xE6 /* command the drive to read */
|
|
#define FDC_WRITE 0xC5 /* command the drive to write */
|
|
#define FDC_SENSE 0x08 /* command the controller to tell its status */
|
|
#define FDC_RECALIBRATE 0x07 /* command the drive to go to cyl 0 */
|
|
#define FDC_SPECIFY 0x03 /* command the drive to accept params */
|
|
#define FDC_READ_ID 0x4A /* command the drive to read sector identity */
|
|
#define FDC_FORMAT 0x4D /* command the drive to format a track */
|
|
|
|
/* DMA channel commands. */
|
|
#define DMA_READ 0x46 /* DMA read opcode */
|
|
#define DMA_WRITE 0x4A /* DMA write opcode */
|
|
|
|
/* Parameters for the disk drive. */
|
|
#define HC_SIZE 2880 /* # sectors on largest legal disk (1.44MB) */
|
|
#define NR_HEADS 0x02 /* two heads (i.e., two tracks/cylinder) */
|
|
#define MAX_SECTORS 18 /* largest # sectors per track */
|
|
#define DTL 0xFF /* determines data length (sector size) */
|
|
#define SPEC2 0x02 /* second parameter to SPECIFY */
|
|
#define MOTOR_OFF (3*system_hz) /* how long to wait before stopping motor */
|
|
#define WAKEUP (2*system_hz) /* timeout on I/O, FDC won't quit. */
|
|
|
|
/* Error codes */
|
|
#define ERR_SEEK (-1) /* bad seek */
|
|
#define ERR_TRANSFER (-2) /* bad transfer */
|
|
#define ERR_STATUS (-3) /* something wrong when getting status */
|
|
#define ERR_READ_ID (-4) /* bad read id */
|
|
#define ERR_RECALIBRATE (-5) /* recalibrate didn't work properly */
|
|
#define ERR_DRIVE (-6) /* something wrong with a drive */
|
|
#define ERR_WR_PROTECT (-7) /* diskette is write protected */
|
|
#define ERR_TIMEOUT (-8) /* interrupt timeout */
|
|
|
|
/* No retries on some errors. */
|
|
#define err_no_retry(err) ((err) <= ERR_WR_PROTECT)
|
|
|
|
/* Encoding of drive type in minor device number. */
|
|
#define DEV_TYPE_BITS 0x7C /* drive type + 1, if nonzero */
|
|
#define DEV_TYPE_SHIFT 2 /* right shift to normalize type bits */
|
|
#define FORMAT_DEV_BIT 0x80 /* bit in minor to turn write into format */
|
|
|
|
/* Miscellaneous. */
|
|
#define MAX_ERRORS 6 /* how often to try rd/wt before quitting */
|
|
#define MAX_RESULTS 7 /* max number of bytes controller returns */
|
|
#define NR_DRIVES 2 /* maximum number of drives */
|
|
#define DIVISOR 128 /* used for sector size encoding */
|
|
#define SECTOR_SIZE_CODE 2 /* code to say "512" to the controller */
|
|
#define TIMEOUT_MICROS 5000000L /* microseconds waiting for FDC */
|
|
#define NT 7 /* number of diskette/drive combinations */
|
|
#define UNCALIBRATED 0 /* drive needs to be calibrated at next use */
|
|
#define CALIBRATED 1 /* no calibration needed */
|
|
#define BASE_SECTOR 1 /* sectors are numbered starting at 1 */
|
|
#define NO_SECTOR ((unsigned) -1) /* current sector unknown */
|
|
#define NO_CYL (-1) /* current cylinder unknown, must seek */
|
|
#define NO_DENS 100 /* current media unknown */
|
|
#define BSY_IDLE 0 /* busy doing nothing */
|
|
#define BSY_IO 1 /* busy doing I/O */
|
|
#define BSY_WAKEN 2 /* got a wakeup call */
|
|
|
|
/* Seven combinations of diskette/drive are supported.
|
|
*
|
|
* # Diskette Drive Sectors Tracks Rotation Data-rate Comment
|
|
* 0 360K 360K 9 40 300 RPM 250 kbps Standard PC DSDD
|
|
* 1 1.2M 1.2M 15 80 360 RPM 500 kbps AT disk in AT drive
|
|
* 2 360K 720K 9 40 300 RPM 250 kbps Quad density PC
|
|
* 3 720K 720K 9 80 300 RPM 250 kbps Toshiba, et al.
|
|
* 4 360K 1.2M 9 40 360 RPM 300 kbps PC disk in AT drive
|
|
* 5 720K 1.2M 9 80 360 RPM 300 kbps Toshiba in AT drive
|
|
* 6 1.44M 1.44M 18 80 300 RPM 500 kbps PS/2, et al.
|
|
*
|
|
* In addition, 720K diskettes can be read in 1.44MB drives, but that does
|
|
* not need a different set of parameters. This combination uses
|
|
*
|
|
* 3 720K 1.44M 9 80 300 RPM 250 kbps PS/2, et al.
|
|
*/
|
|
static struct density {
|
|
u8_t secpt; /* sectors per track */
|
|
u8_t cyls; /* tracks per side */
|
|
u8_t steps; /* steps per cylinder (2 = double step) */
|
|
u8_t test; /* sector to try for density test */
|
|
u8_t rate; /* data rate (2=250, 1=300, 0=500 kbps) */
|
|
clock_t start_ms; /* motor start (milliseconds) */
|
|
u8_t gap; /* gap size */
|
|
u8_t spec1; /* first specify byte (SRT/HUT) */
|
|
} fdensity[NT] = {
|
|
{ 9, 40, 1, 4*9, 2, 500, 0x2A, 0xDF }, /* 360K / 360K */
|
|
{ 15, 80, 1, 14, 0, 500, 0x1B, 0xDF }, /* 1.2M / 1.2M */
|
|
{ 9, 40, 2, 2*9, 2, 500, 0x2A, 0xDF }, /* 360K / 720K */
|
|
{ 9, 80, 1, 4*9, 2, 750, 0x2A, 0xDF }, /* 720K / 720K */
|
|
{ 9, 40, 2, 2*9, 1, 500, 0x23, 0xDF }, /* 360K / 1.2M */
|
|
{ 9, 80, 1, 4*9, 1, 500, 0x23, 0xDF }, /* 720K / 1.2M */
|
|
{ 18, 80, 1, 17, 0, 750, 0x1B, 0xCF }, /* 1.44M / 1.44M */
|
|
};
|
|
|
|
/* The following table is used with the test_sector array to recognize a
|
|
* drive/floppy combination. The sector to test has been determined by
|
|
* looking at the differences in gap size, sectors/track, and double stepping.
|
|
* This means that types 0 and 3 can't be told apart, only the motor start
|
|
* time differs. If a read test succeeds then the drive is limited to the
|
|
* set of densities it can support to avoid unnecessary tests in the future.
|
|
*/
|
|
|
|
#define b(d) (1 << (d)) /* bit for density d. */
|
|
|
|
static struct test_order {
|
|
u8_t t_density; /* floppy/drive type */
|
|
u8_t t_class; /* limit drive to this class of densities */
|
|
} test_order[NT-1] = {
|
|
{ 6, b(3) | b(6) }, /* 1.44M {720K, 1.44M} */
|
|
{ 1, b(1) | b(4) | b(5) }, /* 1.2M {1.2M, 360K, 720K} */
|
|
{ 3, b(2) | b(3) | b(6) }, /* 720K {360K, 720K, 1.44M} */
|
|
{ 4, b(1) | b(4) | b(5) }, /* 360K {1.2M, 360K, 720K} */
|
|
{ 5, b(1) | b(4) | b(5) }, /* 720K {1.2M, 360K, 720K} */
|
|
{ 2, b(2) | b(3) }, /* 360K {360K, 720K} */
|
|
/* Note that type 0 is missing, type 3 can read/write it too, which is
|
|
* why the type 3 parameters have been pessimized to be like type 0.
|
|
*/
|
|
};
|
|
|
|
/* Variables. */
|
|
static struct floppy { /* main drive struct, one entry per drive */
|
|
unsigned fl_curcyl; /* current cylinder */
|
|
unsigned fl_hardcyl; /* hardware cylinder, as opposed to: */
|
|
unsigned fl_cylinder; /* cylinder number addressed */
|
|
unsigned fl_sector; /* sector addressed */
|
|
unsigned fl_head; /* head number addressed */
|
|
char fl_calibration; /* CALIBRATED or UNCALIBRATED */
|
|
u8_t fl_density; /* NO_DENS = ?, 0 = 360K; 1 = 360K/1.2M; etc.*/
|
|
u8_t fl_class; /* bitmap for possible densities */
|
|
minix_timer_t fl_tmr_stop; /* timer to stop motor */
|
|
struct device fl_geom; /* Geometry of the drive */
|
|
struct device fl_part[NR_PARTITIONS]; /* partition's base & size */
|
|
} floppy[NR_DRIVES];
|
|
|
|
static int irq_hook_id; /* id of irq hook at the kernel */
|
|
int motor_status; /* bitmap of current motor status */
|
|
static int need_reset; /* set to 1 when controller must be reset */
|
|
unsigned f_drive; /* selected drive */
|
|
static unsigned f_device; /* selected minor device */
|
|
static struct floppy *f_fp; /* current drive */
|
|
static struct density *f_dp; /* current density parameters */
|
|
static struct density *prev_dp;/* previous density parameters */
|
|
static unsigned f_sectors; /* equal to f_dp->secpt (needed a lot) */
|
|
u16_t f_busy; /* BSY_IDLE, BSY_IO, BSY_WAKEN */
|
|
static struct device *f_dv; /* device's base and size */
|
|
static struct disk_parameter_s fmt_param; /* parameters for format */
|
|
static u8_t f_results[MAX_RESULTS];/* the controller can give lots of output */
|
|
|
|
/* The floppy uses various timers. These are managed by the floppy driver
|
|
* itself, because only a single synchronous alarm is available per process.
|
|
* Besides the 'f_tmr_timeout' timer below, the floppy structure for each
|
|
* floppy disk drive contains a 'fl_tmr_stop' timer.
|
|
*/
|
|
static minix_timer_t f_tmr_timeout; /* timer for various timeouts */
|
|
static u32_t system_hz; /* system clock frequency */
|
|
static void f_expire_tmrs(clock_t stamp);
|
|
static void stop_motor(minix_timer_t *tp);
|
|
static void f_timeout(minix_timer_t *tp);
|
|
|
|
static struct device *f_prepare(devminor_t device);
|
|
static struct device *f_part(devminor_t minor);
|
|
static void f_cleanup(void);
|
|
static ssize_t f_transfer(devminor_t minor, int do_write, u64_t position,
|
|
endpoint_t proc_nr, iovec_t *iov, unsigned int nr_req, int flags);
|
|
static int dma_setup(int do_write);
|
|
static void start_motor(void);
|
|
static int seek(void);
|
|
static int fdc_transfer(int do_write);
|
|
static int fdc_results(void);
|
|
static int fdc_command(const u8_t *cmd, int len);
|
|
static void fdc_out(int val);
|
|
static int recalibrate(void);
|
|
static void f_reset(void);
|
|
static int f_intr_wait(void);
|
|
static int read_id(void);
|
|
static int f_do_open(devminor_t minor, int access);
|
|
static int f_do_close(devminor_t minor);
|
|
static int test_read(int density);
|
|
static void f_geometry(devminor_t minor, struct part_geom *entry);
|
|
|
|
/* Entry points to this driver. */
|
|
static struct blockdriver f_dtab = {
|
|
.bdr_type = BLOCKDRIVER_TYPE_DISK, /* handle partition requests */
|
|
.bdr_open = f_do_open, /* open request, sense type of diskette */
|
|
.bdr_close = f_do_close, /* nothing on a close */
|
|
.bdr_transfer = f_transfer, /* do the I/O */
|
|
.bdr_cleanup = f_cleanup, /* cleanup before sending reply to caller */
|
|
.bdr_part = f_part, /* return partition information structure */
|
|
.bdr_geometry = f_geometry, /* tell the geometry of the diskette */
|
|
.bdr_alarm = f_expire_tmrs /* expire all alarm timers */
|
|
};
|
|
|
|
static char *floppy_buf;
|
|
static phys_bytes floppy_buf_phys;
|
|
|
|
/* SEF functions and variables. */
|
|
static void sef_local_startup(void);
|
|
static int sef_cb_init_fresh(int type, sef_init_info_t *info);
|
|
static void sef_cb_signal_handler(int signo);
|
|
EXTERN int sef_cb_lu_prepare(int state);
|
|
EXTERN int sef_cb_lu_state_isvalid(int state);
|
|
EXTERN void sef_cb_lu_state_dump(int state);
|
|
int last_was_write;
|
|
|
|
/*===========================================================================*
|
|
* floppy_task *
|
|
*===========================================================================*/
|
|
int main(void)
|
|
{
|
|
/* SEF local startup. */
|
|
sef_local_startup();
|
|
|
|
/* Call the generic receive loop. */
|
|
blockdriver_task(&f_dtab);
|
|
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* sef_local_startup *
|
|
*===========================================================================*/
|
|
static void sef_local_startup(void)
|
|
{
|
|
/* Register init callbacks. */
|
|
sef_setcb_init_fresh(sef_cb_init_fresh);
|
|
sef_setcb_init_lu(sef_cb_init_fresh);
|
|
|
|
/* Register live update callbacks. */
|
|
sef_setcb_lu_prepare(sef_cb_lu_prepare);
|
|
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid);
|
|
sef_setcb_lu_state_dump(sef_cb_lu_state_dump);
|
|
|
|
/* Register signal callbacks. */
|
|
sef_setcb_signal_handler(sef_cb_signal_handler);
|
|
|
|
/* Let SEF perform startup. */
|
|
sef_startup();
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* sef_cb_init_fresh *
|
|
*===========================================================================*/
|
|
static int sef_cb_init_fresh(int type, sef_init_info_t *UNUSED(info))
|
|
{
|
|
/* Initialize the floppy driver. */
|
|
struct floppy *fp;
|
|
int s;
|
|
|
|
/* Initialize the floppy structure and the timers. */
|
|
system_hz = sys_hz();
|
|
|
|
if(!(floppy_buf = alloc_contig(2*DMA_BUF_SIZE,
|
|
AC_LOWER16M | AC_ALIGN4K, &floppy_buf_phys)))
|
|
panic("couldn't allocate dma buffer");
|
|
|
|
init_timer(&f_tmr_timeout);
|
|
|
|
for (fp = &floppy[0]; fp < &floppy[NR_DRIVES]; fp++) {
|
|
fp->fl_curcyl = NO_CYL;
|
|
fp->fl_density = NO_DENS;
|
|
fp->fl_class = ~0;
|
|
init_timer(&fp->fl_tmr_stop);
|
|
}
|
|
|
|
/* Set IRQ policy, only request notifications, do not automatically
|
|
* reenable interrupts. ID return on interrupt is the IRQ line number.
|
|
*/
|
|
irq_hook_id = FLOPPY_IRQ;
|
|
if ((s=sys_irqsetpolicy(FLOPPY_IRQ, 0, &irq_hook_id )) != OK)
|
|
panic("Couldn't set IRQ policy: %d", s);
|
|
if ((s=sys_irqenable(&irq_hook_id)) != OK)
|
|
panic("Couldn't enable IRQs: %d", s);
|
|
|
|
/* Announce we are up! */
|
|
blockdriver_announce(type);
|
|
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* sef_cb_signal_handler *
|
|
*===========================================================================*/
|
|
static void sef_cb_signal_handler(int signo)
|
|
{
|
|
int s;
|
|
|
|
/* Only check for termination signal, ignore anything else. */
|
|
if (signo != SIGTERM) return;
|
|
|
|
/* Stop all activity and cleanly exit with the system. */
|
|
if ((s=sys_outb(DOR, ENABLE_INT)) != OK)
|
|
panic("Sys_outb failed: %d", s);
|
|
exit(0);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_expire_tmrs *
|
|
*===========================================================================*/
|
|
static void f_expire_tmrs(clock_t stamp)
|
|
{
|
|
/* A synchronous alarm message was received. Call the watchdog function for
|
|
* each expired timer, if any.
|
|
*/
|
|
|
|
expire_timers(stamp);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_prepare *
|
|
*===========================================================================*/
|
|
static struct device *f_prepare(devminor_t device)
|
|
{
|
|
/* Prepare for I/O on a device. */
|
|
|
|
f_device = device;
|
|
f_drive = device & ~(DEV_TYPE_BITS | FORMAT_DEV_BIT);
|
|
if (device < 0 || f_drive >= NR_DRIVES) return(NULL);
|
|
|
|
f_fp = &floppy[f_drive];
|
|
f_dv = &f_fp->fl_geom;
|
|
if (f_fp->fl_density < NT) {
|
|
f_dp = &fdensity[f_fp->fl_density];
|
|
f_sectors = f_dp->secpt;
|
|
f_fp->fl_geom.dv_size = mul64u((long) (NR_HEADS * f_sectors
|
|
* f_dp->cyls), SECTOR_SIZE);
|
|
}
|
|
|
|
/* A partition? */
|
|
if ((device &= DEV_TYPE_BITS) >= MINOR_fd0p0)
|
|
f_dv = &f_fp->fl_part[(device - MINOR_fd0p0) >> DEV_TYPE_SHIFT];
|
|
|
|
return f_dv;
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_part *
|
|
*===========================================================================*/
|
|
static struct device *f_part(devminor_t minor)
|
|
{
|
|
/* Return a pointer to the partition information of the given minor device. */
|
|
|
|
return f_prepare(minor);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_cleanup *
|
|
*===========================================================================*/
|
|
static void f_cleanup(void)
|
|
{
|
|
/* Start a timer to turn the motor off in a few seconds. */
|
|
set_timer(&f_fp->fl_tmr_stop, MOTOR_OFF, stop_motor, f_drive);
|
|
|
|
/* Exiting the floppy driver, so forget where we are. */
|
|
f_fp->fl_sector = NO_SECTOR;
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_transfer *
|
|
*===========================================================================*/
|
|
static ssize_t f_transfer(
|
|
devminor_t minor, /* minor device number */
|
|
int do_write, /* read or write? */
|
|
u64_t pos64, /* offset on device to read or write */
|
|
endpoint_t proc_nr, /* process doing the request */
|
|
iovec_t *iov, /* pointer to read or write request vector */
|
|
unsigned int nr_req, /* length of request vector */
|
|
int UNUSED(flags) /* transfer flags */
|
|
)
|
|
{
|
|
#define NO_OFFSET -1
|
|
struct floppy *fp;
|
|
iovec_t *iop, *iov_end = iov + nr_req;
|
|
int s, r, errors, nr;
|
|
unsigned block, nbytes, count, chunk, sector;
|
|
u64_t dv_size;
|
|
vir_bytes user_offset, iov_offset = 0, iop_offset;
|
|
unsigned long position;
|
|
signed long uoffsets[MAX_SECTORS], *up;
|
|
cp_grant_id_t ugrants[MAX_SECTORS], *ug = NULL;
|
|
u8_t cmd[3];
|
|
ssize_t total;
|
|
|
|
if (f_prepare(minor) == NULL) return(ENXIO);
|
|
|
|
fp = f_fp;
|
|
dv_size = f_dv->dv_size;
|
|
|
|
if (ex64hi(pos64) != 0)
|
|
return OK; /* Way beyond EOF */
|
|
position= pos64;
|
|
total = 0;
|
|
|
|
/* Record the direction of the last transfer performed. */
|
|
last_was_write = do_write;
|
|
|
|
/* Check disk address. */
|
|
if ((position & SECTOR_MASK) != 0) return(EINVAL);
|
|
|
|
#if 0 /* XXX hack to create a disk driver that crashes */
|
|
{ static int count= 0; if (++count > 10) {
|
|
printf("floppy: time to die\n"); *(int *)-1= 42;
|
|
}}
|
|
#endif
|
|
|
|
errors = 0;
|
|
while (nr_req > 0) {
|
|
/* How many bytes to transfer? */
|
|
nbytes = 0;
|
|
for (iop = iov; iop < iov_end; iop++) nbytes += iop->iov_size;
|
|
|
|
/* Which block on disk and how close to EOF? */
|
|
if (position >= dv_size) return(total); /* At EOF */
|
|
if (position + nbytes > dv_size) nbytes = dv_size - position;
|
|
block = div64u(add64ul(f_dv->dv_base, position), SECTOR_SIZE);
|
|
|
|
if ((nbytes & SECTOR_MASK) != 0) return(EINVAL);
|
|
|
|
/* Using a formatting device? */
|
|
if (f_device & FORMAT_DEV_BIT) {
|
|
if (!do_write) return(EIO);
|
|
if (iov->iov_size < SECTOR_SIZE + sizeof(fmt_param))
|
|
return(EINVAL);
|
|
|
|
if(proc_nr != SELF) {
|
|
s=sys_safecopyfrom(proc_nr, iov->iov_addr,
|
|
SECTOR_SIZE + iov_offset, (vir_bytes) &fmt_param,
|
|
(phys_bytes) sizeof(fmt_param));
|
|
if(s != OK)
|
|
panic("sys_safecopyfrom failed: %d", s);
|
|
} else {
|
|
memcpy(&fmt_param, (void *) (iov->iov_addr +
|
|
SECTOR_SIZE + iov_offset),
|
|
(phys_bytes) sizeof(fmt_param));
|
|
}
|
|
|
|
/* Check that the number of sectors in the data is reasonable,
|
|
* to avoid division by 0. Leave checking of other data to
|
|
* the FDC.
|
|
*/
|
|
if (fmt_param.sectors_per_cylinder == 0) return(EIO);
|
|
|
|
/* Only the first sector of the parameters now needed. */
|
|
iov->iov_size = nbytes = SECTOR_SIZE;
|
|
}
|
|
|
|
/* Only try one sector if there were errors. */
|
|
if (errors > 0) nbytes = SECTOR_SIZE;
|
|
|
|
/* Compute cylinder and head of the track to access. */
|
|
fp->fl_cylinder = block / (NR_HEADS * f_sectors);
|
|
fp->fl_hardcyl = fp->fl_cylinder * f_dp->steps;
|
|
fp->fl_head = (block % (NR_HEADS * f_sectors)) / f_sectors;
|
|
|
|
/* For each sector on this track compute the user address it is to
|
|
* go or to come from.
|
|
*/
|
|
for (up = uoffsets; up < uoffsets + MAX_SECTORS; up++) *up = NO_OFFSET;
|
|
count = 0;
|
|
iop = iov;
|
|
sector = block % f_sectors;
|
|
nr = 0;
|
|
iop_offset = iov_offset;
|
|
for (;;) {
|
|
nr++;
|
|
user_offset = iop_offset;
|
|
chunk = iop->iov_size;
|
|
if ((chunk & SECTOR_MASK) != 0) return(EINVAL);
|
|
|
|
while (chunk > 0) {
|
|
ugrants[sector] = iop->iov_addr;
|
|
uoffsets[sector++] = user_offset;
|
|
chunk -= SECTOR_SIZE;
|
|
user_offset += SECTOR_SIZE;
|
|
count += SECTOR_SIZE;
|
|
if (sector == f_sectors || count == nbytes)
|
|
goto track_set_up;
|
|
}
|
|
iop_offset = 0;
|
|
iop++;
|
|
}
|
|
track_set_up:
|
|
|
|
/* First check to see if a reset is needed. */
|
|
if (need_reset) f_reset();
|
|
|
|
/* See if motor is running; if not, turn it on and wait. */
|
|
start_motor();
|
|
|
|
/* Set the stepping rate and data rate */
|
|
if (f_dp != prev_dp) {
|
|
cmd[0] = FDC_SPECIFY;
|
|
cmd[1] = f_dp->spec1;
|
|
cmd[2] = SPEC2;
|
|
(void) fdc_command(cmd, 3);
|
|
if ((s=sys_outb(FDC_RATE, f_dp->rate)) != OK)
|
|
panic("Sys_outb failed: %d", s);
|
|
prev_dp = f_dp;
|
|
}
|
|
|
|
/* If we are going to a new cylinder, perform a seek. */
|
|
r = seek();
|
|
|
|
/* Avoid read_id() if we don't plan to read much. */
|
|
if (fp->fl_sector == NO_SECTOR && count < (6 * SECTOR_SIZE))
|
|
fp->fl_sector = 0;
|
|
|
|
for (nbytes = 0; nbytes < count; nbytes += SECTOR_SIZE) {
|
|
if (fp->fl_sector == NO_SECTOR) {
|
|
/* Find out what the current sector is. This often
|
|
* fails right after a seek, so try it twice.
|
|
*/
|
|
if (r == OK && read_id() != OK) r = read_id();
|
|
}
|
|
|
|
/* Look for the next job in uoffsets[] */
|
|
if (r == OK) {
|
|
for (;;) {
|
|
if (fp->fl_sector >= f_sectors)
|
|
fp->fl_sector = 0;
|
|
|
|
up = &uoffsets[fp->fl_sector];
|
|
ug = &ugrants[fp->fl_sector];
|
|
if (*up != NO_OFFSET) break;
|
|
fp->fl_sector++;
|
|
}
|
|
|
|
if (do_write) {
|
|
/* Copy the user bytes to the DMA buffer. */
|
|
if(proc_nr != SELF) {
|
|
s=sys_safecopyfrom(proc_nr, *ug, *up,
|
|
(vir_bytes) floppy_buf,
|
|
(phys_bytes) SECTOR_SIZE);
|
|
if(s != OK)
|
|
panic("sys_safecopyfrom failed: %d", s);
|
|
} else {
|
|
memcpy(floppy_buf, (void *) (*ug + *up), SECTOR_SIZE);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Set up the DMA chip and perform the transfer. */
|
|
if (r == OK) {
|
|
if (dma_setup(do_write) != OK) {
|
|
/* This can only fail for addresses above 16MB
|
|
* that cannot be handled by the controller,
|
|
* because it uses 24-bit addressing.
|
|
*/
|
|
return(EIO);
|
|
}
|
|
r = fdc_transfer(do_write);
|
|
}
|
|
|
|
if (r == OK && !do_write) {
|
|
/* Copy the DMA buffer to user space. */
|
|
if(proc_nr != SELF) {
|
|
s=sys_safecopyto(proc_nr, *ug, *up,
|
|
(vir_bytes) floppy_buf,
|
|
(phys_bytes) SECTOR_SIZE);
|
|
if(s != OK)
|
|
panic("sys_safecopyto failed: %d", s);
|
|
} else {
|
|
memcpy((void *) (*ug + *up), floppy_buf, SECTOR_SIZE);
|
|
}
|
|
}
|
|
|
|
if (r != OK) {
|
|
/* Don't retry if write protected or too many errors. */
|
|
if (err_no_retry(r) || ++errors == MAX_ERRORS) {
|
|
return(EIO);
|
|
}
|
|
|
|
/* Recalibrate if halfway. */
|
|
if (errors == MAX_ERRORS / 2)
|
|
fp->fl_calibration = UNCALIBRATED;
|
|
|
|
nbytes = 0;
|
|
break; /* retry */
|
|
}
|
|
}
|
|
|
|
/* Book the bytes successfully transferred. */
|
|
position += nbytes;
|
|
total += nbytes;
|
|
while (nbytes > 0) {
|
|
if (nbytes < iov->iov_size) {
|
|
/* Not done with this one yet. */
|
|
iov_offset += nbytes;
|
|
iov->iov_size -= nbytes;
|
|
break;
|
|
}
|
|
iov_offset = 0;
|
|
nbytes -= iov->iov_size;
|
|
iov->iov_size = 0;
|
|
iov++;
|
|
nr_req--;
|
|
}
|
|
}
|
|
return(total);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* dma_setup *
|
|
*===========================================================================*/
|
|
static int dma_setup(int do_write)
|
|
{
|
|
/* The IBM PC can perform DMA operations by using the DMA chip. To use it,
|
|
* the DMA (Direct Memory Access) chip is loaded with the 20-bit memory address
|
|
* to be read from or written to, the byte count minus 1, and a read or write
|
|
* opcode. This routine sets up the DMA chip. Note that the chip is not
|
|
* capable of doing a DMA across a 64K boundary (e.g., you can't read a
|
|
* 512-byte block starting at physical address 65520).
|
|
*
|
|
* Warning! Also note that it's not possible to do DMA above 16 MB because
|
|
* the ISA bus uses 24-bit addresses. Addresses above 16 MB therefore will
|
|
* be interpreted modulo 16 MB, dangerously overwriting arbitrary memory.
|
|
* A check here denies the I/O if the address is out of range.
|
|
*/
|
|
pvb_pair_t byte_out[9];
|
|
int s;
|
|
|
|
/* First check the DMA memory address not to exceed maximum. */
|
|
if (floppy_buf_phys != (floppy_buf_phys & DMA_ADDR_MASK)) {
|
|
printf("floppy: DMA denied because address out of range\n");
|
|
return(EIO);
|
|
}
|
|
|
|
/* Set up the DMA registers. (The comment on the reset is a bit strong,
|
|
* it probably only resets the floppy channel.)
|
|
*/
|
|
pv_set(byte_out[0], DMA_INIT, DMA_RESET_VAL); /* reset the dma controller */
|
|
pv_set(byte_out[1], DMA_FLIPFLOP, 0); /* write anything to reset it */
|
|
pv_set(byte_out[2], DMA_MODE, do_write ? DMA_WRITE : DMA_READ);
|
|
pv_set(byte_out[3], DMA_ADDR, (unsigned) (floppy_buf_phys >> 0) & 0xff);
|
|
pv_set(byte_out[4], DMA_ADDR, (unsigned) (floppy_buf_phys >> 8) & 0xff);
|
|
pv_set(byte_out[5], DMA_TOP, (unsigned) (floppy_buf_phys >> 16) & 0xff);
|
|
pv_set(byte_out[6], DMA_COUNT, (((SECTOR_SIZE - 1) >> 0)) & 0xff);
|
|
pv_set(byte_out[7], DMA_COUNT, (SECTOR_SIZE - 1) >> 8);
|
|
pv_set(byte_out[8], DMA_INIT, 2); /* some sort of enable */
|
|
|
|
if ((s=sys_voutb(byte_out, 9)) != OK)
|
|
panic("Sys_voutb in dma_setup() failed: %d", s);
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* start_motor *
|
|
*===========================================================================*/
|
|
static void start_motor(void)
|
|
{
|
|
/* Control of the floppy disk motors is a big pain. If a motor is off, you
|
|
* have to turn it on first, which takes 1/2 second. You can't leave it on
|
|
* all the time, since that would wear out the diskette. However, if you turn
|
|
* the motor off after each operation, the system performance will be awful.
|
|
* The compromise used here is to leave it on for a few seconds after each
|
|
* operation. If a new operation is started in that interval, it need not be
|
|
* turned on again. If no new operation is started, a timer goes off and the
|
|
* motor is turned off. I/O port DOR has bits to control each of 4 drives.
|
|
*/
|
|
|
|
int s, motor_bit, running;
|
|
message mess;
|
|
int ipc_status;
|
|
|
|
motor_bit = 1 << f_drive; /* bit mask for this drive */
|
|
running = motor_status & motor_bit; /* nonzero if this motor is running */
|
|
motor_status |= motor_bit; /* want this drive running too */
|
|
|
|
if ((s=sys_outb(DOR,
|
|
(motor_status << MOTOR_SHIFT) | ENABLE_INT | f_drive)) != OK)
|
|
panic("Sys_outb in start_motor() failed: %d", s);
|
|
|
|
/* If the motor was already running, we don't have to wait for it. */
|
|
if (running) return; /* motor was already running */
|
|
|
|
/* Set an alarm timer to force a timeout if the hardware does not interrupt
|
|
* in time. Expect an interrupt, but check for a timeout.
|
|
*/
|
|
set_timer(&f_tmr_timeout, f_dp->start_ms * system_hz / 1000, f_timeout, 0);
|
|
f_busy = BSY_IO;
|
|
do {
|
|
if ((s = driver_receive(ANY, &mess, &ipc_status)) != OK)
|
|
panic("Couldn't receive message: %d", s);
|
|
|
|
if (is_ipc_notify(ipc_status)) {
|
|
switch (_ENDPOINT_P(mess.m_source)) {
|
|
case CLOCK:
|
|
f_expire_tmrs(mess.NOTIFY_TIMESTAMP);
|
|
break;
|
|
default :
|
|
f_busy = BSY_IDLE;
|
|
break;
|
|
}
|
|
} else {
|
|
f_busy = BSY_IDLE;
|
|
}
|
|
} while (f_busy == BSY_IO);
|
|
f_fp->fl_sector = NO_SECTOR;
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* stop_motor *
|
|
*===========================================================================*/
|
|
static void stop_motor(minix_timer_t *tp)
|
|
{
|
|
/* This routine is called from an alarm timer after several seconds have
|
|
* elapsed with no floppy disk activity. It turns the drive motor off.
|
|
*/
|
|
int s;
|
|
motor_status &= ~(1 << tmr_arg(tp)->ta_int);
|
|
if ((s=sys_outb(DOR, (motor_status << MOTOR_SHIFT) | ENABLE_INT)) != OK)
|
|
panic("Sys_outb in stop_motor() failed: %d", s);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* seek *
|
|
*===========================================================================*/
|
|
static int seek(void)
|
|
{
|
|
/* Issue a SEEK command on the indicated drive unless the arm is already
|
|
* positioned on the correct cylinder.
|
|
*/
|
|
|
|
struct floppy *fp = f_fp;
|
|
int r;
|
|
message mess;
|
|
int ipc_status;
|
|
u8_t cmd[3];
|
|
|
|
/* Are we already on the correct cylinder? */
|
|
if (fp->fl_calibration == UNCALIBRATED)
|
|
if (recalibrate() != OK) return(ERR_SEEK);
|
|
if (fp->fl_curcyl == fp->fl_hardcyl) return(OK);
|
|
|
|
/* No. Wrong cylinder. Issue a SEEK and wait for interrupt. */
|
|
cmd[0] = FDC_SEEK;
|
|
cmd[1] = (fp->fl_head << 2) | f_drive;
|
|
cmd[2] = fp->fl_hardcyl;
|
|
if (fdc_command(cmd, 3) != OK) return(ERR_SEEK);
|
|
if (f_intr_wait() != OK) return(ERR_TIMEOUT);
|
|
|
|
/* Interrupt has been received. Check drive status. */
|
|
fdc_out(FDC_SENSE); /* probe FDC to make it return status */
|
|
r = fdc_results(); /* get controller status bytes */
|
|
if (r != OK || (f_results[ST0] & ST0_BITS_SEEK) != SEEK_ST0
|
|
|| f_results[ST1] != fp->fl_hardcyl) {
|
|
/* seek failed, may need a recalibrate */
|
|
return(ERR_SEEK);
|
|
}
|
|
/* Give head time to settle on a format, no retrying here! */
|
|
if (f_device & FORMAT_DEV_BIT) {
|
|
/* Set a synchronous alarm to force a timeout if the hardware does
|
|
* not interrupt.
|
|
*/
|
|
set_timer(&f_tmr_timeout, system_hz/30, f_timeout, 0);
|
|
f_busy = BSY_IO;
|
|
do {
|
|
if ((r = driver_receive(ANY, &mess, &ipc_status)) != OK)
|
|
panic("Couldn't receive message: %d", r);
|
|
|
|
if (is_ipc_notify(ipc_status)) {
|
|
switch (_ENDPOINT_P(mess.m_source)) {
|
|
case CLOCK:
|
|
f_expire_tmrs(mess.NOTIFY_TIMESTAMP);
|
|
break;
|
|
default :
|
|
f_busy = BSY_IDLE;
|
|
break;
|
|
}
|
|
} else {
|
|
f_busy = BSY_IDLE;
|
|
}
|
|
} while (f_busy == BSY_IO);
|
|
}
|
|
fp->fl_curcyl = fp->fl_hardcyl;
|
|
fp->fl_sector = NO_SECTOR;
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* fdc_transfer *
|
|
*===========================================================================*/
|
|
static int fdc_transfer(int do_write)
|
|
{
|
|
/* The drive is now on the proper cylinder. Read, write or format 1 block. */
|
|
|
|
struct floppy *fp = f_fp;
|
|
int r, s;
|
|
u8_t cmd[9];
|
|
|
|
/* Never attempt a transfer if the drive is uncalibrated or motor is off. */
|
|
if (fp->fl_calibration == UNCALIBRATED) return(ERR_TRANSFER);
|
|
if ((motor_status & (1 << f_drive)) == 0) return(ERR_TRANSFER);
|
|
|
|
/* The command is issued by outputting several bytes to the controller chip.
|
|
*/
|
|
if (f_device & FORMAT_DEV_BIT) {
|
|
cmd[0] = FDC_FORMAT;
|
|
cmd[1] = (fp->fl_head << 2) | f_drive;
|
|
cmd[2] = fmt_param.sector_size_code;
|
|
cmd[3] = fmt_param.sectors_per_cylinder;
|
|
cmd[4] = fmt_param.gap_length_for_format;
|
|
cmd[5] = fmt_param.fill_byte_for_format;
|
|
if (fdc_command(cmd, 6) != OK) return(ERR_TRANSFER);
|
|
} else {
|
|
cmd[0] = do_write ? FDC_WRITE : FDC_READ;
|
|
cmd[1] = (fp->fl_head << 2) | f_drive;
|
|
cmd[2] = fp->fl_cylinder;
|
|
cmd[3] = fp->fl_head;
|
|
cmd[4] = BASE_SECTOR + fp->fl_sector;
|
|
cmd[5] = SECTOR_SIZE_CODE;
|
|
cmd[6] = f_sectors;
|
|
cmd[7] = f_dp->gap; /* sector gap */
|
|
cmd[8] = DTL; /* data length */
|
|
if (fdc_command(cmd, 9) != OK) return(ERR_TRANSFER);
|
|
}
|
|
|
|
/* Block, waiting for disk interrupt. */
|
|
if (f_intr_wait() != OK) {
|
|
printf("fd%u: disk interrupt timed out.\n", f_drive);
|
|
return(ERR_TIMEOUT);
|
|
}
|
|
|
|
/* Get controller status and check for errors. */
|
|
r = fdc_results();
|
|
if (r != OK) return(r);
|
|
|
|
if (f_results[ST1] & WRITE_PROTECT) {
|
|
printf("fd%u: diskette is write protected.\n", f_drive);
|
|
return(ERR_WR_PROTECT);
|
|
}
|
|
|
|
if ((f_results[ST0] & ST0_BITS_TRANS) != TRANS_ST0) return(ERR_TRANSFER);
|
|
if (f_results[ST1] | f_results[ST2]) return(ERR_TRANSFER);
|
|
|
|
if (f_device & FORMAT_DEV_BIT) return(OK);
|
|
|
|
/* Compare actual numbers of sectors transferred with expected number. */
|
|
s = (f_results[ST_CYL] - fp->fl_cylinder) * NR_HEADS * f_sectors;
|
|
s += (f_results[ST_HEAD] - fp->fl_head) * f_sectors;
|
|
s += (f_results[ST_SEC] - BASE_SECTOR - fp->fl_sector);
|
|
if (s != 1) return(ERR_TRANSFER);
|
|
|
|
/* This sector is next for I/O: */
|
|
fp->fl_sector = f_results[ST_SEC] - BASE_SECTOR;
|
|
#if 0
|
|
if (processor < 386) fp->fl_sector++; /* Old CPU can't keep up. */
|
|
#endif
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* fdc_results *
|
|
*===========================================================================*/
|
|
static int fdc_results(void)
|
|
{
|
|
/* Extract results from the controller after an operation, then allow floppy
|
|
* interrupts again.
|
|
*/
|
|
|
|
int s, result_nr;
|
|
u32_t status;
|
|
spin_t spin;
|
|
|
|
/* Extract bytes from FDC until it says it has no more. The loop is
|
|
* really an outer loop on result_nr and an inner loop on status.
|
|
* A timeout flag alarm is set.
|
|
*/
|
|
result_nr = 0;
|
|
SPIN_FOR(&spin, TIMEOUT_MICROS) {
|
|
/* Reading one byte is almost a mirror of fdc_out() - the DIRECTION
|
|
* bit must be set instead of clear, but the CTL_BUSY bit destroys
|
|
* the perfection of the mirror.
|
|
*/
|
|
if ((s=sys_inb(FDC_STATUS, &status)) != OK)
|
|
panic("Sys_inb in fdc_results() failed: %d", s);
|
|
status &= (MASTER | DIRECTION | CTL_BUSY);
|
|
if (status == (MASTER | DIRECTION | CTL_BUSY)) {
|
|
u32_t tmp_r;
|
|
if (result_nr >= MAX_RESULTS) break; /* too many results */
|
|
if ((s=sys_inb(FDC_DATA, &tmp_r)) != OK)
|
|
panic("Sys_inb in fdc_results() failed: %d", s);
|
|
f_results[result_nr] = tmp_r;
|
|
result_nr ++;
|
|
continue;
|
|
}
|
|
if (status == MASTER) { /* all read */
|
|
if ((s=sys_irqenable(&irq_hook_id)) != OK)
|
|
panic("Couldn't enable IRQs: %d", s);
|
|
|
|
return(OK); /* only good exit */
|
|
}
|
|
}
|
|
need_reset = TRUE; /* controller chip must be reset */
|
|
|
|
if ((s=sys_irqenable(&irq_hook_id)) != OK)
|
|
panic("Couldn't enable IRQs: %d", s);
|
|
return(ERR_STATUS);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* fdc_command *
|
|
*===========================================================================*/
|
|
static int fdc_command(
|
|
const u8_t *cmd, /* command bytes */
|
|
int len /* command length */
|
|
)
|
|
{
|
|
/* Output a command to the controller. */
|
|
|
|
/* Set a synchronous alarm to force a timeout if the hardware does
|
|
* not interrupt.
|
|
* Note that the actual check is done by the code that issued the
|
|
* fdc_command() call.
|
|
*/
|
|
set_timer(&f_tmr_timeout, WAKEUP, f_timeout, 0);
|
|
|
|
f_busy = BSY_IO;
|
|
while (len > 0) {
|
|
fdc_out(*cmd++);
|
|
len--;
|
|
}
|
|
return(need_reset ? ERR_DRIVE : OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* fdc_out *
|
|
*===========================================================================*/
|
|
static void fdc_out(
|
|
int val /* write this byte to floppy disk controller */
|
|
)
|
|
{
|
|
/* Output a byte to the controller. This is not entirely trivial, since you
|
|
* can only write to it when it is listening, and it decides when to listen.
|
|
* If the controller refuses to listen, the FDC chip is given a hard reset.
|
|
*/
|
|
spin_t spin;
|
|
int s;
|
|
u32_t status;
|
|
|
|
if (need_reset) return; /* if controller is not listening, return */
|
|
|
|
/* It may take several tries to get the FDC to accept a command. */
|
|
SPIN_FOR(&spin, TIMEOUT_MICROS) {
|
|
if ((s=sys_inb(FDC_STATUS, &status)) != OK)
|
|
panic("Sys_inb in fdc_out() failed: %d", s);
|
|
|
|
if ((status & (MASTER | DIRECTION)) == (MASTER | 0)) {
|
|
if ((s=sys_outb(FDC_DATA, val)) != OK)
|
|
panic("Sys_outb in fdc_out() failed: %d", s);
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
need_reset = TRUE; /* hit it over the head */
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* recalibrate *
|
|
*===========================================================================*/
|
|
static int recalibrate(void)
|
|
{
|
|
/* The floppy disk controller has no way of determining its absolute arm
|
|
* position (cylinder). Instead, it steps the arm a cylinder at a time and
|
|
* keeps track of where it thinks it is (in software). However, after a
|
|
* SEEK, the hardware reads information from the diskette telling where the
|
|
* arm actually is. If the arm is in the wrong place, a recalibration is done,
|
|
* which forces the arm to cylinder 0. This way the controller can get back
|
|
* into sync with reality.
|
|
*/
|
|
|
|
struct floppy *fp = f_fp;
|
|
int r;
|
|
u8_t cmd[2];
|
|
|
|
/* Issue the RECALIBRATE command and wait for the interrupt. */
|
|
cmd[0] = FDC_RECALIBRATE; /* tell drive to recalibrate itself */
|
|
cmd[1] = f_drive; /* specify drive */
|
|
if (fdc_command(cmd, 2) != OK) return(ERR_SEEK);
|
|
if (f_intr_wait() != OK) return(ERR_TIMEOUT);
|
|
|
|
/* Determine if the recalibration succeeded. */
|
|
fdc_out(FDC_SENSE); /* issue SENSE command to request results */
|
|
r = fdc_results(); /* get results of the FDC_RECALIBRATE command*/
|
|
fp->fl_curcyl = NO_CYL; /* force a SEEK next time */
|
|
fp->fl_sector = NO_SECTOR;
|
|
if (r != OK || /* controller would not respond */
|
|
(f_results[ST0] & ST0_BITS_SEEK) != SEEK_ST0 || f_results[ST_PCN] != 0) {
|
|
/* Recalibration failed. FDC must be reset. */
|
|
need_reset = TRUE;
|
|
return(ERR_RECALIBRATE);
|
|
} else {
|
|
/* Recalibration succeeded. */
|
|
fp->fl_calibration = CALIBRATED;
|
|
fp->fl_curcyl = f_results[ST_PCN];
|
|
return(OK);
|
|
}
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_reset *
|
|
*===========================================================================*/
|
|
static void f_reset(void)
|
|
{
|
|
/* Issue a reset to the controller. This is done after any catastrophe,
|
|
* like the controller refusing to respond.
|
|
*/
|
|
pvb_pair_t byte_out[2];
|
|
int s,i;
|
|
message mess;
|
|
int ipc_status;
|
|
|
|
/* Disable interrupts and strobe reset bit low. */
|
|
need_reset = FALSE;
|
|
|
|
/* It is not clear why the next lock is needed. Writing 0 to DOR causes
|
|
* interrupt, while the PC documentation says turning bit 8 off disables
|
|
* interrupts. Without the lock:
|
|
* 1) the interrupt handler sets the floppy mask bit in the 8259.
|
|
* 2) writing ENABLE_INT to DOR causes the FDC to assert the interrupt
|
|
* line again, but the mask stops the cpu being interrupted.
|
|
* 3) the sense interrupt clears the interrupt (not clear which one).
|
|
* and for some reason the reset does not work.
|
|
*/
|
|
(void) fdc_command((u8_t *) 0, 0); /* need only the timer */
|
|
motor_status = 0;
|
|
pv_set(byte_out[0], DOR, 0); /* strobe reset bit low */
|
|
pv_set(byte_out[1], DOR, ENABLE_INT); /* strobe it high again */
|
|
if ((s=sys_voutb(byte_out, 2)) != OK)
|
|
panic("Sys_voutb in f_reset() failed: %d", s);
|
|
|
|
/* A synchronous alarm timer was set in fdc_command. Expect an interrupt,
|
|
* but be prepared to handle a timeout.
|
|
*/
|
|
do {
|
|
if ((s = driver_receive(ANY, &mess, &ipc_status)) != OK)
|
|
panic("Couldn't receive message: %d", s);
|
|
if (is_ipc_notify(ipc_status)) {
|
|
switch (_ENDPOINT_P(mess.m_source)) {
|
|
case CLOCK:
|
|
f_expire_tmrs(mess.NOTIFY_TIMESTAMP);
|
|
break;
|
|
default :
|
|
f_busy = BSY_IDLE;
|
|
break;
|
|
}
|
|
} else { /* expect hw interrupt */
|
|
f_busy = BSY_IDLE;
|
|
}
|
|
} while (f_busy == BSY_IO);
|
|
|
|
/* The controller supports 4 drives and returns a result for each of them.
|
|
* Collect all the results now. The old version only collected the first
|
|
* result. This happens to work for 2 drives, but it doesn't work for 3
|
|
* or more drives, at least with only drives 0 and 2 actually connected
|
|
* (the controller generates an extra interrupt for the middle drive when
|
|
* drive 2 is accessed and the driver panics).
|
|
*
|
|
* It would be better to keep collecting results until there are no more.
|
|
* For this, fdc_results needs to return the number of results (instead
|
|
* of OK) when it succeeds.
|
|
*/
|
|
for (i = 0; i < 4; i++) {
|
|
fdc_out(FDC_SENSE); /* probe FDC to make it return status */
|
|
(void) fdc_results(); /* flush controller */
|
|
}
|
|
for (i = 0; i < NR_DRIVES; i++) /* clear each drive */
|
|
floppy[i].fl_calibration = UNCALIBRATED;
|
|
|
|
/* The current timing parameters must be specified again. */
|
|
prev_dp = NULL;
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_intr_wait *
|
|
*===========================================================================*/
|
|
static int f_intr_wait(void)
|
|
{
|
|
/* Wait for an interrupt, but not forever. The FDC may have all the time of
|
|
* the world, but we humans do not.
|
|
*/
|
|
message mess;
|
|
int r, ipc_status;
|
|
|
|
/* We expect an interrupt, but if a timeout, occurs, report an error. */
|
|
do {
|
|
if ((r = driver_receive(ANY, &mess, &ipc_status)) != OK)
|
|
panic("Couldn't receive message: %d", r);
|
|
if (is_ipc_notify(ipc_status)) {
|
|
switch (_ENDPOINT_P(mess.m_source)) {
|
|
case CLOCK:
|
|
f_expire_tmrs(mess.NOTIFY_TIMESTAMP);
|
|
break;
|
|
default :
|
|
f_busy = BSY_IDLE;
|
|
break;
|
|
}
|
|
} else {
|
|
f_busy = BSY_IDLE;
|
|
}
|
|
} while (f_busy == BSY_IO);
|
|
|
|
if (f_busy == BSY_WAKEN) {
|
|
|
|
/* No interrupt from the FDC, this means that there is probably no
|
|
* floppy in the drive. Get the FDC down to earth and return error.
|
|
*/
|
|
need_reset = TRUE;
|
|
return(ERR_TIMEOUT);
|
|
}
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_timeout *
|
|
*===========================================================================*/
|
|
static void f_timeout(minix_timer_t *UNUSED(tp))
|
|
{
|
|
/* This routine is called when a timer expires. Usually to tell that a
|
|
* motor has spun up, but also to forge an interrupt when it takes too long
|
|
* for the FDC to interrupt (no floppy in the drive). It sets a flag to tell
|
|
* what has happened.
|
|
*/
|
|
if (f_busy == BSY_IO) {
|
|
f_busy = BSY_WAKEN;
|
|
}
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* read_id *
|
|
*===========================================================================*/
|
|
static int read_id(void)
|
|
{
|
|
/* Determine current cylinder and sector. */
|
|
|
|
struct floppy *fp = f_fp;
|
|
int result;
|
|
u8_t cmd[2];
|
|
|
|
/* Never attempt a read id if the drive is uncalibrated or motor is off. */
|
|
if (fp->fl_calibration == UNCALIBRATED) return(ERR_READ_ID);
|
|
if ((motor_status & (1 << f_drive)) == 0) return(ERR_READ_ID);
|
|
|
|
/* The command is issued by outputting 2 bytes to the controller chip. */
|
|
cmd[0] = FDC_READ_ID; /* issue the read id command */
|
|
cmd[1] = (fp->fl_head << 2) | f_drive;
|
|
if (fdc_command(cmd, 2) != OK) return(ERR_READ_ID);
|
|
if (f_intr_wait() != OK) return(ERR_TIMEOUT);
|
|
|
|
/* Get controller status and check for errors. */
|
|
result = fdc_results();
|
|
if (result != OK) return(result);
|
|
|
|
if ((f_results[ST0] & ST0_BITS_TRANS) != TRANS_ST0) return(ERR_READ_ID);
|
|
if (f_results[ST1] | f_results[ST2]) return(ERR_READ_ID);
|
|
|
|
/* The next sector is next for I/O: */
|
|
fp->fl_sector = f_results[ST_SEC] - BASE_SECTOR + 1;
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_do_open *
|
|
*===========================================================================*/
|
|
static int f_do_open(devminor_t minor, int UNUSED(access))
|
|
{
|
|
/* Handle an open on a floppy. Determine diskette type if need be. */
|
|
|
|
int dtype;
|
|
struct test_order *top;
|
|
|
|
/* Decode the message parameters. */
|
|
if (f_prepare(minor) == NULL) return(ENXIO);
|
|
|
|
dtype = f_device & DEV_TYPE_BITS; /* get density from minor dev */
|
|
if (dtype >= MINOR_fd0p0) dtype = 0;
|
|
|
|
if (dtype != 0) {
|
|
/* All types except 0 indicate a specific drive/medium combination.*/
|
|
dtype = (dtype >> DEV_TYPE_SHIFT) - 1;
|
|
if (dtype >= NT) return(ENXIO);
|
|
f_fp->fl_density = dtype;
|
|
(void) f_prepare(f_device); /* Recompute parameters. */
|
|
return(OK);
|
|
}
|
|
if (f_device & FORMAT_DEV_BIT) return(EIO); /* Can't format /dev/fdN */
|
|
|
|
/* The device opened is /dev/fdN. Experimentally determine drive/medium.
|
|
* First check fl_density. If it is not NO_DENS, the drive has been used
|
|
* before and the value of fl_density tells what was found last time. Try
|
|
* that first. If the motor is still running then assume nothing changed.
|
|
*/
|
|
if (f_fp->fl_density != NO_DENS) {
|
|
if (motor_status & (1 << f_drive)) return(OK);
|
|
if (test_read(f_fp->fl_density) == OK) return(OK);
|
|
}
|
|
|
|
/* Either drive type is unknown or a different diskette is now present.
|
|
* Use test_order to try them one by one.
|
|
*/
|
|
for (top = &test_order[0]; top < &test_order[NT-1]; top++) {
|
|
dtype = top->t_density;
|
|
|
|
/* Skip densities that have been proven to be impossible */
|
|
if (!(f_fp->fl_class & (1 << dtype))) continue;
|
|
|
|
if (test_read(dtype) == OK) {
|
|
/* The test succeeded, use this knowledge to limit the
|
|
* drive class to match the density just read.
|
|
*/
|
|
f_fp->fl_class &= top->t_class;
|
|
return(OK);
|
|
}
|
|
/* Test failed, wrong density or did it time out? */
|
|
if (f_busy == BSY_WAKEN) break;
|
|
}
|
|
f_fp->fl_density = NO_DENS;
|
|
return(EIO); /* nothing worked */
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_do_close *
|
|
*===========================================================================*/
|
|
static int f_do_close(devminor_t UNUSED(minor))
|
|
{
|
|
/* Handle a close on a floppy. Nothing to do here. */
|
|
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* test_read *
|
|
*===========================================================================*/
|
|
static int test_read(int density)
|
|
{
|
|
/* Try to read the highest numbered sector on cylinder 2. Not all floppy
|
|
* types have as many sectors per track, and trying cylinder 2 finds the
|
|
* ones that need double stepping.
|
|
*/
|
|
int device;
|
|
off_t position;
|
|
iovec_t iovec1;
|
|
ssize_t result;
|
|
|
|
f_fp->fl_density = density;
|
|
device = ((density + 1) << DEV_TYPE_SHIFT) + f_drive;
|
|
|
|
(void) f_prepare(device);
|
|
position = (off_t) f_dp->test << SECTOR_SHIFT;
|
|
iovec1.iov_addr = (vir_bytes) floppy_buf;
|
|
iovec1.iov_size = SECTOR_SIZE;
|
|
result = f_transfer(device, FALSE /*do_write*/, position, SELF,
|
|
&iovec1, 1, BDEV_NOFLAGS);
|
|
|
|
if (result != SECTOR_SIZE) return(EIO);
|
|
|
|
partition(&f_dtab, f_drive, P_FLOPPY, 0);
|
|
return(OK);
|
|
}
|
|
|
|
/*===========================================================================*
|
|
* f_geometry *
|
|
*===========================================================================*/
|
|
static void f_geometry(devminor_t minor, struct part_geom *entry)
|
|
{
|
|
if (f_prepare(minor) == NULL) return;
|
|
|
|
entry->cylinders = f_dp->cyls;
|
|
entry->heads = NR_HEADS;
|
|
entry->sectors = f_sectors;
|
|
}
|