1*b72d5b75SMichael Corcoran /* 2*b72d5b75SMichael Corcoran * CDDL HEADER START 3*b72d5b75SMichael Corcoran * 4*b72d5b75SMichael Corcoran * The contents of this file are subject to the terms of the 5*b72d5b75SMichael Corcoran * Common Development and Distribution License (the "License"). 6*b72d5b75SMichael Corcoran * You may not use this file except in compliance with the License. 7*b72d5b75SMichael Corcoran * 8*b72d5b75SMichael Corcoran * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*b72d5b75SMichael Corcoran * or http://www.opensolaris.org/os/licensing. 10*b72d5b75SMichael Corcoran * See the License for the specific language governing permissions 11*b72d5b75SMichael Corcoran * and limitations under the License. 12*b72d5b75SMichael Corcoran * 13*b72d5b75SMichael Corcoran * When distributing Covered Code, include this CDDL HEADER in each 14*b72d5b75SMichael Corcoran * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*b72d5b75SMichael Corcoran * If applicable, add the following below this CDDL HEADER, with the 16*b72d5b75SMichael Corcoran * fields enclosed by brackets "[]" replaced with your own identifying 17*b72d5b75SMichael Corcoran * information: Portions Copyright [yyyy] [name of copyright owner] 18*b72d5b75SMichael Corcoran * 19*b72d5b75SMichael Corcoran * CDDL HEADER END 20*b72d5b75SMichael Corcoran */ 21*b72d5b75SMichael Corcoran 22*b72d5b75SMichael Corcoran /* 23*b72d5b75SMichael Corcoran * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*b72d5b75SMichael Corcoran * Use is subject to license terms. 25*b72d5b75SMichael Corcoran */ 26*b72d5b75SMichael Corcoran /* 27*b72d5b75SMichael Corcoran * Copyright (c) 2009, Intel Corporation. 28*b72d5b75SMichael Corcoran * All rights reserved. 29*b72d5b75SMichael Corcoran */ 30*b72d5b75SMichael Corcoran 31*b72d5b75SMichael Corcoran #ifndef _SYS_ACPIDEV_RSC_H 32*b72d5b75SMichael Corcoran #define _SYS_ACPIDEV_RSC_H 33*b72d5b75SMichael Corcoran #include <sys/types.h> 34*b72d5b75SMichael Corcoran #include <sys/obpdefs.h> 35*b72d5b75SMichael Corcoran #include <sys/sunddi.h> 36*b72d5b75SMichael Corcoran #include <sys/acpi/acpi.h> 37*b72d5b75SMichael Corcoran #include <sys/acpica.h> 38*b72d5b75SMichael Corcoran 39*b72d5b75SMichael Corcoran #ifdef __cplusplus 40*b72d5b75SMichael Corcoran extern "C" { 41*b72d5b75SMichael Corcoran #endif 42*b72d5b75SMichael Corcoran 43*b72d5b75SMichael Corcoran /* ACPI bus range structure. */ 44*b72d5b75SMichael Corcoran typedef struct acpidev_bus_range { 45*b72d5b75SMichael Corcoran uint_t bus_start; 46*b72d5b75SMichael Corcoran uint_t bus_end; 47*b72d5b75SMichael Corcoran } acpidev_bus_range_t; 48*b72d5b75SMichael Corcoran 49*b72d5b75SMichael Corcoran /* 50*b72d5b75SMichael Corcoran * This structure is modeled after the 1275 "reg" property and 51*b72d5b75SMichael Corcoran * "assigned-addresses" property for PCI device nodes. 52*b72d5b75SMichael Corcoran * There's no standard definition available for ACPI devices. 53*b72d5b75SMichael Corcoran * This structure is used to store resources returned by the ACPI 54*b72d5b75SMichael Corcoran * _CRS method. 55*b72d5b75SMichael Corcoran * 56*b72d5b75SMichael Corcoran * The physical address format is: 57*b72d5b75SMichael Corcoran * Bit#: 33222222 22221111 11111100 00000000 58*b72d5b75SMichael Corcoran * 10987654 32109876 54321098 76543210 59*b72d5b75SMichael Corcoran * phys_hi cell: xxxxxxxx xxxxxxxx xxxxxxxx TSxxxTTT 60*b72d5b75SMichael Corcoran * phys_hi(memory): xxxxxxxx xxxxxxxx wxxxxxcc --xxx000 61*b72d5b75SMichael Corcoran * phys_hi(io): xxxxxxxx xxxxxxxx sdxxxxaa --xxx001 62*b72d5b75SMichael Corcoran * phys_mid cell: hhhhhhhh hhhhhhhh hhhhhhhh hhhhhhhh 63*b72d5b75SMichael Corcoran * phys_low cell: llllllll llllllll llllllll llllllll 64*b72d5b75SMichael Corcoran * 65*b72d5b75SMichael Corcoran * TTT is type of resource. Such as MEMORY, IO etc. 66*b72d5b75SMichael Corcoran * S is 1 if address range is subtractive decoding 67*b72d5b75SMichael Corcoran * T is 1 if resource type is different on primary and 68*b72d5b75SMichael Corcoran * secondary bus 69*b72d5b75SMichael Corcoran * cc is memory coherence type 70*b72d5b75SMichael Corcoran * w is 1 if memory is writable 71*b72d5b75SMichael Corcoran * aa ranges of decoded ports, ISA only, non-ISA only or full. 72*b72d5b75SMichael Corcoran * d is 1 if IO port decode 16 bit address, otherwise 10 bits. 73*b72d5b75SMichael Corcoran * s is 1 if translation is sparse. 74*b72d5b75SMichael Corcoran * hh...hhh is the 32-bit unsigned number 75*b72d5b75SMichael Corcoran * ll...lll is the 32-bit unsigned number 76*b72d5b75SMichael Corcoran * 77*b72d5b75SMichael Corcoran * The physical size format is: 78*b72d5b75SMichael Corcoran * 79*b72d5b75SMichael Corcoran * size_hi cell: hhhhhhhh hhhhhhhh hhhhhhhh hhhhhhhh 80*b72d5b75SMichael Corcoran * size_low cell: llllllll llllllll llllllll llllllll 81*b72d5b75SMichael Corcoran * 82*b72d5b75SMichael Corcoran * hh...hhh is the 32-bit unsigned number 83*b72d5b75SMichael Corcoran * ll...lll is the 32-bit unsigned number 84*b72d5b75SMichael Corcoran */ 85*b72d5b75SMichael Corcoran typedef struct acpidev_phys_spec { 86*b72d5b75SMichael Corcoran uint_t phys_hi; /* resource address, hi word */ 87*b72d5b75SMichael Corcoran uint_t phys_mid; /* resource address, middle word */ 88*b72d5b75SMichael Corcoran uint_t phys_low; /* resource address, low word */ 89*b72d5b75SMichael Corcoran uint_t size_hi; /* high word of size field */ 90*b72d5b75SMichael Corcoran uint_t size_low; /* low word of size field */ 91*b72d5b75SMichael Corcoran } acpidev_phys_spec_t; 92*b72d5b75SMichael Corcoran 93*b72d5b75SMichael Corcoran typedef struct acpidev_phys_spec acpidev_regspec_t; 94*b72d5b75SMichael Corcoran 95*b72d5b75SMichael Corcoran #define ACPIDEV_REG_TYPE_M 0x00000007 96*b72d5b75SMichael Corcoran #define ACPIDEV_REG_TYPE_MEMORY 0x00000000 97*b72d5b75SMichael Corcoran #define ACPIDEV_REG_TYPE_IO 0x00000001 98*b72d5b75SMichael Corcoran #define ACPIDEV_REG_SUB_DEC 0x00000040 99*b72d5b75SMichael Corcoran #define ACPIDEV_REG_TRANSLATED 0x00000080 100*b72d5b75SMichael Corcoran 101*b72d5b75SMichael Corcoran #define ACPIDEV_REG_MEM_COHERENT_M 0x00000300 102*b72d5b75SMichael Corcoran #define ACPIDEV_REG_MEM_COHERENT_NC 0x00000000 /* Non-cachable */ 103*b72d5b75SMichael Corcoran #define ACPIDEV_REG_MEM_COHERENT_CA 0x00000100 /* Cachable */ 104*b72d5b75SMichael Corcoran #define ACPIDEV_REG_MEM_COHERENT_WC 0x00000200 /* Write-combining */ 105*b72d5b75SMichael Corcoran #define ACPIDEV_REG_MEM_COHERENT_PF 0x00000300 /* Prefectable */ 106*b72d5b75SMichael Corcoran #define ACPIDEV_REG_MEM_WRITABLE 0x00008000 /* Writable */ 107*b72d5b75SMichael Corcoran 108*b72d5b75SMichael Corcoran #define ACPIDEV_REG_IO_RANGE_M 0x00000300 109*b72d5b75SMichael Corcoran #define ACPIDEV_REG_IO_RANGE_NONISA 0x00000100 110*b72d5b75SMichael Corcoran #define ACPIDEV_REG_IO_RANGE_ISA 0x00000200 111*b72d5b75SMichael Corcoran #define ACPIDEV_REG_IO_RANGE_FULL 0x00000300 112*b72d5b75SMichael Corcoran #define ACPIDEV_REG_IO_DECODE16 0x00004000 /* Decode 16bit addr. */ 113*b72d5b75SMichael Corcoran #define ACPIDEV_REG_IO_SPARSE 0x00008000 /* Sparse translation. */ 114*b72d5b75SMichael Corcoran 115*b72d5b75SMichael Corcoran typedef struct acpidev_ranges { 116*b72d5b75SMichael Corcoran uint_t child_hi; /* child's address, hi word */ 117*b72d5b75SMichael Corcoran uint_t child_mid; /* child's address, middle word */ 118*b72d5b75SMichael Corcoran uint_t child_low; /* child's address, low word */ 119*b72d5b75SMichael Corcoran uint_t parent_hi; /* parent's address, hi word */ 120*b72d5b75SMichael Corcoran uint_t parent_mid; /* parent's address, middle word */ 121*b72d5b75SMichael Corcoran uint_t parent_low; /* parent's address, low word */ 122*b72d5b75SMichael Corcoran uint_t size_hi; /* high word of size field */ 123*b72d5b75SMichael Corcoran uint_t size_low; /* low word of size field */ 124*b72d5b75SMichael Corcoran } acpidev_ranges_t; 125*b72d5b75SMichael Corcoran 126*b72d5b75SMichael Corcoran #ifdef _KERNEL 127*b72d5b75SMichael Corcoran 128*b72d5b75SMichael Corcoran /* Maximum possible number of IRQs. */ 129*b72d5b75SMichael Corcoran #define ACPIDEV_RES_IRQ_MAX 16 130*b72d5b75SMichael Corcoran /* Maximum possible number of DMAs. */ 131*b72d5b75SMichael Corcoran #define ACPIDEV_RES_DMA_MAX 8 132*b72d5b75SMichael Corcoran 133*b72d5b75SMichael Corcoran /* Forward declaration */ 134*b72d5b75SMichael Corcoran typedef struct acpidev_resource_handle *acpidev_resource_handle_t; 135*b72d5b75SMichael Corcoran 136*b72d5b75SMichael Corcoran /* 137*b72d5b75SMichael Corcoran * Resource handler relative interfaces. 138*b72d5b75SMichael Corcoran * Return values of acpidev_resource_get_xxx interfaces: 139*b72d5b75SMichael Corcoran * AE_OK: succeed with resources stored in buffer and count updated. 140*b72d5b75SMichael Corcoran * AE_LIMIT: buffer is too small, count updated to number of resources. 141*b72d5b75SMichael Corcoran * AE_BAD_PARAMETER: invalid parameter 142*b72d5b75SMichael Corcoran */ 143*b72d5b75SMichael Corcoran extern acpidev_resource_handle_t acpidev_resource_handle_alloc( 144*b72d5b75SMichael Corcoran boolean_t consumer); 145*b72d5b75SMichael Corcoran extern void acpidev_resource_handle_free(acpidev_resource_handle_t rhdl); 146*b72d5b75SMichael Corcoran 147*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_insert_reg(acpidev_resource_handle_t rhdl, 148*b72d5b75SMichael Corcoran acpidev_regspec_t *regp); 149*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_get_regs(acpidev_resource_handle_t rhdl, 150*b72d5b75SMichael Corcoran uint_t mask, uint_t value, acpidev_regspec_t *regp, uint_t *cntp); 151*b72d5b75SMichael Corcoran extern uint_t acpidev_resource_get_reg_count(acpidev_resource_handle_t rhdl, 152*b72d5b75SMichael Corcoran uint_t mask, uint_t value); 153*b72d5b75SMichael Corcoran 154*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_insert_range(acpidev_resource_handle_t rhdl, 155*b72d5b75SMichael Corcoran acpidev_ranges_t *rangep); 156*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_get_ranges(acpidev_resource_handle_t rhdl, 157*b72d5b75SMichael Corcoran uint_t mask, uint_t value, acpidev_ranges_t *rangep, uint_t *cntp); 158*b72d5b75SMichael Corcoran extern uint_t acpidev_resource_get_range_count(acpidev_resource_handle_t rhdl, 159*b72d5b75SMichael Corcoran uint_t mask, uint_t value); 160*b72d5b75SMichael Corcoran 161*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_insert_bus(acpidev_resource_handle_t rhdl, 162*b72d5b75SMichael Corcoran acpidev_bus_range_t *busp); 163*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_get_buses(acpidev_resource_handle_t rhdl, 164*b72d5b75SMichael Corcoran acpidev_bus_range_t *busp, uint_t *cntp); 165*b72d5b75SMichael Corcoran extern uint_t acpidev_resource_get_bus_count(acpidev_resource_handle_t rhdl); 166*b72d5b75SMichael Corcoran 167*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_insert_dma(acpidev_resource_handle_t rhdl, 168*b72d5b75SMichael Corcoran int dma); 169*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_get_dmas(acpidev_resource_handle_t rhdl, 170*b72d5b75SMichael Corcoran uint_t *dmap, uint_t *cntp); 171*b72d5b75SMichael Corcoran extern uint_t acpidev_resource_get_dma_count(acpidev_resource_handle_t rhdl); 172*b72d5b75SMichael Corcoran 173*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_insert_irq(acpidev_resource_handle_t rhdl, 174*b72d5b75SMichael Corcoran int irq); 175*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_get_irqs(acpidev_resource_handle_t rhdl, 176*b72d5b75SMichael Corcoran uint_t *irqp, uint_t *cntp); 177*b72d5b75SMichael Corcoran extern uint_t acpidev_resource_get_irq_count(acpidev_resource_handle_t rhdl); 178*b72d5b75SMichael Corcoran 179*b72d5b75SMichael Corcoran /* 180*b72d5b75SMichael Corcoran * Walk resources returned by 'method' and store parsed resources into rhdlp. 181*b72d5b75SMichael Corcoran * Caller needs to release rhdlp after using it. 182*b72d5b75SMichael Corcoran * Return AE_OK on success with resource handle stored in 'rhdlp'. 183*b72d5b75SMichael Corcoran */ 184*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_walk(ACPI_HANDLE hdl, char *method, 185*b72d5b75SMichael Corcoran boolean_t consumer, acpidev_resource_handle_t *rhdlp); 186*b72d5b75SMichael Corcoran 187*b72d5b75SMichael Corcoran /* 188*b72d5b75SMichael Corcoran * Walk resources returned by the ACPI _CRS method and create device properties. 189*b72d5b75SMichael Corcoran * Create 'reg', 'assigned-addresses', 'dma-channels' and 'interrupts' 190*b72d5b75SMichael Corcoran * properties for resource consumer. 191*b72d5b75SMichael Corcoran * Create 'ranges' and 'bus-range' properties for resource producer. 192*b72d5b75SMichael Corcoran */ 193*b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_resource_process(acpidev_walk_info_t *infop, 194*b72d5b75SMichael Corcoran boolean_t consumer); 195*b72d5b75SMichael Corcoran 196*b72d5b75SMichael Corcoran #endif /* _KERNEL */ 197*b72d5b75SMichael Corcoran 198*b72d5b75SMichael Corcoran #ifdef __cplusplus 199*b72d5b75SMichael Corcoran } 200*b72d5b75SMichael Corcoran #endif 201*b72d5b75SMichael Corcoran 202*b72d5b75SMichael Corcoran #endif /* _SYS_ACPIDEV_RSC_H */ 203