github.com/craftyguy/u-root@v1.0.0/cmds/console/i8042_linux.go (about) 1 // Copyright 2012-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file contains support functions for i8042 io for Linux. 6 package main 7 8 const ( 9 Data = 0x60 /* data port */ 10 11 Status = 0x64 /* status port */ 12 Inready = 0x01 /* input character ready */ 13 Outbusy = 0x02 /* output busy */ 14 Sysflag = 0x04 /* system flag */ 15 Cmddata = 0x08 /* cmd==0 data==1 */ 16 Inhibit = 0x10 /* keyboard/mouse inhibited */ 17 Minready = 0x20 /* mouse character ready */ 18 Rtimeout = 0x40 /* general timeout */ 19 Parity = 0x80 20 21 Cmd = 0x64 /* command port (write only) */ 22 Nscan = 128 23 ) 24 25 type i8042 struct { 26 data, status int64 27 } 28 29 func openi8042() (*i8042, error) { 30 if err := openPort(); err != nil { 31 return nil, err 32 } 33 34 return &i8042{data: Data, status: Status}, nil 35 } 36 37 func (u *i8042) OK(bit uint8) (bool, error) { 38 var rdy [1]byte 39 if _, err := portFile.ReadAt(rdy[:], u.status); err != nil { 40 return false, err 41 } 42 return rdy[0]&bit != 0, nil 43 } 44 45 func (u *i8042) io(b []byte, bit uint8, f func([]byte) error) (int, error) { 46 var ( 47 err error 48 amt int 49 ) 50 51 for amt = 0; amt < len(b); { 52 rdy, err := u.OK(bit) 53 if err != nil { 54 break 55 } 56 if !rdy { 57 continue 58 } 59 if err = f(b[amt:]); err != nil { 60 break 61 } 62 amt = amt + 1 63 } 64 return amt, err 65 } 66 67 func (u *i8042) Read(b []byte) (int, error) { 68 return u.io(b, Inready, func(b []byte) error { 69 _, err := portFile.ReadAt(b[:1], u.data) 70 return err 71 }) 72 }