xref: /openbmc/u-boot/arch/x86/cpu/quark/acpi.c (revision b24a8ec1)
1 /*
2  * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <asm/acpi_table.h>
9 #include <asm/ioapic.h>
10 #include <asm/mpspec.h>
11 #include <asm/tables.h>
12 #include <asm/arch/global_nvs.h>
13 #include <asm/arch/iomap.h>
14 
15 void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
16 		      void *dsdt)
17 {
18 	struct acpi_table_header *header = &(fadt->header);
19 	u16 pmbase = ACPI_PM1_BASE_ADDRESS;
20 
21 	memset((void *)fadt, 0, sizeof(struct acpi_fadt));
22 
23 	acpi_fill_header(header, "FACP");
24 	header->length = sizeof(struct acpi_fadt);
25 	header->revision = 4;
26 
27 	fadt->firmware_ctrl = (u32)facs;
28 	fadt->dsdt = (u32)dsdt;
29 	fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
30 	fadt->sci_int = 9;
31 	fadt->smi_cmd = 0;
32 	fadt->acpi_enable = 0;
33 	fadt->acpi_disable = 0;
34 	fadt->s4bios_req = 0;
35 	fadt->pstate_cnt = 0;
36 	fadt->pm1a_evt_blk = pmbase;
37 	fadt->pm1b_evt_blk = 0x0;
38 	fadt->pm1a_cnt_blk = pmbase + 0x4;
39 	fadt->pm1b_cnt_blk = 0x0;
40 	fadt->pm2_cnt_blk = 0x0;
41 	fadt->pm_tmr_blk = pmbase + 0x8;
42 	fadt->gpe0_blk = ACPI_GPE0_BASE_ADDRESS;
43 	fadt->gpe1_blk = 0;
44 	fadt->pm1_evt_len = 4;
45 	fadt->pm1_cnt_len = 2;
46 	fadt->pm2_cnt_len = 0;
47 	fadt->pm_tmr_len = 4;
48 	fadt->gpe0_blk_len = 8;
49 	fadt->gpe1_blk_len = 0;
50 	fadt->gpe1_base = 0;
51 	fadt->cst_cnt = 0;
52 	fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
53 	fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
54 	fadt->flush_size = 0;
55 	fadt->flush_stride = 0;
56 	fadt->duty_offset = 1;
57 	fadt->duty_width = 3;
58 	fadt->day_alrm = 0x00;
59 	fadt->mon_alrm = 0x00;
60 	fadt->century = 0x00;
61 	fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES;
62 	fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
63 		ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
64 		ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_RESET_REGISTER |
65 		ACPI_FADT_PLATFORM_CLOCK;
66 
67 	fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
68 	fadt->reset_reg.bit_width = 8;
69 	fadt->reset_reg.bit_offset = 0;
70 	fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
71 	fadt->reset_reg.addrl = IO_PORT_RESET;
72 	fadt->reset_reg.addrh = 0;
73 	fadt->reset_value = SYS_RST | RST_CPU;
74 
75 	fadt->x_firmware_ctl_l = (u32)facs;
76 	fadt->x_firmware_ctl_h = 0;
77 	fadt->x_dsdt_l = (u32)dsdt;
78 	fadt->x_dsdt_h = 0;
79 
80 	fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
81 	fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
82 	fadt->x_pm1a_evt_blk.bit_offset = 0;
83 	fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
84 	fadt->x_pm1a_evt_blk.addrl = fadt->pm1a_evt_blk;
85 	fadt->x_pm1a_evt_blk.addrh = 0x0;
86 
87 	fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
88 	fadt->x_pm1b_evt_blk.bit_width = 0;
89 	fadt->x_pm1b_evt_blk.bit_offset = 0;
90 	fadt->x_pm1b_evt_blk.access_size = 0;
91 	fadt->x_pm1b_evt_blk.addrl = 0x0;
92 	fadt->x_pm1b_evt_blk.addrh = 0x0;
93 
94 	fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
95 	fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
96 	fadt->x_pm1a_cnt_blk.bit_offset = 0;
97 	fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
98 	fadt->x_pm1a_cnt_blk.addrl = fadt->pm1a_cnt_blk;
99 	fadt->x_pm1a_cnt_blk.addrh = 0x0;
100 
101 	fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
102 	fadt->x_pm1b_cnt_blk.bit_width = 0;
103 	fadt->x_pm1b_cnt_blk.bit_offset = 0;
104 	fadt->x_pm1b_cnt_blk.access_size = 0;
105 	fadt->x_pm1b_cnt_blk.addrl = 0x0;
106 	fadt->x_pm1b_cnt_blk.addrh = 0x0;
107 
108 	fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
109 	fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8;
110 	fadt->x_pm2_cnt_blk.bit_offset = 0;
111 	fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
112 	fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk;
113 	fadt->x_pm2_cnt_blk.addrh = 0x0;
114 
115 	fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
116 	fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
117 	fadt->x_pm_tmr_blk.bit_offset = 0;
118 	fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
119 	fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk;
120 	fadt->x_pm_tmr_blk.addrh = 0x0;
121 
122 	fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
123 	fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
124 	fadt->x_gpe0_blk.bit_offset = 0;
125 	fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
126 	fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
127 	fadt->x_gpe0_blk.addrh = 0x0;
128 
129 	fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
130 	fadt->x_gpe1_blk.bit_width = 0;
131 	fadt->x_gpe1_blk.bit_offset = 0;
132 	fadt->x_gpe1_blk.access_size = 0;
133 	fadt->x_gpe1_blk.addrl = 0x0;
134 	fadt->x_gpe1_blk.addrh = 0x0;
135 
136 	header->checksum = table_compute_checksum(fadt, header->length);
137 }
138 
139 static int acpi_create_madt_irq_overrides(u32 current)
140 {
141 	struct acpi_madt_irqoverride *irqovr;
142 	u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH;
143 	int length = 0;
144 
145 	irqovr = (void *)current;
146 	length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
147 
148 	irqovr = (void *)(current + length);
149 	length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags);
150 
151 	return length;
152 }
153 
154 u32 acpi_fill_madt(u32 current)
155 {
156 	current += acpi_create_madt_lapics(current);
157 
158 	current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
159 			io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
160 
161 	current += acpi_create_madt_irq_overrides(current);
162 
163 	return current;
164 }
165 
166 void acpi_create_gnvs(struct acpi_global_nvs *gnvs)
167 {
168 	/* quark is a uni-processor */
169 	gnvs->pcnt = 1;
170 }
171