diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2017-05-10 16:04:22 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2017-05-10 16:04:22 +0000 |
commit | 089c4eb612aea43efbe536e468d8698defe4236c (patch) | |
tree | 32d9b9856c143be7a8f8cbd87be1c6e111a3819f /sys/arch | |
parent | cf1f1023eea525d37f1783e6c6f502b28148f2aa (diff) |
Hook up HPET as a timecounter.
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/loongson/loongson/generic3a_machdep.c | 58 | ||||
-rw-r--r-- | sys/arch/mips64/include/loongson3.h | 3 |
2 files changed, 59 insertions, 2 deletions
diff --git a/sys/arch/loongson/loongson/generic3a_machdep.c b/sys/arch/loongson/loongson/generic3a_machdep.c index 65e63ccea62..7c26088783e 100644 --- a/sys/arch/loongson/loongson/generic3a_machdep.c +++ b/sys/arch/loongson/loongson/generic3a_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: generic3a_machdep.c,v 1.6 2017/05/10 15:21:02 visa Exp $ */ +/* $OpenBSD: generic3a_machdep.c,v 1.7 2017/05/10 16:04:21 visa Exp $ */ /* * Copyright (c) 2009, 2010, 2012 Miodrag Vallat. @@ -25,6 +25,7 @@ #include <sys/systm.h> #include <sys/device.h> #include <sys/proc.h> +#include <sys/timetc.h> #include <mips64/archtype.h> #include <mips64/loongson3.h> @@ -46,6 +47,15 @@ #include <loongson/dev/htbvar.h> #include <loongson/dev/leiocvar.h> +#define HPET_FREQ 14318780 +#define HPET_MMIO_BASE 0x20000 + +#define HPET_CONFIGURATION 0x10 +#define HPET_MAIN_COUNTER 0xf0 + +#define HPET_REGVAL32(x) \ + REGVAL32(LS3_HT1_MEM_BASE(0) + HPET_MMIO_BASE + (x)) + #define IRQ_CASCADE 2 void generic3a_device_register(struct device *, void *); @@ -80,6 +90,17 @@ void rs780e_set_imask(uint32_t); void rs780e_irq_mask(int); void rs780e_irq_unmask(int); +u_int rs780e_get_timecount(struct timecounter *); + +struct timecounter rs780e_timecounter = { + .tc_get_timecount = rs780e_get_timecount, + .tc_poll_pps = NULL, + .tc_counter_mask = 0xffffffffu, /* truncated to 32 bits */ + .tc_frequency = HPET_FREQ, + .tc_name = "hpet", + .tc_quality = 100 +}; + /* Firmware entry points */ void (*generic3a_reboot_entry)(void); void (*generic3a_poweroff_entry)(void); @@ -374,6 +395,9 @@ rs780e_setup(void) void rs780sb_setup(pci_chipset_tag_t pc, int dev) { + pcitag_t tag; + pcireg_t reg; + /* * Set up the PIC in the southbridge. */ @@ -393,6 +417,32 @@ rs780sb_setup(pci_chipset_tag_t pc, int dev) REGVAL8(HTB_IO_BASE + IO_ICU2 + PIC_OCW1) = 0xff; loongson3_register_ht_pic(&rs780e_pic); + + /* + * Set up the HPET. + * + * Unfortunately, PMON does not initialize the MMIO base address or + * the tick period, even though it should because it has a complete + * view of the system's resources. + * Use the same address as in Linux in the hope of avoiding + * address space conflicts. + */ + + tag = pci_make_tag(pc, 0, dev, 0); + + /* Set base address for HPET MMIO. */ + pci_conf_write(pc, tag, 0xb4, HPET_MMIO_BASE); + + /* Enable decoding of HPET MMIO. */ + reg = pci_conf_read(pc, tag, 0x40); + reg |= 1u << 28; + pci_conf_write(pc, tag, 0x40, reg); + + /* Enable the HPET. */ + reg = HPET_REGVAL32(HPET_CONFIGURATION); + HPET_REGVAL32(HPET_CONFIGURATION) = reg | 1u; + + tc_init(&rs780e_timecounter); } void @@ -454,3 +504,9 @@ rs780e_irq_unmask(int irq) { rs780e_set_imask(rs780e_imask | (1u << irq)); } + +u_int +rs780e_get_timecount(struct timecounter *arg) +{ + return HPET_REGVAL32(HPET_MAIN_COUNTER); +} diff --git a/sys/arch/mips64/include/loongson3.h b/sys/arch/mips64/include/loongson3.h index 98839c66370..f697e6b0092 100644 --- a/sys/arch/mips64/include/loongson3.h +++ b/sys/arch/mips64/include/loongson3.h @@ -1,4 +1,4 @@ -/* $OpenBSD: loongson3.h,v 1.2 2016/12/12 16:25:47 visa Exp $ */ +/* $OpenBSD: loongson3.h,v 1.3 2017/05/10 16:04:21 visa Exp $ */ /* * Copyright (c) 2016 Visa Hankala @@ -99,6 +99,7 @@ loongson3_get_cpuid(void) * HyperTransport registers */ +#define LS3_HT1_MEM_BASE(n) (LS3_MEM_BASE(n)+0x00000e0000000000ull) #define LS3_HT1_CFG_BASE(n) (LS3_MEM_BASE(n)+0x00000efdfb000000ull) #define LS3_HT_ISR_OFFSET(x) (0x80 + (x) * 4) |