Initial AMD Barcelona support for rev Bx.
[coreboot.git] / src / cpu / amd / model_10xxx / apic_timer.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <stdint.h>
21 #include <delay.h>
22 #include <cpu/x86/msr.h>
23 #include <cpu/x86/lapic.h>
24
25 /* NOTE: We use the APIC TIMER register is to hold flags for AP init during
26  * pre-memory init (ROMCC). Don't use init_timer() and  udelay is redirected
27  * to udelay_tsc().
28  */
29
30
31 void init_timer(void)
32 {
33         /* Set the apic timer to no interrupts and periodic mode */
34         lapic_write(LAPIC_LVTT, (1 << 17)|(1<< 16)|(0 << 12)|(0 << 0));
35
36         /* Set the divider to 1, no divider */
37         lapic_write(LAPIC_TDCR, LAPIC_TDR_DIV_1);
38
39         /* Set the initial counter to 0xffffffff */
40         lapic_write(LAPIC_TMICT, 0xffffffff);
41
42 }
43
44
45 void udelay(u32 usecs)
46 {
47         u32 start, value, ticks;
48         /* Calculate the number of ticks to run, our FSB runs a 200Mhz */
49         ticks = usecs * 200;
50         start = lapic_read(LAPIC_TMCCT);
51         do {
52                 value = lapic_read(LAPIC_TMCCT);
53         } while((start - value) < ticks);
54
55 }