1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright (c) 2010, Intel Corporation.
  27  * All rights reserved.
  28  */
  29 
  30 #ifndef _SYS_DRMACH_ACPI_H
  31 #define _SYS_DRMACH_ACPI_H
  32 #include <sys/types.h>
  33 #include <sys/cmn_err.h>
  34 #include <sys/param.h>
  35 #include <sys/sunddi.h>
  36 #include <acpica/include/acpi.h>
  37 #include <sys/acpica.h>
  38 #include <sys/acpidev.h>
  39 #include <sys/drmach.h>
  40 
  41 #ifdef __cplusplus
  42 extern "C" {
  43 #endif
  44 
  45 #ifdef  _KERNEL
  46 
  47 /* Use ACPI handle as DRMACH handle on x86 systems. */
  48 #define DRMACH_HANDLE           ACPI_HANDLE
  49 
  50 /* Macros to deal with object type. */
  51 #define DRMACH_OBJ(id)          ((drmach_common_t *)id)
  52 
  53 #define DRMACH_NULL_ID(id)      ((id) == 0)
  54 
  55 #define DRMACH_IS_BOARD_ID(id)  \
  56         ((id != 0) && (DRMACH_OBJ(id)->isa == (void *)drmach_board_new))
  57 
  58 #define DRMACH_IS_CPU_ID(id)    \
  59         ((id != 0) && (DRMACH_OBJ(id)->isa == (void *)drmach_cpu_new))
  60 
  61 #define DRMACH_IS_MEM_ID(id)    \
  62         ((id != 0) && (DRMACH_OBJ(id)->isa == (void *)drmach_mem_new))
  63 
  64 #define DRMACH_IS_IO_ID(id)     \
  65         ((id != 0) && (DRMACH_OBJ(id)->isa == (void *)drmach_io_new))
  66 
  67 #define DRMACH_IS_DEVICE_ID(id)                                 \
  68         ((id != 0) &&                                           \
  69         (DRMACH_OBJ(id)->isa == (void *)drmach_cpu_new ||    \
  70             DRMACH_OBJ(id)->isa == (void *)drmach_mem_new || \
  71             DRMACH_OBJ(id)->isa == (void *)drmach_io_new))
  72 
  73 #define DRMACH_IS_ID(id)                                        \
  74         ((id != 0) &&                                           \
  75         (DRMACH_OBJ(id)->isa == (void *)drmach_board_new ||  \
  76             DRMACH_OBJ(id)->isa == (void *)drmach_cpu_new || \
  77             DRMACH_OBJ(id)->isa == (void *)drmach_mem_new || \
  78             DRMACH_OBJ(id)->isa == (void *)drmach_io_new))
  79 
  80 #define DRMACH_INTERNAL_ERROR() \
  81         drerr_new(1, EX86_INTERNAL, drmach_ie_fmt, __LINE__)
  82 
  83 #ifdef DEBUG
  84 extern int drmach_debug;
  85 
  86 #define DRMACH_PR               if (drmach_debug) printf
  87 #else
  88 #define DRMACH_PR               _NOTE(CONSTANTCONDITION) if (0) printf
  89 #endif /* DEBUG */
  90 
  91 typedef struct {
  92         struct drmach_node      *node;
  93         void                    *data;
  94         void                    *func;
  95 } drmach_node_walk_args_t;
  96 
  97 typedef struct drmach_node {
  98         void            *here;
  99 
 100         DRMACH_HANDLE   (*get_dnode)(struct drmach_node *node);
 101         dev_info_t      *(*getdip)(struct drmach_node *node);
 102         int             (*getproplen)(struct drmach_node *node, char *name,
 103                                 int *len);
 104         int             (*getprop)(struct drmach_node *node, char *name,
 105                                 void *buf, int len);
 106         int             (*walk)(struct drmach_node *node, void *data,
 107                                 int (*cb)(drmach_node_walk_args_t *args));
 108 } drmach_node_t;
 109 
 110 typedef struct {
 111         int              min_index;
 112         int              max_index;
 113         int              arr_sz;
 114         drmachid_t      *arr;
 115 } drmach_array_t;
 116 
 117 typedef struct {
 118         void            *isa;
 119 
 120         void            (*dispose)(drmachid_t);
 121         sbd_error_t     *(*release)(drmachid_t);
 122         sbd_error_t     *(*status)(drmachid_t, drmach_status_t *);
 123 
 124         char             name[MAXNAMELEN];
 125 } drmach_common_t;
 126 
 127 typedef struct {
 128         drmach_common_t  cm;
 129         uint_t           bnum;
 130         int              assigned;
 131         int              powered;
 132         int              connected;
 133         int              cond;
 134         drmach_node_t   *tree;
 135         drmach_array_t  *devices;
 136         int              boot_board;    /* if board exists on bootup */
 137 } drmach_board_t;
 138 
 139 typedef struct {
 140         drmach_common_t  cm;
 141         drmach_board_t  *bp;
 142         int              unum;
 143         uint_t           portid;
 144         int              busy;
 145         int              powered;
 146         const char      *type;
 147         drmach_node_t   *node;
 148 } drmach_device_t;
 149 
 150 typedef struct drmach_cpu {
 151         drmach_device_t  dev;
 152         processorid_t    cpuid;
 153         uint32_t         apicid;
 154 } drmach_cpu_t;
 155 
 156 typedef struct drmach_mem {
 157         drmach_device_t dev;
 158         uint64_t        mem_alignment;
 159         uint64_t        slice_base;
 160         uint64_t        slice_top;
 161         uint64_t        slice_size;
 162         uint64_t        base_pa;        /* lowest installed memory base */
 163         uint64_t        nbytes;         /* size of installed memory */
 164         struct memlist *memlist;
 165 } drmach_mem_t;
 166 
 167 typedef struct drmach_io {
 168         drmach_device_t  dev;
 169 } drmach_io_t;
 170 
 171 typedef struct drmach_domain_info {
 172         uint64_t        floating;
 173         int             allow_dr;
 174 } drmach_domain_info_t;
 175 
 176 typedef struct {
 177         drmach_board_t  *obj;
 178         int              ndevs;
 179         void            *a;
 180         sbd_error_t     *(*found)(void *a, const char *, int, drmachid_t);
 181         sbd_error_t     *err;
 182 } drmach_board_cb_data_t;
 183 
 184 extern drmach_domain_info_t drmach_domain;
 185 
 186 extern drmach_board_t   *drmach_board_new(uint_t, int);
 187 extern sbd_error_t      *drmach_device_new(drmach_node_t *,
 188                                 drmach_board_t *, int, drmachid_t *);
 189 extern sbd_error_t      *drmach_cpu_new(drmach_device_t *, drmachid_t *);
 190 extern sbd_error_t      *drmach_mem_new(drmach_device_t *, drmachid_t *);
 191 extern sbd_error_t      *drmach_io_new(drmach_device_t *, drmachid_t *);
 192 
 193 #endif  /* _KERNEL */
 194 
 195 #ifdef __cplusplus
 196 }
 197 #endif
 198 
 199 #endif  /* _SYS_DRMACH_ACPI_H */