--- Gnu-Mach/i386/i386at/kd_mouse.c 2020/09/02 04:42:08 1.1.1.2 +++ Gnu-Mach/i386/i386at/kd_mouse.c 2020/09/02 04:46:52 1.1.1.4 @@ -1,25 +1,25 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ @@ -66,46 +66,31 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT #include #include -#ifdef MACH_KERNEL -#include +#include +#include +#include #include -#else MACH_KERNEL -#include -#include -#include -#include -#include -#include -#include -#include -#endif MACH_KERNEL +#include #include +#include +#include #include +#include #include #include #include -static int (*oldvect)(); /* old interrupt vector */ +#include "kd_mouse.h" + +static void (*oldvect)(); /* old interrupt vector */ static int oldunit; static spl_t oldspl; extern struct bus_device *cominfo[]; kd_event_queue mouse_queue; /* queue of mouse events */ boolean_t mouse_in_use = FALSE; -#ifdef MACH_KERNEL queue_head_t mouse_read_queue = { &mouse_read_queue, &mouse_read_queue }; -#else MACH_KERNEL -struct proc *mouse_sel = 0; /* selecting process, if any */ -short mousepgrp = 0; /* process group leader when dev is open */ -#endif MACH_KERNEL - -#ifdef MACH_KERNEL -#else MACH_KERNEL -int mouseflag = 0; -#define MOUSE_COLL 1 /* select collision */ -#define MOUSE_ASYNC 2 /* user wants asynch notification */ -#define MOUSE_NBIO 4 /* user wants non-blocking I/O */ -#endif MACH_KERNEL + /* * The state of the 3 buttons is encoded in the low-order 3 bits (both @@ -116,22 +101,22 @@ u_char lastbuttons; /* previous state o #define MOUSE_DOWN 0 #define MOUSE_ALL_UP 0x7 -int mouseintr(); +void mouseintr(); void mouse_enqueue(); int mouse_baud = BCNT1200; boolean_t mouse_char_cmd = FALSE; /* mouse response is to cmd */ boolean_t mouse_char_wanted = FALSE; /* want mouse response */ -boolean_t mouse_char_in = FALSE; /* have mouse response */ -unsigned char mouse_char; /* mouse response */ +int mouse_char_index; /* mouse response */ /* * init_mouse_hw - initialize the serial port. */ +void init_mouse_hw(unit, mode) { - caddr_t base_addr = (caddr_t)cominfo[unit]->address; + unsigned short base_addr = cominfo[unit]->address; outb(base_addr + RIE, 0); outb(base_addr + RLC, LCDLAB); @@ -163,24 +148,16 @@ static int mousebufindex = 0; int track_man[10]; /*ARGSUSED*/ +int mouseopen(dev, flags) dev_t dev; int flags; { -#ifdef MACH_KERNEL -#else MACH_KERNEL - if (flags & FWRITE) - return(ENODEV); -#endif MACH_KERNEL if (mouse_in_use) - return(EBUSY); + return (D_ALREADY_OPEN); mouse_in_use = TRUE; /* locking? */ kdq_reset(&mouse_queue); lastbuttons = MOUSE_ALL_UP; -#ifdef MACH_KERNEL -#else MACH_KERNEL - mousepgrp = u.u_procp->p_pgrp; -#endif MACH_KERNEL switch (mouse_type = ((minor(dev) & 0xf8) >> 3)) { case MICROSOFT_MOUSE7: @@ -203,7 +180,7 @@ mouseopen(dev, flags) init_mouse_hw(dev&7, LC7); track_man[0] = comgetc(dev&7); track_man[1] = comgetc(dev&7); - if (track_man[0] != 0x4d && + if (track_man[0] != 0x4d && track_man[1] != 0x33) { printf("LOGITECH_TRACKMAN: NOT M3"); } @@ -220,7 +197,9 @@ mouseopen(dev, flags) return(0); } +void serial_mouse_open(dev) + dev_t dev; { int unit = minor(dev) & 0x7; int mouse_pic = cominfo[unit]->sysdep1; @@ -238,10 +217,14 @@ serial_mouse_open(dev) } int mouse_packets = 0; + +void kd_mouse_open(dev, mouse_pic) + dev_t dev; + int mouse_pic; { spl_t s = splhi(); /* disable interrupts */ - extern int kdintr(); + extern void kdintr(); oldvect = ivect[mouse_pic]; ivect[mouse_pic] = kdintr; @@ -252,17 +235,20 @@ kd_mouse_open(dev, mouse_pic) } /* - * mouseclose - Disable interrupts on the serial port, reset driver flags, + * mouseclose - Disable interrupts on the serial port, reset driver flags, * and restore the serial port interrupt vector. */ +void mouseclose(dev, flags) + dev_t dev; + int flags; { switch (mouse_type) { case MICROSOFT_MOUSE: case MICROSOFT_MOUSE7: case MOUSE_SYSTEM_MOUSE: case LOGITECH_TRACKMAN: - serial_mouse_close(dev); + serial_mouse_close(dev, flags); break; case IBM_MOUSE: ibm_ps2_mouse_close(dev); @@ -276,15 +262,10 @@ mouseclose(dev, flags) kdq_reset(&mouse_queue); /* paranoia */ mouse_in_use = FALSE; -#ifdef MACH_KERNEL -#else MACH_KERNEL - mousepgrp = 0; - mouseflag = 0; - mouse_sel = 0; -#endif MACH_KERNEL } /*ARGSUSED*/ +void serial_mouse_close(dev, flags) dev_t dev; int flags; @@ -292,7 +273,7 @@ serial_mouse_close(dev, flags) spl_t o_pri = splhi(); /* mutex with open() */ int unit = minor(dev) & 0x7; int mouse_pic = cominfo[unit]->sysdep1; - caddr_t base_addr = (caddr_t)cominfo[unit]->address; + unsigned short base_addr = cominfo[unit]->address; assert(ivect[mouse_pic] == mouseintr); outb(base_addr + RIE, 0); /* disable serial port */ @@ -303,7 +284,10 @@ serial_mouse_close(dev, flags) (void)splx(o_pri); } +void kd_mouse_close(dev, mouse_pic) + dev_t dev; + int mouse_pic; { spl_t s = splhi(); @@ -313,15 +297,12 @@ kd_mouse_close(dev, mouse_pic) splx(s); } -#ifdef MACH_KERNEL io_return_t mousegetstat(dev, flavor, data, count) dev_t dev; int flavor; int * data; /* pointer to OUT array */ unsigned int *count; /* OUT */ { - io_return_t result; - switch (flavor) { case DEV_GET_SIZE: data[DEV_GET_SIZE_DEVICE_SIZE] = 0; @@ -334,75 +315,13 @@ io_return_t mousegetstat(dev, flavor, da return D_SUCCESS; } -#else MACH_KERNEL -/* - * mouseioctl - handling for asynch & non-blocking I/O. - */ - -/*ARGSUSED*/ -mouseioctl(dev, cmd, data, flag) - dev_t dev; - int cmd; - caddr_t data; - int flag; -{ - int s = SPLKD(); - int err = 0; - - switch (cmd) { - case FIONBIO: - if (*(int *)data) - mouseflag |= MOUSE_NBIO; - else - mouseflag &= ~MOUSE_NBIO; - break; - case FIOASYNC: - if (*(int *)data) - mouseflag |= MOUSE_ASYNC; - else - mouseflag &= ~MOUSE_ASYNC; - break; - default: - err = ENOTTY; - break; - } - - splx(s); - return(err); -} - - -/* - * mouseselect - check for pending events, etc. - */ - -/*ARGSUSED*/ -mouseselect(dev, rw) -{ - int s = SPLKD(); - - if (!kdq_empty(&mouse_queue)) { - splx(s); - return(1); - } - - if (mouse_sel) - mouseflag |= MOUSE_COLL; - else - mouse_sel = (struct proc *)current_thread(); - /* eeeyuck */ - - splx(s); - return(0); -} -#endif MACH_KERNEL /* * mouseread - dequeue and return any queued events. */ -#ifdef MACH_KERNEL boolean_t mouse_read_done(); /* forward */ +int mouseread(dev, ior) dev_t dev; register io_req_t ior; @@ -472,52 +391,15 @@ boolean_t mouse_read_done(ior) return (TRUE); } -#else MACH_KERNEL -/*ARGSUSED*/ -mouseread(dev, uio) - dev_t dev; - struct uio *uio; -{ - int s = SPLKD(); - int err = 0; - kd_event *ev; - int i; - char *cp; - - if (kdq_empty(&mouse_queue)) - if (mouseflag & MOUSE_NBIO) { - err = EWOULDBLOCK; - goto done; - } else - while (kdq_empty(&mouse_queue)) { - splx(s); - sleep((caddr_t)&mouse_queue, TTIPRI); - s = SPLKD(); - } - - while (!kdq_empty(&mouse_queue) && uio->uio_resid >= sizeof(kd_event)) { - ev = kdq_get(&mouse_queue); - for (cp = (char *)ev, i = 0; i < sizeof(kd_event); - ++i, ++cp) { - err = ureadc(*cp, uio); - if (err) - goto done; - } - } - -done: - splx(s); - return(err); -} -#endif MACH_KERNEL /* * mouseintr - Get a byte and pass it up for handling. Called at SPLKD. */ +void mouseintr(unit) { - caddr_t base_addr = (caddr_t)cominfo[unit]->address; + unsigned short base_addr = cominfo[unit]->address; unsigned char id, ls; /* get reason for interrupt and line status */ @@ -547,7 +429,7 @@ mouseintr(unit) */ int show_mouse_byte = 0; /* - X down; middle down; middle up; X up 50 0 0; 50 0 0 22; 50 0 0 02; 40 0 0 + X down; middle down; middle up; X up 50 0 0; 50 0 0 22; 50 0 0 02; 40 0 0 X down; middle down; X up; middle up 50 0 0; 50 0 0 22; 40 0 0 22; 40 0 0 2 * * The trick here is that all the while the middle button is down you get 4 byte @@ -562,6 +444,7 @@ int middlegitech = 0; /* what should th #define MOUSEBUFSIZE 5 /* num bytes def'd by protocol */ static u_char mousebuf[MOUSEBUFSIZE]; /* 5-byte packet from mouse */ +void mouse_handle_byte(ch) u_char ch; { @@ -573,11 +456,11 @@ mouse_handle_byte(ch) /* * Mouse character is response to command */ - mouse_char = ch; - mouse_char_in = TRUE; + if (mousebufindex < mousebufsize) + mousebuf[mousebufindex++] = ch; if (mouse_char_wanted) { mouse_char_wanted = FALSE; - wakeup(&mouse_char); + wakeup((vm_offset_t)&mousebuf); } return; } @@ -616,7 +499,7 @@ mouse_handle_byte(ch) mousebuf[mousebufindex++] = ch; if (mousebufindex < mousebufsize) return; - + /* got a packet */ mousebufindex = 0; @@ -643,6 +526,7 @@ mouse_handle_byte(ch) } } +void mouse_packet_mouse_system_mouse(mousebuf) u_char mousebuf[MOUSEBUFSIZE]; { @@ -678,6 +562,7 @@ u_char mousebuf[MOUSEBUFSIZE]; * 1 0 Y5 Y4 Y3 Y2 Y1 Y0 * */ +void mouse_packet_microsoft_mouse(mousebuf) u_char mousebuf[MOUSEBUFSIZE]; { @@ -747,23 +632,32 @@ int kd_mouse_read(void) { int ch; - while (!mouse_char_in) { + if (mouse_char_index >= mousebufsize) + return -1; + + while (mousebufindex <= mouse_char_index) { mouse_char_wanted = TRUE; -#ifdef MACH_KERNEL - assert_wait((event_t) &mouse_char, FALSE); + assert_wait((event_t) &mousebuf, FALSE); thread_block((void (*)()) 0); -#else MACH_KERNEL - sleep(&mouse_char, PZERO); -#endif MACH_KERNEL } - ch = mouse_char; - mouse_char_in = FALSE; + ch = mousebuf[mouse_char_index++]; return ch; } +/* + * Prepare buffer for receiving next packet from mouse. + */ +void kd_mouse_read_reset(void) +{ + mousebufindex = 0; + mouse_char_index = 0; +} + +void ibm_ps2_mouse_open(dev) + dev_t dev; { spl_t s = spltty(); @@ -775,6 +669,7 @@ ibm_ps2_mouse_open(dev) kd_cmdreg_write(0x47); /* allow mouse interrupts */ /* magic number for ibm? */ + kd_mouse_read_reset(); kd_mouse_write(0xff); /* reset mouse */ if (kd_mouse_read() != 0xfa) { splx(s); @@ -784,29 +679,35 @@ ibm_ps2_mouse_open(dev) (void) kd_mouse_read(); /* discard 2-character mouse ID */ (void) kd_mouse_read(); + kd_mouse_read_reset(); kd_mouse_write(0xea); /* set stream mode */ if (kd_mouse_read() != 0xfa) { splx(s); return; /* need ACK */ } + kd_mouse_read_reset(); kd_mouse_write(0xf4); /* enable */ if (kd_mouse_read() != 0xfa) { splx(s); return; /* need ACK */ } + kd_mouse_read_reset(); mouse_char_cmd = FALSE; /* now we get mouse packets */ splx(s); } +void ibm_ps2_mouse_close(dev) + dev_t dev; { spl_t s = spltty(); mouse_char_cmd = TRUE; /* responses are to commands */ + kd_mouse_read_reset(); kd_mouse_write(0xff); /* reset mouse */ if (kd_mouse_read() == 0xfa) { /* got ACK: discard 2-char mouse ID */ @@ -830,6 +731,7 @@ ibm_ps2_mouse_close(dev) * Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 * */ +void mouse_packet_ibm_ps2_mouse(mousebuf) u_char mousebuf[MOUSEBUFSIZE]; { @@ -862,6 +764,7 @@ u_char mousebuf[MOUSEBUFSIZE]; /* * Enqueue a mouse-motion event. Called at SPLKD. */ +void mouse_moved(where) struct mouse_motion where; { @@ -877,6 +780,7 @@ mouse_moved(where) /* * Enqueue an event for mouse button press or release. Called at SPLKD. */ +void mouse_button(which, direction) kev_type which; u_char direction; @@ -904,20 +808,9 @@ mouse_enqueue(ev) else kdq_put(&mouse_queue, ev); -#ifdef MACH_KERNEL { register io_req_t ior; while ((ior = (io_req_t)dequeue_head(&mouse_read_queue)) != 0) iodone(ior); } -#else MACH_KERNEL - if (mouse_sel) { - selwakeup(mouse_sel, mouseflag & MOUSE_COLL); - mouse_sel = 0; - mouseflag &= ~MOUSE_COLL; - } - if (mouseflag & MOUSE_ASYNC) - gsignal(mousepgrp, SIGIO); - wakeup((caddr_t)&mouse_queue); -#endif MACH_KERNEL }