Annotation of coherent/d/286_KERNEL/USRSRC/286/clocked.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * clocked.c - support routines for alternate clock rate
        !             3:  *
        !             4:  *  altclk_in(hz, fn) - install routine with specified rate
        !             5:  *                      "hz" should be a multiple of system rate of 100 Hz
        !             6:  *                     return 0 if completed ok, -1 otherwise
        !             7:  *
        !             8:  *  altclk_out()      - uninstall alternate clock routine and restore system rate
        !             9:  *                     return old value of "altclk"
        !            10:  *
        !            11:  *  altclk_rate(hz)   - set clock interrupt rate
        !            12:  *                     new rate must be an even multiple of system rate "HZ"
        !            13:  *                     return 0 if completed ok, -1 otherwise
        !            14:  *
        !            15:  *  History:
        !            16:  *    90/08/08 hws     initial version, works with hs.c modified for com[1-4]
        !            17:  *    90/08/14 hws     make it more like a Unix system call
        !            18:  */
        !            19: 
        !            20: #include       <sys/coherent.h>                /* altclk */
        !            21: #include       <sys/const.h>           /* HZ */
        !            22: 
        !            23: #define        PIT     0x40            /* 8253 port */
        !            24: #define        TMR0_M3 0x36            /* timer 0, mode 3 */
        !            25: 
        !            26: #if 0
        !            27:                                /* nominal IBM rate is 1.1900 MHz */
        !            28: #define        SYS_HZ  1190000L        /* rate of input clock to timer 0 */
        !            29: #else
        !            30:                                /* current kernel rate is 1.1932 MHz */
        !            31: #define        SYS_HZ  1193200L        /* rate of input clock to timer 0 */
        !            32: #endif
        !            33: 
        !            34: typedef int (*PFI)();          /* pointer to function returning int */
        !            35: 
        !            36: altclk_rate(hz)
        !            37: unsigned int hz;
        !            38: {
        !            39:        int s;                  /* to save CPU irpt flag */
        !            40:        unsigned int interval;  /* period for hz, in units of 1.19 MHz ticks */
        !            41:        int ret;
        !            42: 
        !            43:        if (hz >= HZ && hz % HZ == 0) {         /* can't go slower than HZ! */
        !            44:                interval = SYS_HZ/hz;
        !            45:                s = sphi();                     /* disable irpts */
        !            46:                outb(PIT+3, TMR0_M3);
        !            47:                outb(PIT, interval & 0xff);
        !            48:                outb(PIT, interval >> 8);       /* unsigned shift */
        !            49:                spl(s);                         /* restore previous irpt state */
        !            50:                ret = 0;
        !            51:        } else {
        !            52:                ret = -1;
        !            53:        }
        !            54:        return ret;
        !            55: }
        !            56: 
        !            57: int altclk_in(hz, fn)
        !            58: int hz;
        !            59: PFI fn;
        !            60: {
        !            61:        int ret;
        !            62: 
        !            63:        if ((ret = altclk_rate(hz)) == 0)
        !            64:                altclk = fn;
        !            65:        return ret;
        !            66: }
        !            67: 
        !            68: PFI altclk_out()
        !            69: {
        !            70:        PFI ret;
        !            71: 
        !            72:        ret = altclk;
        !            73:        if (ret) {
        !            74:                altclk_rate(HZ);
        !            75:                altclk = 0;
        !            76:        }
        !            77:        return ret;
        !            78: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.