i386 removal, part 11/x: Remove wrong machine/ setup in the boot Makefiles.
[dragonfly.git] / sys / platform / pc32 / acpica / acpi_cstate_machdep.c
1 /*
2  * Copyright (c) 2014 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Sepherosa Ziehau <sepherosa@gmail.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <sys/globaldata.h>
39
40 #include <machine/md_var.h>
41 #include <machine/cpufunc.h>
42 #include <machine/cpufreq.h>
43 #include <machine/cputypes.h>
44 #include <machine/specialreg.h>
45
46 #include "acpi.h"
47 #include "acpi_cpu_cstate.h"
48
49 int
50 acpi_cst_md_cx_setup(struct acpi_cst_cx *cx)
51 {
52         if (cpu_vendor_id != CPU_VENDOR_INTEL) {
53                 /*
54                  * No optimization for non-Intel CPUs so far.
55                  *
56                  * Hardware fixed resouce is not supported for
57                  * C1+ state yet.
58                  */
59                 if (cx->type == ACPI_STATE_C1 &&
60                     cx->gas.SpaceId == ACPI_ADR_SPACE_FIXED_HARDWARE)
61                         return 0;
62                 if (cx->gas.SpaceId != ACPI_ADR_SPACE_SYSTEM_IO &&
63                     cx->gas.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
64                         kprintf("C%d: invalid SpaceId %d\n", cx->type,
65                             cx->gas.SpaceId);
66                         return EINVAL;
67                 }
68                 return 0;
69         }
70
71         if (cx->type == ACPI_STATE_C1 &&
72             cx->gas.SpaceId == ACPI_ADR_SPACE_FIXED_HARDWARE) {
73                 /* TODO: filter C1 I/O then halt */
74                 return 0;
75         }
76
77         /* TODO: We don't support fixed hardware yet */
78         if (cx->gas.SpaceId != ACPI_ADR_SPACE_SYSTEM_IO &&
79             cx->gas.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
80                 if (cx->gas.SpaceId != ACPI_ADR_SPACE_FIXED_HARDWARE) {
81                         kprintf("C%d: invalid SpaceId %d\n", cx->type,
82                             cx->gas.SpaceId);
83                 }
84                 return EINVAL;
85         }
86
87         if (cx->type >= ACPI_STATE_C3) {
88                 if (CPUID_TO_FAMILY(cpu_id) > 0xf ||
89                     (CPUID_TO_FAMILY(cpu_id) == 0x6 &&
90                      CPUID_TO_MODEL(cpu_id) >= 0xf)) {
91                         /*
92                          * Pentium dual-core, Core 2 and beyond do not
93                          * need any additional activities to enter C3(+).
94                          */
95                         cx->preamble = ACPI_CST_CX_PREAMBLE_NONE;
96                 } else if ((acpi_cst_quirks & ACPI_CST_QUIRK_NO_BM) == 0) {
97                         /*
98                          * Intel CPUs support bus master operation for
99                          * entering C3(+) even on MP system.
100                          */
101                         cx->preamble = ACPI_CST_CX_PREAMBLE_BM_ARB;
102                 }
103         }
104         return 0;
105 }