1// Copyright 2016 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#pragma once 6 7#include <acpica/acpi.h> 8#include <zircon/types.h> 9 10enum resource_address_type { 11 RESOURCE_ADDRESS_MEMORY, 12 RESOURCE_ADDRESS_IO, 13 RESOURCE_ADDRESS_BUS_NUMBER, 14 RESOURCE_ADDRESS_UNKNOWN, 15}; 16 17// Structure that unifies the 3 Memory resource types 18typedef struct resource_memory { 19 bool writeable; 20 uint32_t minimum; // min base address 21 uint32_t maximum; // max base address 22 uint32_t alignment; 23 uint32_t address_length; 24} resource_memory_t; 25 26// Structure that unifies the 4 Address resource types 27typedef struct resource_address { 28 // Interpretation of min/max depend on the min/max_address_fixed flags 29 // below. 30 uint64_t minimum; 31 uint64_t maximum; 32 uint64_t address_length; 33 34 uint64_t translation_offset; 35 uint64_t granularity; 36 37 enum resource_address_type resource_type; 38 bool consumed_only; 39 bool subtractive_decode; 40 bool min_address_fixed; 41 bool max_address_fixed; 42} resource_address_t; 43 44typedef struct resource_io { 45 bool decodes_full_space; // If false, only decodes 10-bits 46 uint8_t alignment; 47 uint8_t address_length; 48 uint16_t minimum; 49 uint16_t maximum; 50} resource_io_t; 51 52typedef struct resource_irq { 53 uint8_t trigger; 54 uint8_t polarity; 55 uint8_t sharable; 56 uint8_t wake_capable; 57 uint8_t pin_count; 58 uint32_t pins[16]; 59} resource_irq_t; 60 61static bool resource_is_memory(ACPI_RESOURCE* res) { 62 return res->Type == ACPI_RESOURCE_TYPE_MEMORY24 || 63 res->Type == ACPI_RESOURCE_TYPE_MEMORY32|| 64 res->Type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32; 65} 66 67static bool resource_is_address(ACPI_RESOURCE* res) { 68 return res->Type == ACPI_RESOURCE_TYPE_ADDRESS16 || 69 res->Type == ACPI_RESOURCE_TYPE_ADDRESS32 || 70 res->Type == ACPI_RESOURCE_TYPE_ADDRESS64 || 71 res->Type == ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64; 72} 73 74static bool resource_is_io(ACPI_RESOURCE* res) { 75 return res->Type == ACPI_RESOURCE_TYPE_IO || 76 res->Type == ACPI_RESOURCE_TYPE_FIXED_IO; 77} 78 79static bool resource_is_irq(ACPI_RESOURCE* res) { 80 return res->Type == ACPI_RESOURCE_TYPE_IRQ || 81 res->Type == ACPI_RESOURCE_TYPE_EXTENDED_IRQ; 82} 83 84zx_status_t resource_parse_memory(ACPI_RESOURCE* res, resource_memory_t* out); 85zx_status_t resource_parse_address(ACPI_RESOURCE* res, resource_address_t* out); 86zx_status_t resource_parse_io(ACPI_RESOURCE* res, resource_io_t* out); 87zx_status_t resource_parse_irq(ACPI_RESOURCE* res, resource_irq_t* out); 88