1 /* 2 * ACPI PCI Hot Plug Controller Driver 3 * 4 * Copyright (C) 1995,2001 Compaq Computer Corporation 5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) 6 * Copyright (C) 2001 IBM Corp. 7 * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) 8 * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) 9 * Copyright (C) 2002,2003 NEC Corporation 10 * 11 * All rights reserved. 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or (at 16 * your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, but 19 * WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 21 * NON INFRINGEMENT. See the GNU General Public License for more 22 * details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software 26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 * 28 * Send feedback to <gregkh@us.ibm.com>, 29 * <t-kochi@bq.jp.nec.com> 30 * 31 */ 32 33 #ifndef _ACPIPHP_H 34 #define _ACPIPHP_H 35 36 #include <linux/acpi.h> 37 #include <linux/kobject.h> /* for KOBJ_NAME_LEN */ 38 #include "pci_hotplug.h" 39 40 #define dbg(format, arg...) \ 41 do { \ 42 if (acpiphp_debug) \ 43 printk(KERN_DEBUG "%s: " format, \ 44 MY_NAME , ## arg); \ 45 } while (0) 46 #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg) 47 #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 48 #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 49 50 /* name size which is used for entries in pcihpfs */ 51 #define SLOT_NAME_SIZE KOBJ_NAME_LEN /* {_SUN} */ 52 53 struct acpiphp_bridge; 54 struct acpiphp_slot; 55 struct pci_resource; 56 57 /* 58 * struct slot - slot information for each *physical* slot 59 */ 60 struct slot { 61 u8 number; 62 struct hotplug_slot *hotplug_slot; 63 struct list_head slot_list; 64 65 struct acpiphp_slot *acpi_slot; 66 }; 67 68 /* 69 * struct pci_resource - describes pci resource (mem, pfmem, io, bus) 70 */ 71 struct pci_resource { 72 struct pci_resource * next; 73 u64 base; 74 u32 length; 75 }; 76 77 /** 78 * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters 79 * @cache_line_size in DWORD 80 * @latency_timer in PCI clock 81 * @enable_SERR 0 or 1 82 * @enable_PERR 0 or 1 83 */ 84 struct hpp_param { 85 u8 cache_line_size; 86 u8 latency_timer; 87 u8 enable_SERR; 88 u8 enable_PERR; 89 }; 90 91 92 /** 93 * struct acpiphp_bridge - PCI bridge information 94 * 95 * for each bridge device in ACPI namespace 96 */ 97 struct acpiphp_bridge { 98 struct list_head list; 99 acpi_handle handle; 100 struct acpiphp_slot *slots; 101 int type; 102 int nr_slots; 103 104 u8 seg; 105 u8 bus; 106 u8 sub; 107 108 u32 flags; 109 110 /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */ 111 struct pci_bus *pci_bus; 112 113 /* PCI-to-PCI bridge device */ 114 struct pci_dev *pci_dev; 115 116 /* ACPI 2.0 _HPP parameters */ 117 struct hpp_param hpp; 118 119 spinlock_t res_lock; 120 121 /* available resources on this bus */ 122 struct pci_resource *mem_head; 123 struct pci_resource *p_mem_head; 124 struct pci_resource *io_head; 125 struct pci_resource *bus_head; 126 }; 127 128 129 /** 130 * struct acpiphp_slot - PCI slot information 131 * 132 * PCI slot information for each *physical* PCI slot 133 */ 134 struct acpiphp_slot { 135 struct acpiphp_slot *next; 136 struct acpiphp_bridge *bridge; /* parent */ 137 struct list_head funcs; /* one slot may have different 138 objects (i.e. for each function) */ 139 struct semaphore crit_sect; 140 141 u32 id; /* slot id (serial #) for hotplug core */ 142 u8 device; /* pci device# */ 143 144 u32 sun; /* ACPI _SUN (slot unique number) */ 145 u32 slotno; /* slot number relative to bridge */ 146 u32 flags; /* see below */ 147 }; 148 149 150 /** 151 * struct acpiphp_func - PCI function information 152 * 153 * PCI function information for each object in ACPI namespace 154 * typically 8 objects per slot (i.e. for each PCI function) 155 */ 156 struct acpiphp_func { 157 struct acpiphp_slot *slot; /* parent */ 158 159 struct list_head sibling; 160 struct pci_dev *pci_dev; 161 162 acpi_handle handle; 163 164 u8 function; /* pci function# */ 165 u32 flags; /* see below */ 166 167 /* resources used for this function */ 168 struct pci_resource *mem_head; 169 struct pci_resource *p_mem_head; 170 struct pci_resource *io_head; 171 struct pci_resource *bus_head; 172 }; 173 174 /** 175 * struct acpiphp_attention_info - device specific attention registration 176 * 177 * ACPI has no generic method of setting/getting attention status 178 * this allows for device specific driver registration 179 */ 180 struct acpiphp_attention_info 181 { 182 int (*set_attn)(struct hotplug_slot *slot, u8 status); 183 int (*get_attn)(struct hotplug_slot *slot, u8 *status); 184 struct module *owner; 185 }; 186 187 /* PCI bus bridge HID */ 188 #define ACPI_PCI_HOST_HID "PNP0A03" 189 190 /* PCI BRIDGE type */ 191 #define BRIDGE_TYPE_HOST 0 192 #define BRIDGE_TYPE_P2P 1 193 194 /* ACPI _STA method value (ignore bit 4; battery present) */ 195 #define ACPI_STA_PRESENT (0x00000001) 196 #define ACPI_STA_ENABLED (0x00000002) 197 #define ACPI_STA_SHOW_IN_UI (0x00000004) 198 #define ACPI_STA_FUNCTIONING (0x00000008) 199 #define ACPI_STA_ALL (0x0000000f) 200 201 /* bridge flags */ 202 #define BRIDGE_HAS_STA (0x00000001) 203 #define BRIDGE_HAS_EJ0 (0x00000002) 204 #define BRIDGE_HAS_HPP (0x00000004) 205 #define BRIDGE_HAS_PS0 (0x00000010) 206 #define BRIDGE_HAS_PS1 (0x00000020) 207 #define BRIDGE_HAS_PS2 (0x00000040) 208 #define BRIDGE_HAS_PS3 (0x00000080) 209 210 /* slot flags */ 211 212 #define SLOT_POWEREDON (0x00000001) 213 #define SLOT_ENABLED (0x00000002) 214 #define SLOT_MULTIFUNCTION (0x00000004) 215 216 /* function flags */ 217 218 #define FUNC_HAS_STA (0x00000001) 219 #define FUNC_HAS_EJ0 (0x00000002) 220 #define FUNC_HAS_PS0 (0x00000010) 221 #define FUNC_HAS_PS1 (0x00000020) 222 #define FUNC_HAS_PS2 (0x00000040) 223 #define FUNC_HAS_PS3 (0x00000080) 224 225 /* function prototypes */ 226 227 /* acpiphp_core.c */ 228 extern int acpiphp_register_attention(struct acpiphp_attention_info*info); 229 extern int acpiphp_unregister_attention(struct acpiphp_attention_info *info); 230 231 /* acpiphp_glue.c */ 232 extern int acpiphp_glue_init (void); 233 extern void acpiphp_glue_exit (void); 234 extern int acpiphp_get_num_slots (void); 235 extern struct acpiphp_slot *get_slot_from_id (int id); 236 typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data); 237 238 extern int acpiphp_enable_slot (struct acpiphp_slot *slot); 239 extern int acpiphp_disable_slot (struct acpiphp_slot *slot); 240 extern u8 acpiphp_get_power_status (struct acpiphp_slot *slot); 241 extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot); 242 extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); 243 extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 244 extern u32 acpiphp_get_address (struct acpiphp_slot *slot); 245 246 /* acpiphp_pci.c */ 247 extern struct pci_dev *acpiphp_allocate_pcidev (struct pci_bus *pbus, int dev, int fn); 248 extern int acpiphp_configure_slot (struct acpiphp_slot *slot); 249 extern int acpiphp_configure_function (struct acpiphp_func *func); 250 extern void acpiphp_unconfigure_function (struct acpiphp_func *func); 251 extern int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge); 252 extern int acpiphp_init_func_resource (struct acpiphp_func *func); 253 254 /* acpiphp_res.c */ 255 extern struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size); 256 extern struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size); 257 extern struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size); 258 extern int acpiphp_resource_sort_and_combine (struct pci_resource **head); 259 extern struct pci_resource *acpiphp_make_resource (u64 base, u32 length); 260 extern void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to); 261 extern void acpiphp_free_resource (struct pci_resource **res); 262 extern void acpiphp_dump_resource (struct acpiphp_bridge *bridge); /* debug */ 263 extern void acpiphp_dump_func_resource (struct acpiphp_func *func); /* debug */ 264 265 /* variables */ 266 extern int acpiphp_debug; 267 268 #endif /* _ACPIPHP_H */ 269