blob: f91702ff5d46431fd51bdce84fc1ede5820ebde4 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2012 Chromium OS Authors
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Aaron Durbin76c37002012-10-30 09:03:43 -050015 */
16
Duncan Lauried7cb8d02013-05-15 15:03:57 -070017#include <arch/acpi.h>
18#include <arch/acpigen.h>
19#include <cbmem.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include <types.h>
21#include <string.h>
22#include "pch.h"
Duncan Lauried7cb8d02013-05-15 15:03:57 -070023#include "nvs.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050024
25void acpi_create_intel_hpet(acpi_hpet_t * hpet)
26{
27 acpi_header_t *header = &(hpet->header);
28 acpi_addr_t *addr = &(hpet->addr);
29
30 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
31
32 /* fill out header fields */
33 memcpy(header->signature, "HPET", 4);
34 memcpy(header->oem_id, OEM_ID, 6);
35 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
36 memcpy(header->asl_compiler_id, ASLC, 4);
37
38 header->length = sizeof(acpi_hpet_t);
39 header->revision = 1;
40
41 /* fill out HPET address */
42 addr->space_id = 0; /* Memory */
43 addr->bit_width = 64;
44 addr->bit_offset = 0;
45 addr->addrl = (unsigned long long)HPET_ADDR & 0xffffffff;
46 addr->addrh = (unsigned long long)HPET_ADDR >> 32;
47
48 hpet->id = 0x8086a201; /* Intel */
49 hpet->number = 0x00;
50 hpet->min_tick = 0x0080;
51
52 header->checksum =
53 acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
54}
55
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010056static void acpi_create_serialio_ssdt_entry(int id, global_nvs_t *gnvs)
Duncan Lauried7cb8d02013-05-15 15:03:57 -070057{
58 char sio_name[5] = {};
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +010059 snprintf(sio_name, sizeof (sio_name), "S%1uEN", id);
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010060 acpigen_write_name_byte(sio_name, gnvs->s0b[id] ? 1 : 0);
Duncan Lauried7cb8d02013-05-15 15:03:57 -070061}
62
63void acpi_create_serialio_ssdt(acpi_header_t *ssdt)
64{
65 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
66 global_nvs_t *gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010067 int id;
Duncan Lauried7cb8d02013-05-15 15:03:57 -070068
69 if (!gnvs)
70 return;
71
72 /* Fill the SSDT header */
73 memset((void *)ssdt, 0, sizeof(acpi_header_t));
74 memcpy(&ssdt->signature, "SSDT", 4);
75 ssdt->revision = 2;
76 memcpy(&ssdt->oem_id, OEM_ID, 6);
Vladimir Serbinenko6b330f22014-10-05 11:08:40 +020077 memcpy(&ssdt->oem_table_id, "SERIALIO", 8);
78 ssdt->oem_revision = 43;
Duncan Lauried7cb8d02013-05-15 15:03:57 -070079 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
80 ssdt->asl_compiler_revision = 42;
81 ssdt->length = sizeof(acpi_header_t);
82 acpigen_set_current((char *) current);
83
84 /* Fill the SSDT with an entry for each SerialIO device */
85 for (id = 0; id < 8; id++)
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +010086 acpi_create_serialio_ssdt_entry(id, gnvs);
Duncan Lauried7cb8d02013-05-15 15:03:57 -070087
88 /* (Re)calculate length and checksum. */
89 current = (unsigned long)acpigen_get_current();
90 ssdt->length = current - (unsigned long)ssdt;
91 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
92}