18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Compaq Hot Plug Controller Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 1995,2001 Compaq Computer Corporation 68c2ecf20Sopenharmony_ci * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com) 78c2ecf20Sopenharmony_ci * Copyright (C) 2001 IBM 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * All rights reserved. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Send feedback to <greg@kroah.com> 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci#ifndef _CPQPHP_H 158c2ecf20Sopenharmony_ci#define _CPQPHP_H 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 188c2ecf20Sopenharmony_ci#include <asm/io.h> /* for read? and write? functions */ 198c2ecf20Sopenharmony_ci#include <linux/delay.h> /* for delays */ 208c2ecf20Sopenharmony_ci#include <linux/mutex.h> 218c2ecf20Sopenharmony_ci#include <linux/sched/signal.h> /* for signal_pending() */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define MY_NAME "cpqphp" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define dbg(fmt, arg...) do { if (cpqhp_debug) printk(KERN_DEBUG "%s: " fmt, MY_NAME, ## arg); } while (0) 268c2ecf20Sopenharmony_ci#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME, ## arg) 278c2ecf20Sopenharmony_ci#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME, ## arg) 288c2ecf20Sopenharmony_ci#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME, ## arg) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct smbios_system_slot { 338c2ecf20Sopenharmony_ci u8 type; 348c2ecf20Sopenharmony_ci u8 length; 358c2ecf20Sopenharmony_ci u16 handle; 368c2ecf20Sopenharmony_ci u8 name_string_num; 378c2ecf20Sopenharmony_ci u8 slot_type; 388c2ecf20Sopenharmony_ci u8 slot_width; 398c2ecf20Sopenharmony_ci u8 slot_current_usage; 408c2ecf20Sopenharmony_ci u8 slot_length; 418c2ecf20Sopenharmony_ci u16 slot_number; 428c2ecf20Sopenharmony_ci u8 properties1; 438c2ecf20Sopenharmony_ci u8 properties2; 448c2ecf20Sopenharmony_ci} __attribute__ ((packed)); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* offsets to the smbios generic type based on the above structure layout */ 478c2ecf20Sopenharmony_cienum smbios_system_slot_offsets { 488c2ecf20Sopenharmony_ci SMBIOS_SLOT_GENERIC_TYPE = offsetof(struct smbios_system_slot, type), 498c2ecf20Sopenharmony_ci SMBIOS_SLOT_GENERIC_LENGTH = offsetof(struct smbios_system_slot, length), 508c2ecf20Sopenharmony_ci SMBIOS_SLOT_GENERIC_HANDLE = offsetof(struct smbios_system_slot, handle), 518c2ecf20Sopenharmony_ci SMBIOS_SLOT_NAME_STRING_NUM = offsetof(struct smbios_system_slot, name_string_num), 528c2ecf20Sopenharmony_ci SMBIOS_SLOT_TYPE = offsetof(struct smbios_system_slot, slot_type), 538c2ecf20Sopenharmony_ci SMBIOS_SLOT_WIDTH = offsetof(struct smbios_system_slot, slot_width), 548c2ecf20Sopenharmony_ci SMBIOS_SLOT_CURRENT_USAGE = offsetof(struct smbios_system_slot, slot_current_usage), 558c2ecf20Sopenharmony_ci SMBIOS_SLOT_LENGTH = offsetof(struct smbios_system_slot, slot_length), 568c2ecf20Sopenharmony_ci SMBIOS_SLOT_NUMBER = offsetof(struct smbios_system_slot, slot_number), 578c2ecf20Sopenharmony_ci SMBIOS_SLOT_PROPERTIES1 = offsetof(struct smbios_system_slot, properties1), 588c2ecf20Sopenharmony_ci SMBIOS_SLOT_PROPERTIES2 = offsetof(struct smbios_system_slot, properties2), 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct smbios_generic { 628c2ecf20Sopenharmony_ci u8 type; 638c2ecf20Sopenharmony_ci u8 length; 648c2ecf20Sopenharmony_ci u16 handle; 658c2ecf20Sopenharmony_ci} __attribute__ ((packed)); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* offsets to the smbios generic type based on the above structure layout */ 688c2ecf20Sopenharmony_cienum smbios_generic_offsets { 698c2ecf20Sopenharmony_ci SMBIOS_GENERIC_TYPE = offsetof(struct smbios_generic, type), 708c2ecf20Sopenharmony_ci SMBIOS_GENERIC_LENGTH = offsetof(struct smbios_generic, length), 718c2ecf20Sopenharmony_ci SMBIOS_GENERIC_HANDLE = offsetof(struct smbios_generic, handle), 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistruct smbios_entry_point { 758c2ecf20Sopenharmony_ci char anchor[4]; 768c2ecf20Sopenharmony_ci u8 ep_checksum; 778c2ecf20Sopenharmony_ci u8 ep_length; 788c2ecf20Sopenharmony_ci u8 major_version; 798c2ecf20Sopenharmony_ci u8 minor_version; 808c2ecf20Sopenharmony_ci u16 max_size_entry; 818c2ecf20Sopenharmony_ci u8 ep_rev; 828c2ecf20Sopenharmony_ci u8 reserved[5]; 838c2ecf20Sopenharmony_ci char int_anchor[5]; 848c2ecf20Sopenharmony_ci u8 int_checksum; 858c2ecf20Sopenharmony_ci u16 st_length; 868c2ecf20Sopenharmony_ci u32 st_address; 878c2ecf20Sopenharmony_ci u16 number_of_entrys; 888c2ecf20Sopenharmony_ci u8 bcd_rev; 898c2ecf20Sopenharmony_ci} __attribute__ ((packed)); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/* offsets to the smbios entry point based on the above structure layout */ 928c2ecf20Sopenharmony_cienum smbios_entry_point_offsets { 938c2ecf20Sopenharmony_ci ANCHOR = offsetof(struct smbios_entry_point, anchor[0]), 948c2ecf20Sopenharmony_ci EP_CHECKSUM = offsetof(struct smbios_entry_point, ep_checksum), 958c2ecf20Sopenharmony_ci EP_LENGTH = offsetof(struct smbios_entry_point, ep_length), 968c2ecf20Sopenharmony_ci MAJOR_VERSION = offsetof(struct smbios_entry_point, major_version), 978c2ecf20Sopenharmony_ci MINOR_VERSION = offsetof(struct smbios_entry_point, minor_version), 988c2ecf20Sopenharmony_ci MAX_SIZE_ENTRY = offsetof(struct smbios_entry_point, max_size_entry), 998c2ecf20Sopenharmony_ci EP_REV = offsetof(struct smbios_entry_point, ep_rev), 1008c2ecf20Sopenharmony_ci INT_ANCHOR = offsetof(struct smbios_entry_point, int_anchor[0]), 1018c2ecf20Sopenharmony_ci INT_CHECKSUM = offsetof(struct smbios_entry_point, int_checksum), 1028c2ecf20Sopenharmony_ci ST_LENGTH = offsetof(struct smbios_entry_point, st_length), 1038c2ecf20Sopenharmony_ci ST_ADDRESS = offsetof(struct smbios_entry_point, st_address), 1048c2ecf20Sopenharmony_ci NUMBER_OF_ENTRYS = offsetof(struct smbios_entry_point, number_of_entrys), 1058c2ecf20Sopenharmony_ci BCD_REV = offsetof(struct smbios_entry_point, bcd_rev), 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct ctrl_reg { /* offset */ 1098c2ecf20Sopenharmony_ci u8 slot_RST; /* 0x00 */ 1108c2ecf20Sopenharmony_ci u8 slot_enable; /* 0x01 */ 1118c2ecf20Sopenharmony_ci u16 misc; /* 0x02 */ 1128c2ecf20Sopenharmony_ci u32 led_control; /* 0x04 */ 1138c2ecf20Sopenharmony_ci u32 int_input_clear; /* 0x08 */ 1148c2ecf20Sopenharmony_ci u32 int_mask; /* 0x0a */ 1158c2ecf20Sopenharmony_ci u8 reserved0; /* 0x10 */ 1168c2ecf20Sopenharmony_ci u8 reserved1; /* 0x11 */ 1178c2ecf20Sopenharmony_ci u8 reserved2; /* 0x12 */ 1188c2ecf20Sopenharmony_ci u8 gen_output_AB; /* 0x13 */ 1198c2ecf20Sopenharmony_ci u32 non_int_input; /* 0x14 */ 1208c2ecf20Sopenharmony_ci u32 reserved3; /* 0x18 */ 1218c2ecf20Sopenharmony_ci u32 reserved4; /* 0x1a */ 1228c2ecf20Sopenharmony_ci u32 reserved5; /* 0x20 */ 1238c2ecf20Sopenharmony_ci u8 reserved6; /* 0x24 */ 1248c2ecf20Sopenharmony_ci u8 reserved7; /* 0x25 */ 1258c2ecf20Sopenharmony_ci u16 reserved8; /* 0x26 */ 1268c2ecf20Sopenharmony_ci u8 slot_mask; /* 0x28 */ 1278c2ecf20Sopenharmony_ci u8 reserved9; /* 0x29 */ 1288c2ecf20Sopenharmony_ci u8 reserved10; /* 0x2a */ 1298c2ecf20Sopenharmony_ci u8 reserved11; /* 0x2b */ 1308c2ecf20Sopenharmony_ci u8 slot_SERR; /* 0x2c */ 1318c2ecf20Sopenharmony_ci u8 slot_power; /* 0x2d */ 1328c2ecf20Sopenharmony_ci u8 reserved12; /* 0x2e */ 1338c2ecf20Sopenharmony_ci u8 reserved13; /* 0x2f */ 1348c2ecf20Sopenharmony_ci u8 next_curr_freq; /* 0x30 */ 1358c2ecf20Sopenharmony_ci u8 reset_freq_mode; /* 0x31 */ 1368c2ecf20Sopenharmony_ci} __attribute__ ((packed)); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* offsets to the controller registers based on the above structure layout */ 1398c2ecf20Sopenharmony_cienum ctrl_offsets { 1408c2ecf20Sopenharmony_ci SLOT_RST = offsetof(struct ctrl_reg, slot_RST), 1418c2ecf20Sopenharmony_ci SLOT_ENABLE = offsetof(struct ctrl_reg, slot_enable), 1428c2ecf20Sopenharmony_ci MISC = offsetof(struct ctrl_reg, misc), 1438c2ecf20Sopenharmony_ci LED_CONTROL = offsetof(struct ctrl_reg, led_control), 1448c2ecf20Sopenharmony_ci INT_INPUT_CLEAR = offsetof(struct ctrl_reg, int_input_clear), 1458c2ecf20Sopenharmony_ci INT_MASK = offsetof(struct ctrl_reg, int_mask), 1468c2ecf20Sopenharmony_ci CTRL_RESERVED0 = offsetof(struct ctrl_reg, reserved0), 1478c2ecf20Sopenharmony_ci CTRL_RESERVED1 = offsetof(struct ctrl_reg, reserved1), 1488c2ecf20Sopenharmony_ci CTRL_RESERVED2 = offsetof(struct ctrl_reg, reserved1), 1498c2ecf20Sopenharmony_ci GEN_OUTPUT_AB = offsetof(struct ctrl_reg, gen_output_AB), 1508c2ecf20Sopenharmony_ci NON_INT_INPUT = offsetof(struct ctrl_reg, non_int_input), 1518c2ecf20Sopenharmony_ci CTRL_RESERVED3 = offsetof(struct ctrl_reg, reserved3), 1528c2ecf20Sopenharmony_ci CTRL_RESERVED4 = offsetof(struct ctrl_reg, reserved4), 1538c2ecf20Sopenharmony_ci CTRL_RESERVED5 = offsetof(struct ctrl_reg, reserved5), 1548c2ecf20Sopenharmony_ci CTRL_RESERVED6 = offsetof(struct ctrl_reg, reserved6), 1558c2ecf20Sopenharmony_ci CTRL_RESERVED7 = offsetof(struct ctrl_reg, reserved7), 1568c2ecf20Sopenharmony_ci CTRL_RESERVED8 = offsetof(struct ctrl_reg, reserved8), 1578c2ecf20Sopenharmony_ci SLOT_MASK = offsetof(struct ctrl_reg, slot_mask), 1588c2ecf20Sopenharmony_ci CTRL_RESERVED9 = offsetof(struct ctrl_reg, reserved9), 1598c2ecf20Sopenharmony_ci CTRL_RESERVED10 = offsetof(struct ctrl_reg, reserved10), 1608c2ecf20Sopenharmony_ci CTRL_RESERVED11 = offsetof(struct ctrl_reg, reserved11), 1618c2ecf20Sopenharmony_ci SLOT_SERR = offsetof(struct ctrl_reg, slot_SERR), 1628c2ecf20Sopenharmony_ci SLOT_POWER = offsetof(struct ctrl_reg, slot_power), 1638c2ecf20Sopenharmony_ci NEXT_CURR_FREQ = offsetof(struct ctrl_reg, next_curr_freq), 1648c2ecf20Sopenharmony_ci RESET_FREQ_MODE = offsetof(struct ctrl_reg, reset_freq_mode), 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistruct hrt { 1688c2ecf20Sopenharmony_ci char sig0; 1698c2ecf20Sopenharmony_ci char sig1; 1708c2ecf20Sopenharmony_ci char sig2; 1718c2ecf20Sopenharmony_ci char sig3; 1728c2ecf20Sopenharmony_ci u16 unused_IRQ; 1738c2ecf20Sopenharmony_ci u16 PCIIRQ; 1748c2ecf20Sopenharmony_ci u8 number_of_entries; 1758c2ecf20Sopenharmony_ci u8 revision; 1768c2ecf20Sopenharmony_ci u16 reserved1; 1778c2ecf20Sopenharmony_ci u32 reserved2; 1788c2ecf20Sopenharmony_ci} __attribute__ ((packed)); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci/* offsets to the hotplug resource table registers based on the above 1818c2ecf20Sopenharmony_ci * structure layout 1828c2ecf20Sopenharmony_ci */ 1838c2ecf20Sopenharmony_cienum hrt_offsets { 1848c2ecf20Sopenharmony_ci SIG0 = offsetof(struct hrt, sig0), 1858c2ecf20Sopenharmony_ci SIG1 = offsetof(struct hrt, sig1), 1868c2ecf20Sopenharmony_ci SIG2 = offsetof(struct hrt, sig2), 1878c2ecf20Sopenharmony_ci SIG3 = offsetof(struct hrt, sig3), 1888c2ecf20Sopenharmony_ci UNUSED_IRQ = offsetof(struct hrt, unused_IRQ), 1898c2ecf20Sopenharmony_ci PCIIRQ = offsetof(struct hrt, PCIIRQ), 1908c2ecf20Sopenharmony_ci NUMBER_OF_ENTRIES = offsetof(struct hrt, number_of_entries), 1918c2ecf20Sopenharmony_ci REVISION = offsetof(struct hrt, revision), 1928c2ecf20Sopenharmony_ci HRT_RESERVED1 = offsetof(struct hrt, reserved1), 1938c2ecf20Sopenharmony_ci HRT_RESERVED2 = offsetof(struct hrt, reserved2), 1948c2ecf20Sopenharmony_ci}; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistruct slot_rt { 1978c2ecf20Sopenharmony_ci u8 dev_func; 1988c2ecf20Sopenharmony_ci u8 primary_bus; 1998c2ecf20Sopenharmony_ci u8 secondary_bus; 2008c2ecf20Sopenharmony_ci u8 max_bus; 2018c2ecf20Sopenharmony_ci u16 io_base; 2028c2ecf20Sopenharmony_ci u16 io_length; 2038c2ecf20Sopenharmony_ci u16 mem_base; 2048c2ecf20Sopenharmony_ci u16 mem_length; 2058c2ecf20Sopenharmony_ci u16 pre_mem_base; 2068c2ecf20Sopenharmony_ci u16 pre_mem_length; 2078c2ecf20Sopenharmony_ci} __attribute__ ((packed)); 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci/* offsets to the hotplug slot resource table registers based on the above 2108c2ecf20Sopenharmony_ci * structure layout 2118c2ecf20Sopenharmony_ci */ 2128c2ecf20Sopenharmony_cienum slot_rt_offsets { 2138c2ecf20Sopenharmony_ci DEV_FUNC = offsetof(struct slot_rt, dev_func), 2148c2ecf20Sopenharmony_ci PRIMARY_BUS = offsetof(struct slot_rt, primary_bus), 2158c2ecf20Sopenharmony_ci SECONDARY_BUS = offsetof(struct slot_rt, secondary_bus), 2168c2ecf20Sopenharmony_ci MAX_BUS = offsetof(struct slot_rt, max_bus), 2178c2ecf20Sopenharmony_ci IO_BASE = offsetof(struct slot_rt, io_base), 2188c2ecf20Sopenharmony_ci IO_LENGTH = offsetof(struct slot_rt, io_length), 2198c2ecf20Sopenharmony_ci MEM_BASE = offsetof(struct slot_rt, mem_base), 2208c2ecf20Sopenharmony_ci MEM_LENGTH = offsetof(struct slot_rt, mem_length), 2218c2ecf20Sopenharmony_ci PRE_MEM_BASE = offsetof(struct slot_rt, pre_mem_base), 2228c2ecf20Sopenharmony_ci PRE_MEM_LENGTH = offsetof(struct slot_rt, pre_mem_length), 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistruct pci_func { 2268c2ecf20Sopenharmony_ci struct pci_func *next; 2278c2ecf20Sopenharmony_ci u8 bus; 2288c2ecf20Sopenharmony_ci u8 device; 2298c2ecf20Sopenharmony_ci u8 function; 2308c2ecf20Sopenharmony_ci u8 is_a_board; 2318c2ecf20Sopenharmony_ci u16 status; 2328c2ecf20Sopenharmony_ci u8 configured; 2338c2ecf20Sopenharmony_ci u8 switch_save; 2348c2ecf20Sopenharmony_ci u8 presence_save; 2358c2ecf20Sopenharmony_ci u32 base_length[0x06]; 2368c2ecf20Sopenharmony_ci u8 base_type[0x06]; 2378c2ecf20Sopenharmony_ci u16 reserved2; 2388c2ecf20Sopenharmony_ci u32 config_space[0x20]; 2398c2ecf20Sopenharmony_ci struct pci_resource *mem_head; 2408c2ecf20Sopenharmony_ci struct pci_resource *p_mem_head; 2418c2ecf20Sopenharmony_ci struct pci_resource *io_head; 2428c2ecf20Sopenharmony_ci struct pci_resource *bus_head; 2438c2ecf20Sopenharmony_ci struct timer_list *p_task_event; 2448c2ecf20Sopenharmony_ci struct pci_dev *pci_dev; 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistruct slot { 2488c2ecf20Sopenharmony_ci struct slot *next; 2498c2ecf20Sopenharmony_ci u8 bus; 2508c2ecf20Sopenharmony_ci u8 device; 2518c2ecf20Sopenharmony_ci u8 number; 2528c2ecf20Sopenharmony_ci u8 is_a_board; 2538c2ecf20Sopenharmony_ci u8 configured; 2548c2ecf20Sopenharmony_ci u8 state; 2558c2ecf20Sopenharmony_ci u8 switch_save; 2568c2ecf20Sopenharmony_ci u8 presence_save; 2578c2ecf20Sopenharmony_ci u32 capabilities; 2588c2ecf20Sopenharmony_ci u16 reserved2; 2598c2ecf20Sopenharmony_ci struct timer_list task_event; 2608c2ecf20Sopenharmony_ci u8 hp_slot; 2618c2ecf20Sopenharmony_ci struct controller *ctrl; 2628c2ecf20Sopenharmony_ci void __iomem *p_sm_slot; 2638c2ecf20Sopenharmony_ci struct hotplug_slot hotplug_slot; 2648c2ecf20Sopenharmony_ci}; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_cistruct pci_resource { 2678c2ecf20Sopenharmony_ci struct pci_resource *next; 2688c2ecf20Sopenharmony_ci u32 base; 2698c2ecf20Sopenharmony_ci u32 length; 2708c2ecf20Sopenharmony_ci}; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_cistruct event_info { 2738c2ecf20Sopenharmony_ci u32 event_type; 2748c2ecf20Sopenharmony_ci u8 hp_slot; 2758c2ecf20Sopenharmony_ci}; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_cistruct controller { 2788c2ecf20Sopenharmony_ci struct controller *next; 2798c2ecf20Sopenharmony_ci u32 ctrl_int_comp; 2808c2ecf20Sopenharmony_ci struct mutex crit_sect; /* critical section mutex */ 2818c2ecf20Sopenharmony_ci void __iomem *hpc_reg; /* cookie for our pci controller location */ 2828c2ecf20Sopenharmony_ci struct pci_resource *mem_head; 2838c2ecf20Sopenharmony_ci struct pci_resource *p_mem_head; 2848c2ecf20Sopenharmony_ci struct pci_resource *io_head; 2858c2ecf20Sopenharmony_ci struct pci_resource *bus_head; 2868c2ecf20Sopenharmony_ci struct pci_dev *pci_dev; 2878c2ecf20Sopenharmony_ci struct pci_bus *pci_bus; 2888c2ecf20Sopenharmony_ci struct event_info event_queue[10]; 2898c2ecf20Sopenharmony_ci struct slot *slot; 2908c2ecf20Sopenharmony_ci u8 next_event; 2918c2ecf20Sopenharmony_ci u8 interrupt; 2928c2ecf20Sopenharmony_ci u8 cfgspc_irq; 2938c2ecf20Sopenharmony_ci u8 bus; /* bus number for the pci hotplug controller */ 2948c2ecf20Sopenharmony_ci u8 rev; 2958c2ecf20Sopenharmony_ci u8 slot_device_offset; 2968c2ecf20Sopenharmony_ci u8 first_slot; 2978c2ecf20Sopenharmony_ci u8 add_support; 2988c2ecf20Sopenharmony_ci u8 push_flag; 2998c2ecf20Sopenharmony_ci u8 push_button; /* 0 = no pushbutton, 1 = pushbutton present */ 3008c2ecf20Sopenharmony_ci u8 slot_switch_type; /* 0 = no switch, 1 = switch present */ 3018c2ecf20Sopenharmony_ci u8 defeature_PHP; /* 0 = PHP not supported, 1 = PHP supported */ 3028c2ecf20Sopenharmony_ci u8 alternate_base_address; /* 0 = not supported, 1 = supported */ 3038c2ecf20Sopenharmony_ci u8 pci_config_space; /* Index/data access to working registers 0 = not supported, 1 = supported */ 3048c2ecf20Sopenharmony_ci u8 pcix_speed_capability; /* PCI-X */ 3058c2ecf20Sopenharmony_ci u8 pcix_support; /* PCI-X */ 3068c2ecf20Sopenharmony_ci u16 vendor_id; 3078c2ecf20Sopenharmony_ci struct work_struct int_task_event; 3088c2ecf20Sopenharmony_ci wait_queue_head_t queue; /* sleep & wake process */ 3098c2ecf20Sopenharmony_ci struct dentry *dentry; /* debugfs dentry */ 3108c2ecf20Sopenharmony_ci}; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistruct irq_mapping { 3138c2ecf20Sopenharmony_ci u8 barber_pole; 3148c2ecf20Sopenharmony_ci u8 valid_INT; 3158c2ecf20Sopenharmony_ci u8 interrupt[4]; 3168c2ecf20Sopenharmony_ci}; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_cistruct resource_lists { 3198c2ecf20Sopenharmony_ci struct pci_resource *mem_head; 3208c2ecf20Sopenharmony_ci struct pci_resource *p_mem_head; 3218c2ecf20Sopenharmony_ci struct pci_resource *io_head; 3228c2ecf20Sopenharmony_ci struct pci_resource *bus_head; 3238c2ecf20Sopenharmony_ci struct irq_mapping *irqs; 3248c2ecf20Sopenharmony_ci}; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci#define ROM_PHY_ADDR 0x0F0000 3278c2ecf20Sopenharmony_ci#define ROM_PHY_LEN 0x00ffff 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci#define PCI_HPC_ID 0xA0F7 3308c2ecf20Sopenharmony_ci#define PCI_SUB_HPC_ID 0xA2F7 3318c2ecf20Sopenharmony_ci#define PCI_SUB_HPC_ID2 0xA2F8 3328c2ecf20Sopenharmony_ci#define PCI_SUB_HPC_ID3 0xA2F9 3338c2ecf20Sopenharmony_ci#define PCI_SUB_HPC_ID_INTC 0xA2FA 3348c2ecf20Sopenharmony_ci#define PCI_SUB_HPC_ID4 0xA2FD 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci#define INT_BUTTON_IGNORE 0 3378c2ecf20Sopenharmony_ci#define INT_PRESENCE_ON 1 3388c2ecf20Sopenharmony_ci#define INT_PRESENCE_OFF 2 3398c2ecf20Sopenharmony_ci#define INT_SWITCH_CLOSE 3 3408c2ecf20Sopenharmony_ci#define INT_SWITCH_OPEN 4 3418c2ecf20Sopenharmony_ci#define INT_POWER_FAULT 5 3428c2ecf20Sopenharmony_ci#define INT_POWER_FAULT_CLEAR 6 3438c2ecf20Sopenharmony_ci#define INT_BUTTON_PRESS 7 3448c2ecf20Sopenharmony_ci#define INT_BUTTON_RELEASE 8 3458c2ecf20Sopenharmony_ci#define INT_BUTTON_CANCEL 9 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci#define STATIC_STATE 0 3488c2ecf20Sopenharmony_ci#define BLINKINGON_STATE 1 3498c2ecf20Sopenharmony_ci#define BLINKINGOFF_STATE 2 3508c2ecf20Sopenharmony_ci#define POWERON_STATE 3 3518c2ecf20Sopenharmony_ci#define POWEROFF_STATE 4 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci#define PCISLOT_INTERLOCK_CLOSED 0x00000001 3548c2ecf20Sopenharmony_ci#define PCISLOT_ADAPTER_PRESENT 0x00000002 3558c2ecf20Sopenharmony_ci#define PCISLOT_POWERED 0x00000004 3568c2ecf20Sopenharmony_ci#define PCISLOT_66_MHZ_OPERATION 0x00000008 3578c2ecf20Sopenharmony_ci#define PCISLOT_64_BIT_OPERATION 0x00000010 3588c2ecf20Sopenharmony_ci#define PCISLOT_REPLACE_SUPPORTED 0x00000020 3598c2ecf20Sopenharmony_ci#define PCISLOT_ADD_SUPPORTED 0x00000040 3608c2ecf20Sopenharmony_ci#define PCISLOT_INTERLOCK_SUPPORTED 0x00000080 3618c2ecf20Sopenharmony_ci#define PCISLOT_66_MHZ_SUPPORTED 0x00000100 3628c2ecf20Sopenharmony_ci#define PCISLOT_64_BIT_SUPPORTED 0x00000200 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci#define PCI_TO_PCI_BRIDGE_CLASS 0x00060400 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci#define INTERLOCK_OPEN 0x00000002 3678c2ecf20Sopenharmony_ci#define ADD_NOT_SUPPORTED 0x00000003 3688c2ecf20Sopenharmony_ci#define CARD_FUNCTIONING 0x00000005 3698c2ecf20Sopenharmony_ci#define ADAPTER_NOT_SAME 0x00000006 3708c2ecf20Sopenharmony_ci#define NO_ADAPTER_PRESENT 0x00000009 3718c2ecf20Sopenharmony_ci#define NOT_ENOUGH_RESOURCES 0x0000000B 3728c2ecf20Sopenharmony_ci#define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C 3738c2ecf20Sopenharmony_ci#define POWER_FAILURE 0x0000000E 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci#define REMOVE_NOT_SUPPORTED 0x00000003 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci/* 3798c2ecf20Sopenharmony_ci * error Messages 3808c2ecf20Sopenharmony_ci */ 3818c2ecf20Sopenharmony_ci#define msg_initialization_err "Initialization failure, error=%d\n" 3828c2ecf20Sopenharmony_ci#define msg_HPC_rev_error "Unsupported revision of the PCI hot plug controller found.\n" 3838c2ecf20Sopenharmony_ci#define msg_HPC_non_compaq_or_intel "The PCI hot plug controller is not supported by this driver.\n" 3848c2ecf20Sopenharmony_ci#define msg_HPC_not_supported "this system is not supported by this version of cpqphpd. Upgrade to a newer version of cpqphpd\n" 3858c2ecf20Sopenharmony_ci#define msg_unable_to_save "unable to store PCI hot plug add resource information. This system must be rebooted before adding any PCI devices.\n" 3868c2ecf20Sopenharmony_ci#define msg_button_on "PCI slot #%d - powering on due to button press.\n" 3878c2ecf20Sopenharmony_ci#define msg_button_off "PCI slot #%d - powering off due to button press.\n" 3888c2ecf20Sopenharmony_ci#define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n" 3898c2ecf20Sopenharmony_ci#define msg_button_ignore "PCI slot #%d - button press ignored. (action in progress...)\n" 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci/* debugfs functions for the hotplug controller info */ 3938c2ecf20Sopenharmony_civoid cpqhp_initialize_debugfs(void); 3948c2ecf20Sopenharmony_civoid cpqhp_shutdown_debugfs(void); 3958c2ecf20Sopenharmony_civoid cpqhp_create_debugfs_files(struct controller *ctrl); 3968c2ecf20Sopenharmony_civoid cpqhp_remove_debugfs_files(struct controller *ctrl); 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci/* controller functions */ 3998c2ecf20Sopenharmony_civoid cpqhp_pushbutton_thread(struct timer_list *t); 4008c2ecf20Sopenharmony_ciirqreturn_t cpqhp_ctrl_intr(int IRQ, void *data); 4018c2ecf20Sopenharmony_ciint cpqhp_find_available_resources(struct controller *ctrl, 4028c2ecf20Sopenharmony_ci void __iomem *rom_start); 4038c2ecf20Sopenharmony_ciint cpqhp_event_start_thread(void); 4048c2ecf20Sopenharmony_civoid cpqhp_event_stop_thread(void); 4058c2ecf20Sopenharmony_cistruct pci_func *cpqhp_slot_create(unsigned char busnumber); 4068c2ecf20Sopenharmony_cistruct pci_func *cpqhp_slot_find(unsigned char bus, unsigned char device, 4078c2ecf20Sopenharmony_ci unsigned char index); 4088c2ecf20Sopenharmony_ciint cpqhp_process_SI(struct controller *ctrl, struct pci_func *func); 4098c2ecf20Sopenharmony_ciint cpqhp_process_SS(struct controller *ctrl, struct pci_func *func); 4108c2ecf20Sopenharmony_ciint cpqhp_hardware_test(struct controller *ctrl, int test_num); 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci/* resource functions */ 4138c2ecf20Sopenharmony_ciint cpqhp_resource_sort_and_combine(struct pci_resource **head); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci/* pci functions */ 4168c2ecf20Sopenharmony_ciint cpqhp_set_irq(u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num); 4178c2ecf20Sopenharmony_ciint cpqhp_get_bus_dev(struct controller *ctrl, u8 *bus_num, u8 *dev_num, 4188c2ecf20Sopenharmony_ci u8 slot); 4198c2ecf20Sopenharmony_ciint cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug); 4208c2ecf20Sopenharmony_ciint cpqhp_save_base_addr_length(struct controller *ctrl, struct pci_func *func); 4218c2ecf20Sopenharmony_ciint cpqhp_save_used_resources(struct controller *ctrl, struct pci_func *func); 4228c2ecf20Sopenharmony_ciint cpqhp_configure_board(struct controller *ctrl, struct pci_func *func); 4238c2ecf20Sopenharmony_ciint cpqhp_save_slot_config(struct controller *ctrl, struct pci_func *new_slot); 4248c2ecf20Sopenharmony_ciint cpqhp_valid_replace(struct controller *ctrl, struct pci_func *func); 4258c2ecf20Sopenharmony_civoid cpqhp_destroy_board_resources(struct pci_func *func); 4268c2ecf20Sopenharmony_ciint cpqhp_return_board_resources(struct pci_func *func, 4278c2ecf20Sopenharmony_ci struct resource_lists *resources); 4288c2ecf20Sopenharmony_civoid cpqhp_destroy_resource_list(struct resource_lists *resources); 4298c2ecf20Sopenharmony_ciint cpqhp_configure_device(struct controller *ctrl, struct pci_func *func); 4308c2ecf20Sopenharmony_ciint cpqhp_unconfigure_device(struct pci_func *func); 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci/* Global variables */ 4338c2ecf20Sopenharmony_ciextern int cpqhp_debug; 4348c2ecf20Sopenharmony_ciextern int cpqhp_legacy_mode; 4358c2ecf20Sopenharmony_ciextern struct controller *cpqhp_ctrl_list; 4368c2ecf20Sopenharmony_ciextern struct pci_func *cpqhp_slot_list[256]; 4378c2ecf20Sopenharmony_ciextern struct irq_routing_table *cpqhp_routing_table; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci/* these can be gotten rid of, but for debugging they are purty */ 4408c2ecf20Sopenharmony_ciextern u8 cpqhp_nic_irq; 4418c2ecf20Sopenharmony_ciextern u8 cpqhp_disk_irq; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci/* inline functions */ 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_cistatic inline const char *slot_name(struct slot *slot) 4478c2ecf20Sopenharmony_ci{ 4488c2ecf20Sopenharmony_ci return hotplug_slot_name(&slot->hotplug_slot); 4498c2ecf20Sopenharmony_ci} 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_cistatic inline struct slot *to_slot(struct hotplug_slot *hotplug_slot) 4528c2ecf20Sopenharmony_ci{ 4538c2ecf20Sopenharmony_ci return container_of(hotplug_slot, struct slot, hotplug_slot); 4548c2ecf20Sopenharmony_ci} 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci/* 4578c2ecf20Sopenharmony_ci * return_resource 4588c2ecf20Sopenharmony_ci * 4598c2ecf20Sopenharmony_ci * Puts node back in the resource list pointed to by head 4608c2ecf20Sopenharmony_ci */ 4618c2ecf20Sopenharmony_cistatic inline void return_resource(struct pci_resource **head, 4628c2ecf20Sopenharmony_ci struct pci_resource *node) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci if (!node || !head) 4658c2ecf20Sopenharmony_ci return; 4668c2ecf20Sopenharmony_ci node->next = *head; 4678c2ecf20Sopenharmony_ci *head = node; 4688c2ecf20Sopenharmony_ci} 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_cistatic inline void set_SOGO(struct controller *ctrl) 4718c2ecf20Sopenharmony_ci{ 4728c2ecf20Sopenharmony_ci u16 misc; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci misc = readw(ctrl->hpc_reg + MISC); 4758c2ecf20Sopenharmony_ci misc = (misc | 0x0001) & 0xFFFB; 4768c2ecf20Sopenharmony_ci writew(misc, ctrl->hpc_reg + MISC); 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistatic inline void amber_LED_on(struct controller *ctrl, u8 slot) 4818c2ecf20Sopenharmony_ci{ 4828c2ecf20Sopenharmony_ci u32 led_control; 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci led_control = readl(ctrl->hpc_reg + LED_CONTROL); 4858c2ecf20Sopenharmony_ci led_control |= (0x01010000L << slot); 4868c2ecf20Sopenharmony_ci writel(led_control, ctrl->hpc_reg + LED_CONTROL); 4878c2ecf20Sopenharmony_ci} 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_cistatic inline void amber_LED_off(struct controller *ctrl, u8 slot) 4918c2ecf20Sopenharmony_ci{ 4928c2ecf20Sopenharmony_ci u32 led_control; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci led_control = readl(ctrl->hpc_reg + LED_CONTROL); 4958c2ecf20Sopenharmony_ci led_control &= ~(0x01010000L << slot); 4968c2ecf20Sopenharmony_ci writel(led_control, ctrl->hpc_reg + LED_CONTROL); 4978c2ecf20Sopenharmony_ci} 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_cistatic inline int read_amber_LED(struct controller *ctrl, u8 slot) 5018c2ecf20Sopenharmony_ci{ 5028c2ecf20Sopenharmony_ci u32 led_control; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci led_control = readl(ctrl->hpc_reg + LED_CONTROL); 5058c2ecf20Sopenharmony_ci led_control &= (0x01010000L << slot); 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci return led_control ? 1 : 0; 5088c2ecf20Sopenharmony_ci} 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic inline void green_LED_on(struct controller *ctrl, u8 slot) 5128c2ecf20Sopenharmony_ci{ 5138c2ecf20Sopenharmony_ci u32 led_control; 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci led_control = readl(ctrl->hpc_reg + LED_CONTROL); 5168c2ecf20Sopenharmony_ci led_control |= 0x0101L << slot; 5178c2ecf20Sopenharmony_ci writel(led_control, ctrl->hpc_reg + LED_CONTROL); 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_cistatic inline void green_LED_off(struct controller *ctrl, u8 slot) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci u32 led_control; 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci led_control = readl(ctrl->hpc_reg + LED_CONTROL); 5258c2ecf20Sopenharmony_ci led_control &= ~(0x0101L << slot); 5268c2ecf20Sopenharmony_ci writel(led_control, ctrl->hpc_reg + LED_CONTROL); 5278c2ecf20Sopenharmony_ci} 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_cistatic inline void green_LED_blink(struct controller *ctrl, u8 slot) 5318c2ecf20Sopenharmony_ci{ 5328c2ecf20Sopenharmony_ci u32 led_control; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci led_control = readl(ctrl->hpc_reg + LED_CONTROL); 5358c2ecf20Sopenharmony_ci led_control &= ~(0x0101L << slot); 5368c2ecf20Sopenharmony_ci led_control |= (0x0001L << slot); 5378c2ecf20Sopenharmony_ci writel(led_control, ctrl->hpc_reg + LED_CONTROL); 5388c2ecf20Sopenharmony_ci} 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_cistatic inline void slot_disable(struct controller *ctrl, u8 slot) 5428c2ecf20Sopenharmony_ci{ 5438c2ecf20Sopenharmony_ci u8 slot_enable; 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci slot_enable = readb(ctrl->hpc_reg + SLOT_ENABLE); 5468c2ecf20Sopenharmony_ci slot_enable &= ~(0x01 << slot); 5478c2ecf20Sopenharmony_ci writeb(slot_enable, ctrl->hpc_reg + SLOT_ENABLE); 5488c2ecf20Sopenharmony_ci} 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_cistatic inline void slot_enable(struct controller *ctrl, u8 slot) 5528c2ecf20Sopenharmony_ci{ 5538c2ecf20Sopenharmony_ci u8 slot_enable; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci slot_enable = readb(ctrl->hpc_reg + SLOT_ENABLE); 5568c2ecf20Sopenharmony_ci slot_enable |= (0x01 << slot); 5578c2ecf20Sopenharmony_ci writeb(slot_enable, ctrl->hpc_reg + SLOT_ENABLE); 5588c2ecf20Sopenharmony_ci} 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cistatic inline u8 is_slot_enabled(struct controller *ctrl, u8 slot) 5628c2ecf20Sopenharmony_ci{ 5638c2ecf20Sopenharmony_ci u8 slot_enable; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci slot_enable = readb(ctrl->hpc_reg + SLOT_ENABLE); 5668c2ecf20Sopenharmony_ci slot_enable &= (0x01 << slot); 5678c2ecf20Sopenharmony_ci return slot_enable ? 1 : 0; 5688c2ecf20Sopenharmony_ci} 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_cistatic inline u8 read_slot_enable(struct controller *ctrl) 5728c2ecf20Sopenharmony_ci{ 5738c2ecf20Sopenharmony_ci return readb(ctrl->hpc_reg + SLOT_ENABLE); 5748c2ecf20Sopenharmony_ci} 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci/** 5788c2ecf20Sopenharmony_ci * get_controller_speed - find the current frequency/mode of controller. 5798c2ecf20Sopenharmony_ci * 5808c2ecf20Sopenharmony_ci * @ctrl: controller to get frequency/mode for. 5818c2ecf20Sopenharmony_ci * 5828c2ecf20Sopenharmony_ci * Returns controller speed. 5838c2ecf20Sopenharmony_ci */ 5848c2ecf20Sopenharmony_cistatic inline u8 get_controller_speed(struct controller *ctrl) 5858c2ecf20Sopenharmony_ci{ 5868c2ecf20Sopenharmony_ci u8 curr_freq; 5878c2ecf20Sopenharmony_ci u16 misc; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci if (ctrl->pcix_support) { 5908c2ecf20Sopenharmony_ci curr_freq = readb(ctrl->hpc_reg + NEXT_CURR_FREQ); 5918c2ecf20Sopenharmony_ci if ((curr_freq & 0xB0) == 0xB0) 5928c2ecf20Sopenharmony_ci return PCI_SPEED_133MHz_PCIX; 5938c2ecf20Sopenharmony_ci if ((curr_freq & 0xA0) == 0xA0) 5948c2ecf20Sopenharmony_ci return PCI_SPEED_100MHz_PCIX; 5958c2ecf20Sopenharmony_ci if ((curr_freq & 0x90) == 0x90) 5968c2ecf20Sopenharmony_ci return PCI_SPEED_66MHz_PCIX; 5978c2ecf20Sopenharmony_ci if (curr_freq & 0x10) 5988c2ecf20Sopenharmony_ci return PCI_SPEED_66MHz; 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci return PCI_SPEED_33MHz; 6018c2ecf20Sopenharmony_ci } 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci misc = readw(ctrl->hpc_reg + MISC); 6048c2ecf20Sopenharmony_ci return (misc & 0x0800) ? PCI_SPEED_66MHz : PCI_SPEED_33MHz; 6058c2ecf20Sopenharmony_ci} 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci/** 6098c2ecf20Sopenharmony_ci * get_adapter_speed - find the max supported frequency/mode of adapter. 6108c2ecf20Sopenharmony_ci * 6118c2ecf20Sopenharmony_ci * @ctrl: hotplug controller. 6128c2ecf20Sopenharmony_ci * @hp_slot: hotplug slot where adapter is installed. 6138c2ecf20Sopenharmony_ci * 6148c2ecf20Sopenharmony_ci * Returns adapter speed. 6158c2ecf20Sopenharmony_ci */ 6168c2ecf20Sopenharmony_cistatic inline u8 get_adapter_speed(struct controller *ctrl, u8 hp_slot) 6178c2ecf20Sopenharmony_ci{ 6188c2ecf20Sopenharmony_ci u32 temp_dword = readl(ctrl->hpc_reg + NON_INT_INPUT); 6198c2ecf20Sopenharmony_ci dbg("slot: %d, PCIXCAP: %8x\n", hp_slot, temp_dword); 6208c2ecf20Sopenharmony_ci if (ctrl->pcix_support) { 6218c2ecf20Sopenharmony_ci if (temp_dword & (0x10000 << hp_slot)) 6228c2ecf20Sopenharmony_ci return PCI_SPEED_133MHz_PCIX; 6238c2ecf20Sopenharmony_ci if (temp_dword & (0x100 << hp_slot)) 6248c2ecf20Sopenharmony_ci return PCI_SPEED_66MHz_PCIX; 6258c2ecf20Sopenharmony_ci } 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci if (temp_dword & (0x01 << hp_slot)) 6288c2ecf20Sopenharmony_ci return PCI_SPEED_66MHz; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci return PCI_SPEED_33MHz; 6318c2ecf20Sopenharmony_ci} 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_cistatic inline void enable_slot_power(struct controller *ctrl, u8 slot) 6348c2ecf20Sopenharmony_ci{ 6358c2ecf20Sopenharmony_ci u8 slot_power; 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci slot_power = readb(ctrl->hpc_reg + SLOT_POWER); 6388c2ecf20Sopenharmony_ci slot_power |= (0x01 << slot); 6398c2ecf20Sopenharmony_ci writeb(slot_power, ctrl->hpc_reg + SLOT_POWER); 6408c2ecf20Sopenharmony_ci} 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_cistatic inline void disable_slot_power(struct controller *ctrl, u8 slot) 6438c2ecf20Sopenharmony_ci{ 6448c2ecf20Sopenharmony_ci u8 slot_power; 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci slot_power = readb(ctrl->hpc_reg + SLOT_POWER); 6478c2ecf20Sopenharmony_ci slot_power &= ~(0x01 << slot); 6488c2ecf20Sopenharmony_ci writeb(slot_power, ctrl->hpc_reg + SLOT_POWER); 6498c2ecf20Sopenharmony_ci} 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_cistatic inline int cpq_get_attention_status(struct controller *ctrl, struct slot *slot) 6538c2ecf20Sopenharmony_ci{ 6548c2ecf20Sopenharmony_ci u8 hp_slot; 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci hp_slot = slot->device - ctrl->slot_device_offset; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci return read_amber_LED(ctrl, hp_slot); 6598c2ecf20Sopenharmony_ci} 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_cistatic inline int get_slot_enabled(struct controller *ctrl, struct slot *slot) 6638c2ecf20Sopenharmony_ci{ 6648c2ecf20Sopenharmony_ci u8 hp_slot; 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci hp_slot = slot->device - ctrl->slot_device_offset; 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci return is_slot_enabled(ctrl, hp_slot); 6698c2ecf20Sopenharmony_ci} 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_cistatic inline int cpq_get_latch_status(struct controller *ctrl, 6738c2ecf20Sopenharmony_ci struct slot *slot) 6748c2ecf20Sopenharmony_ci{ 6758c2ecf20Sopenharmony_ci u32 status; 6768c2ecf20Sopenharmony_ci u8 hp_slot; 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci hp_slot = slot->device - ctrl->slot_device_offset; 6798c2ecf20Sopenharmony_ci dbg("%s: slot->device = %d, ctrl->slot_device_offset = %d\n", 6808c2ecf20Sopenharmony_ci __func__, slot->device, ctrl->slot_device_offset); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci status = (readl(ctrl->hpc_reg + INT_INPUT_CLEAR) & (0x01L << hp_slot)); 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci return (status == 0) ? 1 : 0; 6858c2ecf20Sopenharmony_ci} 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_cistatic inline int get_presence_status(struct controller *ctrl, 6898c2ecf20Sopenharmony_ci struct slot *slot) 6908c2ecf20Sopenharmony_ci{ 6918c2ecf20Sopenharmony_ci int presence_save = 0; 6928c2ecf20Sopenharmony_ci u8 hp_slot; 6938c2ecf20Sopenharmony_ci u32 tempdword; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci hp_slot = slot->device - ctrl->slot_device_offset; 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR); 6988c2ecf20Sopenharmony_ci presence_save = (int) ((((~tempdword) >> 23) | ((~tempdword) >> 15)) 6998c2ecf20Sopenharmony_ci >> hp_slot) & 0x02; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci return presence_save; 7028c2ecf20Sopenharmony_ci} 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_cistatic inline int wait_for_ctrl_irq(struct controller *ctrl) 7058c2ecf20Sopenharmony_ci{ 7068c2ecf20Sopenharmony_ci DECLARE_WAITQUEUE(wait, current); 7078c2ecf20Sopenharmony_ci int retval = 0; 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci dbg("%s - start\n", __func__); 7108c2ecf20Sopenharmony_ci add_wait_queue(&ctrl->queue, &wait); 7118c2ecf20Sopenharmony_ci /* Sleep for up to 1 second to wait for the LED to change. */ 7128c2ecf20Sopenharmony_ci msleep_interruptible(1000); 7138c2ecf20Sopenharmony_ci remove_wait_queue(&ctrl->queue, &wait); 7148c2ecf20Sopenharmony_ci if (signal_pending(current)) 7158c2ecf20Sopenharmony_ci retval = -EINTR; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci dbg("%s - end\n", __func__); 7188c2ecf20Sopenharmony_ci return retval; 7198c2ecf20Sopenharmony_ci} 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci#include <asm/pci_x86.h> 7228c2ecf20Sopenharmony_cistatic inline int cpqhp_routing_table_length(void) 7238c2ecf20Sopenharmony_ci{ 7248c2ecf20Sopenharmony_ci BUG_ON(cpqhp_routing_table == NULL); 7258c2ecf20Sopenharmony_ci return ((cpqhp_routing_table->size - sizeof(struct irq_routing_table)) / 7268c2ecf20Sopenharmony_ci sizeof(struct irq_info)); 7278c2ecf20Sopenharmony_ci} 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci#endif 730