diff options
author | Paul Irofti <pirofti@cvs.openbsd.org> | 2013-01-16 07:18:00 +0000 |
---|---|---|
committer | Paul Irofti <pirofti@cvs.openbsd.org> | 2013-01-16 07:18:00 +0000 |
commit | 44aa720b13bb54c6c4c46ac926b9e225e83710e8 (patch) | |
tree | b8addb457a37c15bb3817ef373b40cf9289450b4 /sys | |
parent | 5a4345224f103103da1da8f00db185fc1829cbbf (diff) |
Loongson: add throttling support.
This commit allows CPU throttling on the 2F systems.
Inspired by an old diff from otto@.
Help from and okay miod@.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/loongson/loongson/loongson2_machdep.c | 29 | ||||
-rw-r--r-- | sys/arch/loongson/loongson/yeeloong_machdep.c | 4 | ||||
-rw-r--r-- | sys/dev/pci/glxpcib.c | 6 |
3 files changed, 31 insertions, 8 deletions
diff --git a/sys/arch/loongson/loongson/loongson2_machdep.c b/sys/arch/loongson/loongson/loongson2_machdep.c index 427ddb4037b..88383766b04 100644 --- a/sys/arch/loongson/loongson/loongson2_machdep.c +++ b/sys/arch/loongson/loongson/loongson2_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loongson2_machdep.c,v 1.11 2011/03/31 20:37:44 miod Exp $ */ +/* $OpenBSD: loongson2_machdep.c,v 1.12 2013/01/16 07:17:59 pirofti Exp $ */ /* * Copyright (c) 2009, 2010 Miodrag Vallat. @@ -39,6 +39,7 @@ void loongson2e_setup(u_long, u_long); void loongson2f_setup(u_long, u_long); void loongson2f_setup_window(uint, uint, uint64_t, uint64_t, uint64_t, uint); int loongson2f_cpuspeed(int *); +void loongson2f_setperf(int); /* PCI view of CPU memory */ paddr_t loongson_dma_base = 0; @@ -207,6 +208,7 @@ loongson2f_setup(u_long memlo, u_long memhi) ~(DDR_PHYSICAL_SIZE - 1), DDR_PHYSICAL_BASE, MASTER_CPU); cpu_cpuspeed = loongson2f_cpuspeed; + cpu_setperf = loongson2f_setperf; } /* @@ -272,6 +274,29 @@ is_memory_range(paddr_t pa, psize_t len, psize_t limit) int loongson2f_cpuspeed(int *freq) { - *freq = bootcpu_hwinfo.clock / 1000000; + uint32_t step, val; + + val = REGVAL(LOONGSON_CHIP_CONFIG0); + step = (val & 0x7) + 1; + *freq = ((bootcpu_hwinfo.clock / 8) * step) / 1000000; + return 0; } + +void +loongson2f_setperf(int percent) +{ + uint32_t step, val; + + step = percent * 8 / 100; + if (step < 2) + step = 2; + + /* + * Set clock step. + */ + val = REGVAL(LOONGSON_CHIP_CONFIG0); + val = (val & ~0x7) | (step - 1); + REGVAL(LOONGSON_CHIP_CONFIG0) = val; + (void)REGVAL(LOONGSON_CHIP_CONFIG0); +} diff --git a/sys/arch/loongson/loongson/yeeloong_machdep.c b/sys/arch/loongson/loongson/yeeloong_machdep.c index 6f426fe9a61..c7f9a224a5c 100644 --- a/sys/arch/loongson/loongson/yeeloong_machdep.c +++ b/sys/arch/loongson/loongson/yeeloong_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: yeeloong_machdep.c,v 1.21 2013/01/14 21:18:47 pirofti Exp $ */ +/* $OpenBSD: yeeloong_machdep.c,v 1.22 2013/01/16 07:17:59 pirofti Exp $ */ /* * Copyright (c) 2009, 2010 Miodrag Vallat. @@ -75,6 +75,7 @@ void lemote_isa_intr_disestablish(void *, void *); uint lemote_get_isa_imr(void); uint lemote_get_isa_isr(void); uint32_t lemote_isa_intr(uint32_t, struct trap_frame *); +extern void (*cpu_setperf)(int); const struct bonito_config lemote_bonito = { .bc_adbase = 11, @@ -481,6 +482,7 @@ yeeloong_powerdown() void lemote_reset() { + cpu_setperf(100); wrmsr(GLCP_SYS_RST, rdmsr(GLCP_SYS_RST) | 1); } diff --git a/sys/dev/pci/glxpcib.c b/sys/dev/pci/glxpcib.c index 5ae0ef9978e..d55d0cadd87 100644 --- a/sys/dev/pci/glxpcib.c +++ b/sys/dev/pci/glxpcib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: glxpcib.c,v 1.8 2013/01/14 21:18:47 pirofti Exp $ */ +/* $OpenBSD: glxpcib.c,v 1.9 2013/01/16 07:17:59 pirofti Exp $ */ /* * Copyright (c) 2007 Marc Balmer <mbalmer@openbsd.org> @@ -280,11 +280,7 @@ glxpcib_attach(struct device *parent, struct device *self, void *aux) tc->tc_counter_mask = 0xffffffff; tc->tc_frequency = 3579545; tc->tc_name = "CS5536"; -#ifdef __loongson__ - tc->tc_quality = 0; -#else tc->tc_quality = 1000; -#endif tc->tc_priv = sc; tc_init(tc); |