Annotation of qemu/roms/SLOF/clients/net-snk/kernel/timer.c, revision 1.1.1.3

1.1       root        1: /******************************************************************************
                      2:  * Copyright (c) 2004, 2008 IBM Corporation
                      3:  * All rights reserved.
                      4:  * This program and the accompanying materials
                      5:  * are made available under the terms of the BSD License
                      6:  * which accompanies this distribution, and is available at
                      7:  * http://www.opensource.org/licenses/bsd-license.php
                      8:  *
                      9:  * Contributors:
                     10:  *     IBM Corporation - initial implementation
                     11:  *****************************************************************************/
1.1.1.2   root       12: 
                     13: #include <stdint.h>
1.1.1.3 ! root       14: #include "kernel.h"
1.1       root       15: 
                     16: //*******************************************************************
                     17: // variable "tb_freq" contains the frequency in Hz
                     18: // and is read from the device tree (setup by LLFW) in "init.c"
                     19: uint64_t tb_freq;
                     20: 
                     21: //-------------------------------------------------------------------
                     22: // Read the current timebase
                     23: uint64_t get_time(void)
                     24: {
                     25:     uint64_t act;
                     26: 
                     27:     __asm__ __volatile__( 
                     28:         "0:     mftbu   %0 ;\
                     29:                 mftbl   %%r0 ; \
                     30:                 mftbu   %%r4 ; \
                     31:                 cmpw    %0,%%r4 ; \
                     32:                 bne     0b; \
                     33:                 sldi    %0,%0,32; \
                     34:                 or      %0,%0,%%r0"
                     35:         : "=r"(act)
                     36:         : /* no inputs */
                     37:         : "r0", "r4");
                     38:     return act;
                     39: }
                     40: 
                     41: //-------------------------------------------------------------------
                     42: // wait for ticks/scale timebase ticks
1.1.1.3 ! root       43: static void wait_ticks(uint64_t ticks)
1.1       root       44: {
                     45:         uint64_t timeout = get_time() + ticks;
                     46:         while (get_time() < timeout) {
                     47:                 unsigned int i;
                     48:                 for (i = 1000; i > 0; i--)
                     49:                         __asm__ __volatile__ ("" : : : "memory");
                     50:         }
                     51: }
                     52: 
                     53: //-------------------------------------------------------------------
                     54: // wait for (at least) usecs microseconds
                     55: void udelay(unsigned int usecs)
                     56: {
                     57:         // first multiply the usec with timebase and then devide
                     58:         // because 1.000.000 is relatively huge compared to usecs
                     59:         wait_ticks((usecs*tb_freq)/1000000);
                     60: }
                     61: 
                     62: //-------------------------------------------------------------------
                     63: // wait for (at least) msecs milliseconds
                     64: void mdelay(unsigned int msecs)
                     65: {
                     66:         // first multiply the msec and timebase and then devide
                     67:         // because 1.000 is relatively huge compared to msecs
                     68:         wait_ticks((msecs*tb_freq)/1000);
                     69: }

unix.superglobalmegacorp.com

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