xref: /linux/drivers/pci/hotplug/cpqphp.h (revision 9f3f4681291fc88864bb27f8f3832b95bb53aae5)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Compaq Hot Plug Controller Driver
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (C) 1995,2001 Compaq Computer Corporation
51da177e4SLinus Torvalds  * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
61da177e4SLinus Torvalds  * Copyright (C) 2001 IBM
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * All rights reserved.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
111da177e4SLinus Torvalds  * it under the terms of the GNU General Public License as published by
121da177e4SLinus Torvalds  * the Free Software Foundation; either version 2 of the License, or (at
131da177e4SLinus Torvalds  * your option) any later version.
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful, but
161da177e4SLinus Torvalds  * WITHOUT ANY WARRANTY; without even the implied warranty of
171da177e4SLinus Torvalds  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
181da177e4SLinus Torvalds  * NON INFRINGEMENT.  See the GNU General Public License for more
191da177e4SLinus Torvalds  * details.
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
221da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
231da177e4SLinus Torvalds  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  * Send feedback to <greg@kroah.com>
261da177e4SLinus Torvalds  *
271da177e4SLinus Torvalds  */
281da177e4SLinus Torvalds #ifndef _CPQPHP_H
291da177e4SLinus Torvalds #define _CPQPHP_H
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds #include "pci_hotplug.h"
321da177e4SLinus Torvalds #include <linux/interrupt.h>
331da177e4SLinus Torvalds #include <asm/io.h>		/* for read? and write? functions */
341da177e4SLinus Torvalds #include <linux/delay.h>	/* for delays */
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds #define MY_NAME	"cpqphp"
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #define dbg(fmt, arg...) do { if (cpqhp_debug) printk(KERN_DEBUG "%s: " fmt , MY_NAME , ## arg); } while (0)
391da177e4SLinus Torvalds #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
401da177e4SLinus Torvalds #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
411da177e4SLinus Torvalds #define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds struct smbios_system_slot {
461da177e4SLinus Torvalds 	u8 type;
471da177e4SLinus Torvalds 	u8 length;
481da177e4SLinus Torvalds 	u16 handle;
491da177e4SLinus Torvalds 	u8 name_string_num;
501da177e4SLinus Torvalds 	u8 slot_type;
511da177e4SLinus Torvalds 	u8 slot_width;
521da177e4SLinus Torvalds 	u8 slot_current_usage;
531da177e4SLinus Torvalds 	u8 slot_length;
541da177e4SLinus Torvalds 	u16 slot_number;
551da177e4SLinus Torvalds 	u8 properties1;
561da177e4SLinus Torvalds 	u8 properties2;
571da177e4SLinus Torvalds } __attribute__ ((packed));
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds /* offsets to the smbios generic type based on the above structure layout */
601da177e4SLinus Torvalds enum smbios_system_slot_offsets {
611da177e4SLinus Torvalds 	SMBIOS_SLOT_GENERIC_TYPE =	offsetof(struct smbios_system_slot, type),
621da177e4SLinus Torvalds 	SMBIOS_SLOT_GENERIC_LENGTH =	offsetof(struct smbios_system_slot, length),
631da177e4SLinus Torvalds 	SMBIOS_SLOT_GENERIC_HANDLE =	offsetof(struct smbios_system_slot, handle),
641da177e4SLinus Torvalds 	SMBIOS_SLOT_NAME_STRING_NUM =	offsetof(struct smbios_system_slot, name_string_num),
651da177e4SLinus Torvalds 	SMBIOS_SLOT_TYPE =		offsetof(struct smbios_system_slot, slot_type),
661da177e4SLinus Torvalds 	SMBIOS_SLOT_WIDTH =		offsetof(struct smbios_system_slot, slot_width),
671da177e4SLinus Torvalds 	SMBIOS_SLOT_CURRENT_USAGE =	offsetof(struct smbios_system_slot, slot_current_usage),
681da177e4SLinus Torvalds 	SMBIOS_SLOT_LENGTH =		offsetof(struct smbios_system_slot, slot_length),
691da177e4SLinus Torvalds 	SMBIOS_SLOT_NUMBER =		offsetof(struct smbios_system_slot, slot_number),
701da177e4SLinus Torvalds 	SMBIOS_SLOT_PROPERTIES1 =	offsetof(struct smbios_system_slot, properties1),
711da177e4SLinus Torvalds 	SMBIOS_SLOT_PROPERTIES2 =	offsetof(struct smbios_system_slot, properties2),
721da177e4SLinus Torvalds };
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds struct smbios_generic {
751da177e4SLinus Torvalds 	u8 type;
761da177e4SLinus Torvalds 	u8 length;
771da177e4SLinus Torvalds 	u16 handle;
781da177e4SLinus Torvalds } __attribute__ ((packed));
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds /* offsets to the smbios generic type based on the above structure layout */
811da177e4SLinus Torvalds enum smbios_generic_offsets {
821da177e4SLinus Torvalds 	SMBIOS_GENERIC_TYPE =	offsetof(struct smbios_generic, type),
831da177e4SLinus Torvalds 	SMBIOS_GENERIC_LENGTH =	offsetof(struct smbios_generic, length),
841da177e4SLinus Torvalds 	SMBIOS_GENERIC_HANDLE =	offsetof(struct smbios_generic, handle),
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds struct smbios_entry_point {
881da177e4SLinus Torvalds 	char anchor[4];
891da177e4SLinus Torvalds 	u8 ep_checksum;
901da177e4SLinus Torvalds 	u8 ep_length;
911da177e4SLinus Torvalds 	u8 major_version;
921da177e4SLinus Torvalds 	u8 minor_version;
931da177e4SLinus Torvalds 	u16 max_size_entry;
941da177e4SLinus Torvalds 	u8 ep_rev;
951da177e4SLinus Torvalds 	u8 reserved[5];
961da177e4SLinus Torvalds 	char int_anchor[5];
971da177e4SLinus Torvalds 	u8 int_checksum;
981da177e4SLinus Torvalds 	u16 st_length;
991da177e4SLinus Torvalds 	u32 st_address;
1001da177e4SLinus Torvalds 	u16 number_of_entrys;
1011da177e4SLinus Torvalds 	u8 bcd_rev;
1021da177e4SLinus Torvalds } __attribute__ ((packed));
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /* offsets to the smbios entry point based on the above structure layout */
1051da177e4SLinus Torvalds enum smbios_entry_point_offsets {
1061da177e4SLinus Torvalds 	ANCHOR =		offsetof(struct smbios_entry_point, anchor[0]),
1071da177e4SLinus Torvalds 	EP_CHECKSUM =		offsetof(struct smbios_entry_point, ep_checksum),
1081da177e4SLinus Torvalds 	EP_LENGTH =		offsetof(struct smbios_entry_point, ep_length),
1091da177e4SLinus Torvalds 	MAJOR_VERSION =		offsetof(struct smbios_entry_point, major_version),
1101da177e4SLinus Torvalds 	MINOR_VERSION =		offsetof(struct smbios_entry_point, minor_version),
1111da177e4SLinus Torvalds 	MAX_SIZE_ENTRY =	offsetof(struct smbios_entry_point, max_size_entry),
1121da177e4SLinus Torvalds 	EP_REV =		offsetof(struct smbios_entry_point, ep_rev),
1131da177e4SLinus Torvalds 	INT_ANCHOR =		offsetof(struct smbios_entry_point, int_anchor[0]),
1141da177e4SLinus Torvalds 	INT_CHECKSUM =		offsetof(struct smbios_entry_point, int_checksum),
1151da177e4SLinus Torvalds 	ST_LENGTH =		offsetof(struct smbios_entry_point, st_length),
1161da177e4SLinus Torvalds 	ST_ADDRESS =		offsetof(struct smbios_entry_point, st_address),
1171da177e4SLinus Torvalds 	NUMBER_OF_ENTRYS =	offsetof(struct smbios_entry_point, number_of_entrys),
1181da177e4SLinus Torvalds 	BCD_REV =		offsetof(struct smbios_entry_point, bcd_rev),
1191da177e4SLinus Torvalds };
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds struct ctrl_reg {			/* offset */
1221da177e4SLinus Torvalds 	u8	slot_RST;		/* 0x00 */
1231da177e4SLinus Torvalds 	u8	slot_enable;		/* 0x01 */
1241da177e4SLinus Torvalds 	u16	misc;			/* 0x02 */
1251da177e4SLinus Torvalds 	u32	led_control;		/* 0x04 */
1261da177e4SLinus Torvalds 	u32	int_input_clear;	/* 0x08 */
1271da177e4SLinus Torvalds 	u32	int_mask;		/* 0x0a */
1281da177e4SLinus Torvalds 	u8	reserved0;		/* 0x10 */
1291da177e4SLinus Torvalds 	u8	reserved1;		/* 0x11 */
1301da177e4SLinus Torvalds 	u8	reserved2;		/* 0x12 */
1311da177e4SLinus Torvalds 	u8	gen_output_AB;		/* 0x13 */
1321da177e4SLinus Torvalds 	u32	non_int_input;		/* 0x14 */
1331da177e4SLinus Torvalds 	u32	reserved3;		/* 0x18 */
1341da177e4SLinus Torvalds 	u32	reserved4;		/* 0x1a */
1351da177e4SLinus Torvalds 	u32	reserved5;		/* 0x20 */
1361da177e4SLinus Torvalds 	u8	reserved6;		/* 0x24 */
1371da177e4SLinus Torvalds 	u8	reserved7;		/* 0x25 */
1381da177e4SLinus Torvalds 	u16	reserved8;		/* 0x26 */
1391da177e4SLinus Torvalds 	u8	slot_mask;		/* 0x28 */
1401da177e4SLinus Torvalds 	u8	reserved9;		/* 0x29 */
1411da177e4SLinus Torvalds 	u8	reserved10;		/* 0x2a */
1421da177e4SLinus Torvalds 	u8	reserved11;		/* 0x2b */
1431da177e4SLinus Torvalds 	u8	slot_SERR;		/* 0x2c */
1441da177e4SLinus Torvalds 	u8	slot_power;		/* 0x2d */
1451da177e4SLinus Torvalds 	u8	reserved12;		/* 0x2e */
1461da177e4SLinus Torvalds 	u8	reserved13;		/* 0x2f */
1471da177e4SLinus Torvalds 	u8	next_curr_freq;		/* 0x30 */
1481da177e4SLinus Torvalds 	u8	reset_freq_mode;	/* 0x31 */
1491da177e4SLinus Torvalds } __attribute__ ((packed));
1501da177e4SLinus Torvalds 
1511da177e4SLinus Torvalds /* offsets to the controller registers based on the above structure layout */
1521da177e4SLinus Torvalds enum ctrl_offsets {
1531da177e4SLinus Torvalds 	SLOT_RST = 		offsetof(struct ctrl_reg, slot_RST),
1541da177e4SLinus Torvalds 	SLOT_ENABLE =		offsetof(struct ctrl_reg, slot_enable),
1551da177e4SLinus Torvalds 	MISC =			offsetof(struct ctrl_reg, misc),
1561da177e4SLinus Torvalds 	LED_CONTROL =		offsetof(struct ctrl_reg, led_control),
1571da177e4SLinus Torvalds 	INT_INPUT_CLEAR =	offsetof(struct ctrl_reg, int_input_clear),
1581da177e4SLinus Torvalds 	INT_MASK = 		offsetof(struct ctrl_reg, int_mask),
1591da177e4SLinus Torvalds 	CTRL_RESERVED0 = 	offsetof(struct ctrl_reg, reserved0),
1601da177e4SLinus Torvalds 	CTRL_RESERVED1 =	offsetof(struct ctrl_reg, reserved1),
1611da177e4SLinus Torvalds 	CTRL_RESERVED2 =	offsetof(struct ctrl_reg, reserved1),
1621da177e4SLinus Torvalds 	GEN_OUTPUT_AB = 	offsetof(struct ctrl_reg, gen_output_AB),
1631da177e4SLinus Torvalds 	NON_INT_INPUT = 	offsetof(struct ctrl_reg, non_int_input),
1641da177e4SLinus Torvalds 	CTRL_RESERVED3 =	offsetof(struct ctrl_reg, reserved3),
1651da177e4SLinus Torvalds 	CTRL_RESERVED4 =	offsetof(struct ctrl_reg, reserved4),
1661da177e4SLinus Torvalds 	CTRL_RESERVED5 =	offsetof(struct ctrl_reg, reserved5),
1671da177e4SLinus Torvalds 	CTRL_RESERVED6 =	offsetof(struct ctrl_reg, reserved6),
1681da177e4SLinus Torvalds 	CTRL_RESERVED7 =	offsetof(struct ctrl_reg, reserved7),
1691da177e4SLinus Torvalds 	CTRL_RESERVED8 =	offsetof(struct ctrl_reg, reserved8),
1701da177e4SLinus Torvalds 	SLOT_MASK = 		offsetof(struct ctrl_reg, slot_mask),
1711da177e4SLinus Torvalds 	CTRL_RESERVED9 = 	offsetof(struct ctrl_reg, reserved9),
1721da177e4SLinus Torvalds 	CTRL_RESERVED10 =	offsetof(struct ctrl_reg, reserved10),
1731da177e4SLinus Torvalds 	CTRL_RESERVED11 =	offsetof(struct ctrl_reg, reserved11),
1741da177e4SLinus Torvalds 	SLOT_SERR =		offsetof(struct ctrl_reg, slot_SERR),
1751da177e4SLinus Torvalds 	SLOT_POWER =		offsetof(struct ctrl_reg, slot_power),
1761da177e4SLinus Torvalds 	NEXT_CURR_FREQ =	offsetof(struct ctrl_reg, next_curr_freq),
1771da177e4SLinus Torvalds 	RESET_FREQ_MODE =	offsetof(struct ctrl_reg, reset_freq_mode),
1781da177e4SLinus Torvalds };
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds struct hrt {
1811da177e4SLinus Torvalds 	char sig0;
1821da177e4SLinus Torvalds 	char sig1;
1831da177e4SLinus Torvalds 	char sig2;
1841da177e4SLinus Torvalds 	char sig3;
1851da177e4SLinus Torvalds 	u16 unused_IRQ;
1861da177e4SLinus Torvalds 	u16 PCIIRQ;
1871da177e4SLinus Torvalds 	u8 number_of_entries;
1881da177e4SLinus Torvalds 	u8 revision;
1891da177e4SLinus Torvalds 	u16 reserved1;
1901da177e4SLinus Torvalds 	u32 reserved2;
1911da177e4SLinus Torvalds } __attribute__ ((packed));
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds /* offsets to the hotplug resource table registers based on the above structure layout */
1941da177e4SLinus Torvalds enum hrt_offsets {
1951da177e4SLinus Torvalds 	SIG0 =			offsetof(struct hrt, sig0),
1961da177e4SLinus Torvalds 	SIG1 =			offsetof(struct hrt, sig1),
1971da177e4SLinus Torvalds 	SIG2 =			offsetof(struct hrt, sig2),
1981da177e4SLinus Torvalds 	SIG3 =			offsetof(struct hrt, sig3),
1991da177e4SLinus Torvalds 	UNUSED_IRQ =		offsetof(struct hrt, unused_IRQ),
2001da177e4SLinus Torvalds 	PCIIRQ =		offsetof(struct hrt, PCIIRQ),
2011da177e4SLinus Torvalds 	NUMBER_OF_ENTRIES =	offsetof(struct hrt, number_of_entries),
2021da177e4SLinus Torvalds 	REVISION =		offsetof(struct hrt, revision),
2031da177e4SLinus Torvalds 	HRT_RESERVED1 =		offsetof(struct hrt, reserved1),
2041da177e4SLinus Torvalds 	HRT_RESERVED2 =		offsetof(struct hrt, reserved2),
2051da177e4SLinus Torvalds };
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds struct slot_rt {
2081da177e4SLinus Torvalds 	u8 dev_func;
2091da177e4SLinus Torvalds 	u8 primary_bus;
2101da177e4SLinus Torvalds 	u8 secondary_bus;
2111da177e4SLinus Torvalds 	u8 max_bus;
2121da177e4SLinus Torvalds 	u16 io_base;
2131da177e4SLinus Torvalds 	u16 io_length;
2141da177e4SLinus Torvalds 	u16 mem_base;
2151da177e4SLinus Torvalds 	u16 mem_length;
2161da177e4SLinus Torvalds 	u16 pre_mem_base;
2171da177e4SLinus Torvalds 	u16 pre_mem_length;
2181da177e4SLinus Torvalds } __attribute__ ((packed));
2191da177e4SLinus Torvalds 
2201da177e4SLinus Torvalds /* offsets to the hotplug slot resource table registers based on the above structure layout */
2211da177e4SLinus Torvalds enum slot_rt_offsets {
2221da177e4SLinus Torvalds 	DEV_FUNC =		offsetof(struct slot_rt, dev_func),
2231da177e4SLinus Torvalds 	PRIMARY_BUS = 		offsetof(struct slot_rt, primary_bus),
2241da177e4SLinus Torvalds 	SECONDARY_BUS = 	offsetof(struct slot_rt, secondary_bus),
2251da177e4SLinus Torvalds 	MAX_BUS = 		offsetof(struct slot_rt, max_bus),
2261da177e4SLinus Torvalds 	IO_BASE = 		offsetof(struct slot_rt, io_base),
2271da177e4SLinus Torvalds 	IO_LENGTH = 		offsetof(struct slot_rt, io_length),
2281da177e4SLinus Torvalds 	MEM_BASE = 		offsetof(struct slot_rt, mem_base),
2291da177e4SLinus Torvalds 	MEM_LENGTH = 		offsetof(struct slot_rt, mem_length),
2301da177e4SLinus Torvalds 	PRE_MEM_BASE = 		offsetof(struct slot_rt, pre_mem_base),
2311da177e4SLinus Torvalds 	PRE_MEM_LENGTH = 	offsetof(struct slot_rt, pre_mem_length),
2321da177e4SLinus Torvalds };
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds struct pci_func {
2351da177e4SLinus Torvalds 	struct pci_func *next;
2361da177e4SLinus Torvalds 	u8 bus;
2371da177e4SLinus Torvalds 	u8 device;
2381da177e4SLinus Torvalds 	u8 function;
2391da177e4SLinus Torvalds 	u8 is_a_board;
2401da177e4SLinus Torvalds 	u16 status;
2411da177e4SLinus Torvalds 	u8 configured;
2421da177e4SLinus Torvalds 	u8 switch_save;
2431da177e4SLinus Torvalds 	u8 presence_save;
2441da177e4SLinus Torvalds 	u32 base_length[0x06];
2451da177e4SLinus Torvalds 	u8 base_type[0x06];
2461da177e4SLinus Torvalds 	u16 reserved2;
2471da177e4SLinus Torvalds 	u32 config_space[0x20];
2481da177e4SLinus Torvalds 	struct pci_resource *mem_head;
2491da177e4SLinus Torvalds 	struct pci_resource *p_mem_head;
2501da177e4SLinus Torvalds 	struct pci_resource *io_head;
2511da177e4SLinus Torvalds 	struct pci_resource *bus_head;
2521da177e4SLinus Torvalds 	struct timer_list *p_task_event;
2531da177e4SLinus Torvalds 	struct pci_dev* pci_dev;
2541da177e4SLinus Torvalds };
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds struct slot {
2571da177e4SLinus Torvalds 	struct slot *next;
2581da177e4SLinus Torvalds 	u8 bus;
2591da177e4SLinus Torvalds 	u8 device;
2601da177e4SLinus Torvalds 	u8 number;
2611da177e4SLinus Torvalds 	u8 is_a_board;
2621da177e4SLinus Torvalds 	u8 configured;
2631da177e4SLinus Torvalds 	u8 state;
2641da177e4SLinus Torvalds 	u8 switch_save;
2651da177e4SLinus Torvalds 	u8 presence_save;
2661da177e4SLinus Torvalds 	u32 capabilities;
2671da177e4SLinus Torvalds 	u16 reserved2;
2681da177e4SLinus Torvalds 	struct timer_list task_event;
2691da177e4SLinus Torvalds 	u8 hp_slot;
2701da177e4SLinus Torvalds 	struct controller *ctrl;
2711da177e4SLinus Torvalds 	void __iomem *p_sm_slot;
2721da177e4SLinus Torvalds 	struct hotplug_slot *hotplug_slot;
2731da177e4SLinus Torvalds };
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds struct pci_resource {
2761da177e4SLinus Torvalds 	struct pci_resource * next;
2771da177e4SLinus Torvalds 	u32 base;
2781da177e4SLinus Torvalds 	u32 length;
2791da177e4SLinus Torvalds };
2801da177e4SLinus Torvalds 
2811da177e4SLinus Torvalds struct event_info {
2821da177e4SLinus Torvalds 	u32 event_type;
2831da177e4SLinus Torvalds 	u8 hp_slot;
2841da177e4SLinus Torvalds };
2851da177e4SLinus Torvalds 
2861da177e4SLinus Torvalds struct controller {
2871da177e4SLinus Torvalds 	struct controller *next;
2881da177e4SLinus Torvalds 	u32 ctrl_int_comp;
2891da177e4SLinus Torvalds 	struct semaphore crit_sect;	/* critical section semaphore */
2901da177e4SLinus Torvalds 	void __iomem *hpc_reg;		/* cookie for our pci controller location */
2911da177e4SLinus Torvalds 	struct pci_resource *mem_head;
2921da177e4SLinus Torvalds 	struct pci_resource *p_mem_head;
2931da177e4SLinus Torvalds 	struct pci_resource *io_head;
2941da177e4SLinus Torvalds 	struct pci_resource *bus_head;
2951da177e4SLinus Torvalds 	struct pci_dev *pci_dev;
2961da177e4SLinus Torvalds 	struct pci_bus *pci_bus;
2971da177e4SLinus Torvalds 	struct event_info event_queue[10];
2981da177e4SLinus Torvalds 	struct slot *slot;
2991da177e4SLinus Torvalds 	u8 next_event;
3001da177e4SLinus Torvalds 	u8 interrupt;
3011da177e4SLinus Torvalds 	u8 cfgspc_irq;
3021da177e4SLinus Torvalds 	u8 bus;				/* bus number for the pci hotplug controller */
3031da177e4SLinus Torvalds 	u8 rev;
3041da177e4SLinus Torvalds 	u8 slot_device_offset;
3051da177e4SLinus Torvalds 	u8 first_slot;
3061da177e4SLinus Torvalds 	u8 add_support;
3071da177e4SLinus Torvalds 	u8 push_flag;
3081da177e4SLinus Torvalds 	enum pci_bus_speed speed;
3091da177e4SLinus Torvalds 	enum pci_bus_speed speed_capability;
3101da177e4SLinus Torvalds 	u8 push_button;			/* 0 = no pushbutton, 1 = pushbutton present */
3111da177e4SLinus Torvalds 	u8 slot_switch_type;		/* 0 = no switch, 1 = switch present */
3121da177e4SLinus Torvalds 	u8 defeature_PHP;		/* 0 = PHP not supported, 1 = PHP supported */
3131da177e4SLinus Torvalds 	u8 alternate_base_address;	/* 0 = not supported, 1 = supported */
3141da177e4SLinus Torvalds 	u8 pci_config_space;		/* Index/data access to working registers 0 = not supported, 1 = supported */
3151da177e4SLinus Torvalds 	u8 pcix_speed_capability;	/* PCI-X */
3161da177e4SLinus Torvalds 	u8 pcix_support;		/* PCI-X */
3171da177e4SLinus Torvalds 	u16 vendor_id;
3181da177e4SLinus Torvalds 	struct work_struct int_task_event;
3191da177e4SLinus Torvalds 	wait_queue_head_t queue;	/* sleep & wake process */
320*9f3f4681SGreg Kroah-Hartman 	struct dentry *dentry;		/* debugfs dentry */
3211da177e4SLinus Torvalds };
3221da177e4SLinus Torvalds 
3231da177e4SLinus Torvalds struct irq_mapping {
3241da177e4SLinus Torvalds 	u8 barber_pole;
3251da177e4SLinus Torvalds 	u8 valid_INT;
3261da177e4SLinus Torvalds 	u8 interrupt[4];
3271da177e4SLinus Torvalds };
3281da177e4SLinus Torvalds 
3291da177e4SLinus Torvalds struct resource_lists {
3301da177e4SLinus Torvalds 	struct pci_resource *mem_head;
3311da177e4SLinus Torvalds 	struct pci_resource *p_mem_head;
3321da177e4SLinus Torvalds 	struct pci_resource *io_head;
3331da177e4SLinus Torvalds 	struct pci_resource *bus_head;
3341da177e4SLinus Torvalds 	struct irq_mapping *irqs;
3351da177e4SLinus Torvalds };
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds #define ROM_PHY_ADDR			0x0F0000
3381da177e4SLinus Torvalds #define ROM_PHY_LEN			0x00ffff
3391da177e4SLinus Torvalds 
3401da177e4SLinus Torvalds #define PCI_HPC_ID			0xA0F7
3411da177e4SLinus Torvalds #define PCI_SUB_HPC_ID			0xA2F7
3421da177e4SLinus Torvalds #define PCI_SUB_HPC_ID2			0xA2F8
3431da177e4SLinus Torvalds #define PCI_SUB_HPC_ID3			0xA2F9
3441da177e4SLinus Torvalds #define PCI_SUB_HPC_ID_INTC		0xA2FA
3451da177e4SLinus Torvalds #define PCI_SUB_HPC_ID4			0xA2FD
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds #define INT_BUTTON_IGNORE		0
3481da177e4SLinus Torvalds #define INT_PRESENCE_ON			1
3491da177e4SLinus Torvalds #define INT_PRESENCE_OFF		2
3501da177e4SLinus Torvalds #define INT_SWITCH_CLOSE		3
3511da177e4SLinus Torvalds #define INT_SWITCH_OPEN			4
3521da177e4SLinus Torvalds #define INT_POWER_FAULT			5
3531da177e4SLinus Torvalds #define INT_POWER_FAULT_CLEAR		6
3541da177e4SLinus Torvalds #define INT_BUTTON_PRESS		7
3551da177e4SLinus Torvalds #define INT_BUTTON_RELEASE		8
3561da177e4SLinus Torvalds #define INT_BUTTON_CANCEL		9
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds #define STATIC_STATE			0
3591da177e4SLinus Torvalds #define BLINKINGON_STATE		1
3601da177e4SLinus Torvalds #define BLINKINGOFF_STATE		2
3611da177e4SLinus Torvalds #define POWERON_STATE			3
3621da177e4SLinus Torvalds #define POWEROFF_STATE			4
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds #define PCISLOT_INTERLOCK_CLOSED	0x00000001
3651da177e4SLinus Torvalds #define PCISLOT_ADAPTER_PRESENT		0x00000002
3661da177e4SLinus Torvalds #define PCISLOT_POWERED			0x00000004
3671da177e4SLinus Torvalds #define PCISLOT_66_MHZ_OPERATION	0x00000008
3681da177e4SLinus Torvalds #define PCISLOT_64_BIT_OPERATION	0x00000010
3691da177e4SLinus Torvalds #define PCISLOT_REPLACE_SUPPORTED	0x00000020
3701da177e4SLinus Torvalds #define PCISLOT_ADD_SUPPORTED		0x00000040
3711da177e4SLinus Torvalds #define PCISLOT_INTERLOCK_SUPPORTED	0x00000080
3721da177e4SLinus Torvalds #define PCISLOT_66_MHZ_SUPPORTED	0x00000100
3731da177e4SLinus Torvalds #define PCISLOT_64_BIT_SUPPORTED	0x00000200
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds #define PCI_TO_PCI_BRIDGE_CLASS		0x00060400
3761da177e4SLinus Torvalds 
3771da177e4SLinus Torvalds #define INTERLOCK_OPEN			0x00000002
3781da177e4SLinus Torvalds #define ADD_NOT_SUPPORTED		0x00000003
3791da177e4SLinus Torvalds #define CARD_FUNCTIONING		0x00000005
3801da177e4SLinus Torvalds #define ADAPTER_NOT_SAME		0x00000006
3811da177e4SLinus Torvalds #define NO_ADAPTER_PRESENT		0x00000009
3821da177e4SLinus Torvalds #define NOT_ENOUGH_RESOURCES		0x0000000B
3831da177e4SLinus Torvalds #define DEVICE_TYPE_NOT_SUPPORTED	0x0000000C
3841da177e4SLinus Torvalds #define POWER_FAILURE			0x0000000E
3851da177e4SLinus Torvalds 
3861da177e4SLinus Torvalds #define REMOVE_NOT_SUPPORTED		0x00000003
3871da177e4SLinus Torvalds 
3881da177e4SLinus Torvalds 
3891da177e4SLinus Torvalds /*
3901da177e4SLinus Torvalds  * error Messages
3911da177e4SLinus Torvalds  */
3921da177e4SLinus Torvalds #define msg_initialization_err	"Initialization failure, error=%d\n"
3931da177e4SLinus Torvalds #define msg_HPC_rev_error	"Unsupported revision of the PCI hot plug controller found.\n"
3941da177e4SLinus Torvalds #define msg_HPC_non_compaq_or_intel	"The PCI hot plug controller is not supported by this driver.\n"
3951da177e4SLinus Torvalds #define msg_HPC_not_supported	"this system is not supported by this version of cpqphpd. Upgrade to a newer version of cpqphpd\n"
3961da177e4SLinus Torvalds #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"
3971da177e4SLinus Torvalds #define msg_button_on		"PCI slot #%d - powering on due to button press.\n"
3981da177e4SLinus Torvalds #define msg_button_off		"PCI slot #%d - powering off due to button press.\n"
3991da177e4SLinus Torvalds #define msg_button_cancel	"PCI slot #%d - action canceled due to button press.\n"
4001da177e4SLinus Torvalds #define msg_button_ignore	"PCI slot #%d - button press ignored.  (action in progress...)\n"
4011da177e4SLinus Torvalds 
4021da177e4SLinus Torvalds 
403*9f3f4681SGreg Kroah-Hartman /* debugfs functions for the hotplug controller info */
404*9f3f4681SGreg Kroah-Hartman extern void cpqhp_initialize_debugfs		(void);
405*9f3f4681SGreg Kroah-Hartman extern void cpqhp_shutdown_debugfs		(void);
406*9f3f4681SGreg Kroah-Hartman extern void cpqhp_create_debugfs_files		(struct controller *ctrl);
407*9f3f4681SGreg Kroah-Hartman extern void cpqhp_remove_debugfs_files		(struct controller *ctrl);
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds /* controller functions */
4101da177e4SLinus Torvalds extern void	cpqhp_pushbutton_thread		(unsigned long event_pointer);
4111da177e4SLinus Torvalds extern irqreturn_t cpqhp_ctrl_intr		(int IRQ, void *data, struct pt_regs *regs);
4121da177e4SLinus Torvalds extern int	cpqhp_find_available_resources	(struct controller *ctrl, void __iomem *rom_start);
4131da177e4SLinus Torvalds extern int	cpqhp_event_start_thread	(void);
4141da177e4SLinus Torvalds extern void	cpqhp_event_stop_thread		(void);
4151da177e4SLinus Torvalds extern struct pci_func *cpqhp_slot_create	(unsigned char busnumber);
4161da177e4SLinus Torvalds extern struct pci_func *cpqhp_slot_find		(unsigned char bus, unsigned char device, unsigned char index);
4171da177e4SLinus Torvalds extern int	cpqhp_process_SI		(struct controller *ctrl, struct pci_func *func);
4181da177e4SLinus Torvalds extern int	cpqhp_process_SS		(struct controller *ctrl, struct pci_func *func);
4191da177e4SLinus Torvalds extern int	cpqhp_hardware_test		(struct controller *ctrl, int test_num);
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds /* resource functions */
4221da177e4SLinus Torvalds extern int	cpqhp_resource_sort_and_combine	(struct pci_resource **head);
4231da177e4SLinus Torvalds 
4241da177e4SLinus Torvalds /* pci functions */
4251da177e4SLinus Torvalds extern int	cpqhp_set_irq			(u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num);
4261da177e4SLinus Torvalds extern int	cpqhp_get_bus_dev		(struct controller *ctrl, u8 *bus_num, u8 *dev_num, u8 slot);
4271da177e4SLinus Torvalds extern int	cpqhp_save_config		(struct controller *ctrl, int busnumber, int is_hot_plug);
4281da177e4SLinus Torvalds extern int	cpqhp_save_base_addr_length	(struct controller *ctrl, struct pci_func * func);
4291da177e4SLinus Torvalds extern int	cpqhp_save_used_resources	(struct controller *ctrl, struct pci_func * func);
4301da177e4SLinus Torvalds extern int	cpqhp_configure_board		(struct controller *ctrl, struct pci_func * func);
4311da177e4SLinus Torvalds extern int	cpqhp_save_slot_config		(struct controller *ctrl, struct pci_func * new_slot);
4321da177e4SLinus Torvalds extern int	cpqhp_valid_replace		(struct controller *ctrl, struct pci_func * func);
4331da177e4SLinus Torvalds extern void	cpqhp_destroy_board_resources	(struct pci_func * func);
4341da177e4SLinus Torvalds extern int	cpqhp_return_board_resources	(struct pci_func * func, struct resource_lists * resources);
4351da177e4SLinus Torvalds extern void	cpqhp_destroy_resource_list	(struct resource_lists * resources);
4361da177e4SLinus Torvalds extern int	cpqhp_configure_device		(struct controller* ctrl, struct pci_func* func);
4371da177e4SLinus Torvalds extern int	cpqhp_unconfigure_device	(struct pci_func* func);
4381da177e4SLinus Torvalds 
4391da177e4SLinus Torvalds /* Global variables */
4401da177e4SLinus Torvalds extern int cpqhp_debug;
4411da177e4SLinus Torvalds extern int cpqhp_legacy_mode;
4421da177e4SLinus Torvalds extern struct controller *cpqhp_ctrl_list;
4431da177e4SLinus Torvalds extern struct pci_func *cpqhp_slot_list[256];
4441da177e4SLinus Torvalds 
4451da177e4SLinus Torvalds /* these can be gotten rid of, but for debugging they are purty */
4461da177e4SLinus Torvalds extern u8 cpqhp_nic_irq;
4471da177e4SLinus Torvalds extern u8 cpqhp_disk_irq;
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds 
4501da177e4SLinus Torvalds /* inline functions */
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds /*
4531da177e4SLinus Torvalds  * return_resource
4541da177e4SLinus Torvalds  *
4551da177e4SLinus Torvalds  * Puts node back in the resource list pointed to by head
4561da177e4SLinus Torvalds  *
4571da177e4SLinus Torvalds  */
4581da177e4SLinus Torvalds static inline void return_resource(struct pci_resource **head, struct pci_resource *node)
4591da177e4SLinus Torvalds {
4601da177e4SLinus Torvalds 	if (!node || !head)
4611da177e4SLinus Torvalds 		return;
4621da177e4SLinus Torvalds 	node->next = *head;
4631da177e4SLinus Torvalds 	*head = node;
4641da177e4SLinus Torvalds }
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds static inline void set_SOGO(struct controller *ctrl)
4671da177e4SLinus Torvalds {
4681da177e4SLinus Torvalds 	u16 misc;
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds 	misc = readw(ctrl->hpc_reg + MISC);
4711da177e4SLinus Torvalds 	misc = (misc | 0x0001) & 0xFFFB;
4721da177e4SLinus Torvalds 	writew(misc, ctrl->hpc_reg + MISC);
4731da177e4SLinus Torvalds }
4741da177e4SLinus Torvalds 
4751da177e4SLinus Torvalds 
4761da177e4SLinus Torvalds static inline void amber_LED_on(struct controller *ctrl, u8 slot)
4771da177e4SLinus Torvalds {
4781da177e4SLinus Torvalds 	u32 led_control;
4791da177e4SLinus Torvalds 
4801da177e4SLinus Torvalds 	led_control = readl(ctrl->hpc_reg + LED_CONTROL);
4811da177e4SLinus Torvalds 	led_control |= (0x01010000L << slot);
4821da177e4SLinus Torvalds 	writel(led_control, ctrl->hpc_reg + LED_CONTROL);
4831da177e4SLinus Torvalds }
4841da177e4SLinus Torvalds 
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds static inline void amber_LED_off(struct controller *ctrl, u8 slot)
4871da177e4SLinus Torvalds {
4881da177e4SLinus Torvalds 	u32 led_control;
4891da177e4SLinus Torvalds 
4901da177e4SLinus Torvalds 	led_control = readl(ctrl->hpc_reg + LED_CONTROL);
4911da177e4SLinus Torvalds 	led_control &= ~(0x01010000L << slot);
4921da177e4SLinus Torvalds 	writel(led_control, ctrl->hpc_reg + LED_CONTROL);
4931da177e4SLinus Torvalds }
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds 
4961da177e4SLinus Torvalds static inline int read_amber_LED(struct controller *ctrl, u8 slot)
4971da177e4SLinus Torvalds {
4981da177e4SLinus Torvalds 	u32 led_control;
4991da177e4SLinus Torvalds 
5001da177e4SLinus Torvalds 	led_control = readl(ctrl->hpc_reg + LED_CONTROL);
5011da177e4SLinus Torvalds 	led_control &= (0x01010000L << slot);
5021da177e4SLinus Torvalds 
5031da177e4SLinus Torvalds 	return led_control ? 1 : 0;
5041da177e4SLinus Torvalds }
5051da177e4SLinus Torvalds 
5061da177e4SLinus Torvalds 
5071da177e4SLinus Torvalds static inline void green_LED_on(struct controller *ctrl, u8 slot)
5081da177e4SLinus Torvalds {
5091da177e4SLinus Torvalds 	u32 led_control;
5101da177e4SLinus Torvalds 
5111da177e4SLinus Torvalds 	led_control = readl(ctrl->hpc_reg + LED_CONTROL);
5121da177e4SLinus Torvalds 	led_control |= 0x0101L << slot;
5131da177e4SLinus Torvalds 	writel(led_control, ctrl->hpc_reg + LED_CONTROL);
5141da177e4SLinus Torvalds }
5151da177e4SLinus Torvalds 
5161da177e4SLinus Torvalds static inline void green_LED_off(struct controller *ctrl, u8 slot)
5171da177e4SLinus Torvalds {
5181da177e4SLinus Torvalds 	u32 led_control;
5191da177e4SLinus Torvalds 
5201da177e4SLinus Torvalds 	led_control = readl(ctrl->hpc_reg + LED_CONTROL);
5211da177e4SLinus Torvalds 	led_control &= ~(0x0101L << slot);
5221da177e4SLinus Torvalds 	writel(led_control, ctrl->hpc_reg + LED_CONTROL);
5231da177e4SLinus Torvalds }
5241da177e4SLinus Torvalds 
5251da177e4SLinus Torvalds 
5261da177e4SLinus Torvalds static inline void green_LED_blink(struct controller *ctrl, u8 slot)
5271da177e4SLinus Torvalds {
5281da177e4SLinus Torvalds 	u32 led_control;
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds 	led_control = readl(ctrl->hpc_reg + LED_CONTROL);
5311da177e4SLinus Torvalds 	led_control &= ~(0x0101L << slot);
5321da177e4SLinus Torvalds 	led_control |= (0x0001L << slot);
5331da177e4SLinus Torvalds 	writel(led_control, ctrl->hpc_reg + LED_CONTROL);
5341da177e4SLinus Torvalds }
5351da177e4SLinus Torvalds 
5361da177e4SLinus Torvalds 
5371da177e4SLinus Torvalds static inline void slot_disable(struct controller *ctrl, u8 slot)
5381da177e4SLinus Torvalds {
5391da177e4SLinus Torvalds 	u8 slot_enable;
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds 	slot_enable = readb(ctrl->hpc_reg + SLOT_ENABLE);
5421da177e4SLinus Torvalds 	slot_enable &= ~(0x01 << slot);
5431da177e4SLinus Torvalds 	writeb(slot_enable, ctrl->hpc_reg + SLOT_ENABLE);
5441da177e4SLinus Torvalds }
5451da177e4SLinus Torvalds 
5461da177e4SLinus Torvalds 
5471da177e4SLinus Torvalds static inline void slot_enable(struct controller *ctrl, u8 slot)
5481da177e4SLinus Torvalds {
5491da177e4SLinus Torvalds 	u8 slot_enable;
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds 	slot_enable = readb(ctrl->hpc_reg + SLOT_ENABLE);
5521da177e4SLinus Torvalds 	slot_enable |= (0x01 << slot);
5531da177e4SLinus Torvalds 	writeb(slot_enable, ctrl->hpc_reg + SLOT_ENABLE);
5541da177e4SLinus Torvalds }
5551da177e4SLinus Torvalds 
5561da177e4SLinus Torvalds 
5571da177e4SLinus Torvalds static inline u8 is_slot_enabled(struct controller *ctrl, u8 slot)
5581da177e4SLinus Torvalds {
5591da177e4SLinus Torvalds 	u8 slot_enable;
5601da177e4SLinus Torvalds 
5611da177e4SLinus Torvalds 	slot_enable = readb(ctrl->hpc_reg + SLOT_ENABLE);
5621da177e4SLinus Torvalds 	slot_enable &= (0x01 << slot);
5631da177e4SLinus Torvalds 	return slot_enable ? 1 : 0;
5641da177e4SLinus Torvalds }
5651da177e4SLinus Torvalds 
5661da177e4SLinus Torvalds 
5671da177e4SLinus Torvalds static inline u8 read_slot_enable(struct controller *ctrl)
5681da177e4SLinus Torvalds {
5691da177e4SLinus Torvalds 	return readb(ctrl->hpc_reg + SLOT_ENABLE);
5701da177e4SLinus Torvalds }
5711da177e4SLinus Torvalds 
5721da177e4SLinus Torvalds 
5731da177e4SLinus Torvalds /*
5741da177e4SLinus Torvalds  * get_controller_speed - find the current frequency/mode of controller.
5751da177e4SLinus Torvalds  *
5761da177e4SLinus Torvalds  * @ctrl: controller to get frequency/mode for.
5771da177e4SLinus Torvalds  *
5781da177e4SLinus Torvalds  * Returns controller speed.
5791da177e4SLinus Torvalds  *
5801da177e4SLinus Torvalds  */
5811da177e4SLinus Torvalds static inline u8 get_controller_speed(struct controller *ctrl)
5821da177e4SLinus Torvalds {
5831da177e4SLinus Torvalds 	u8 curr_freq;
5841da177e4SLinus Torvalds  	u16 misc;
5851da177e4SLinus Torvalds 
5861da177e4SLinus Torvalds 	if (ctrl->pcix_support) {
5871da177e4SLinus Torvalds 		curr_freq = readb(ctrl->hpc_reg + NEXT_CURR_FREQ);
5881da177e4SLinus Torvalds 		if ((curr_freq & 0xB0) == 0xB0)
5891da177e4SLinus Torvalds 			return PCI_SPEED_133MHz_PCIX;
5901da177e4SLinus Torvalds 		if ((curr_freq & 0xA0) == 0xA0)
5911da177e4SLinus Torvalds 			return PCI_SPEED_100MHz_PCIX;
5921da177e4SLinus Torvalds 		if ((curr_freq & 0x90) == 0x90)
5931da177e4SLinus Torvalds 			return PCI_SPEED_66MHz_PCIX;
5941da177e4SLinus Torvalds 		if (curr_freq & 0x10)
5951da177e4SLinus Torvalds 			return PCI_SPEED_66MHz;
5961da177e4SLinus Torvalds 
5971da177e4SLinus Torvalds 		return PCI_SPEED_33MHz;
5981da177e4SLinus Torvalds 	}
5991da177e4SLinus Torvalds 
6001da177e4SLinus Torvalds  	misc = readw(ctrl->hpc_reg + MISC);
6011da177e4SLinus Torvalds  	return (misc & 0x0800) ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
6021da177e4SLinus Torvalds }
6031da177e4SLinus Torvalds 
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds /*
6061da177e4SLinus Torvalds  * get_adapter_speed - find the max supported frequency/mode of adapter.
6071da177e4SLinus Torvalds  *
6081da177e4SLinus Torvalds  * @ctrl: hotplug controller.
6091da177e4SLinus Torvalds  * @hp_slot: hotplug slot where adapter is installed.
6101da177e4SLinus Torvalds  *
6111da177e4SLinus Torvalds  * Returns adapter speed.
6121da177e4SLinus Torvalds  *
6131da177e4SLinus Torvalds  */
6141da177e4SLinus Torvalds static inline u8 get_adapter_speed(struct controller *ctrl, u8 hp_slot)
6151da177e4SLinus Torvalds {
6161da177e4SLinus Torvalds 	u32 temp_dword = readl(ctrl->hpc_reg + NON_INT_INPUT);
6171da177e4SLinus Torvalds 	dbg("slot: %d, PCIXCAP: %8x\n", hp_slot, temp_dword);
6181da177e4SLinus Torvalds 	if (ctrl->pcix_support) {
6191da177e4SLinus Torvalds 		if (temp_dword & (0x10000 << hp_slot))
6201da177e4SLinus Torvalds 			return PCI_SPEED_133MHz_PCIX;
6211da177e4SLinus Torvalds 		if (temp_dword & (0x100 << hp_slot))
6221da177e4SLinus Torvalds 			return PCI_SPEED_66MHz_PCIX;
6231da177e4SLinus Torvalds 	}
6241da177e4SLinus Torvalds 
6251da177e4SLinus Torvalds 	if (temp_dword & (0x01 << hp_slot))
6261da177e4SLinus Torvalds 		return PCI_SPEED_66MHz;
6271da177e4SLinus Torvalds 
6281da177e4SLinus Torvalds 	return PCI_SPEED_33MHz;
6291da177e4SLinus Torvalds }
6301da177e4SLinus Torvalds 
6311da177e4SLinus Torvalds static inline void enable_slot_power(struct controller *ctrl, u8 slot)
6321da177e4SLinus Torvalds {
6331da177e4SLinus Torvalds 	u8 slot_power;
6341da177e4SLinus Torvalds 
6351da177e4SLinus Torvalds 	slot_power = readb(ctrl->hpc_reg + SLOT_POWER);
6361da177e4SLinus Torvalds 	slot_power |= (0x01 << slot);
6371da177e4SLinus Torvalds 	writeb(slot_power, ctrl->hpc_reg + SLOT_POWER);
6381da177e4SLinus Torvalds }
6391da177e4SLinus Torvalds 
6401da177e4SLinus Torvalds static inline void disable_slot_power(struct controller *ctrl, u8 slot)
6411da177e4SLinus Torvalds {
6421da177e4SLinus Torvalds 	u8 slot_power;
6431da177e4SLinus Torvalds 
6441da177e4SLinus Torvalds 	slot_power = readb(ctrl->hpc_reg + SLOT_POWER);
6451da177e4SLinus Torvalds 	slot_power &= ~(0x01 << slot);
6461da177e4SLinus Torvalds 	writeb(slot_power, ctrl->hpc_reg + SLOT_POWER);
6471da177e4SLinus Torvalds }
6481da177e4SLinus Torvalds 
6491da177e4SLinus Torvalds 
6501da177e4SLinus Torvalds static inline int cpq_get_attention_status(struct controller *ctrl, struct slot *slot)
6511da177e4SLinus Torvalds {
6521da177e4SLinus Torvalds 	u8 hp_slot;
6531da177e4SLinus Torvalds 
6541da177e4SLinus Torvalds 	hp_slot = slot->device - ctrl->slot_device_offset;
6551da177e4SLinus Torvalds 
6561da177e4SLinus Torvalds 	return read_amber_LED(ctrl, hp_slot);
6571da177e4SLinus Torvalds }
6581da177e4SLinus Torvalds 
6591da177e4SLinus Torvalds 
6601da177e4SLinus Torvalds static inline int get_slot_enabled(struct controller *ctrl, struct slot *slot)
6611da177e4SLinus Torvalds {
6621da177e4SLinus Torvalds 	u8 hp_slot;
6631da177e4SLinus Torvalds 
6641da177e4SLinus Torvalds 	hp_slot = slot->device - ctrl->slot_device_offset;
6651da177e4SLinus Torvalds 
6661da177e4SLinus Torvalds 	return is_slot_enabled(ctrl, hp_slot);
6671da177e4SLinus Torvalds }
6681da177e4SLinus Torvalds 
6691da177e4SLinus Torvalds 
6701da177e4SLinus Torvalds static inline int cpq_get_latch_status(struct controller *ctrl, struct slot *slot)
6711da177e4SLinus Torvalds {
6721da177e4SLinus Torvalds 	u32 status;
6731da177e4SLinus Torvalds 	u8 hp_slot;
6741da177e4SLinus Torvalds 
6751da177e4SLinus Torvalds 	hp_slot = slot->device - ctrl->slot_device_offset;
6761da177e4SLinus Torvalds 	dbg("%s: slot->device = %d, ctrl->slot_device_offset = %d \n",
6771da177e4SLinus Torvalds 	    __FUNCTION__, slot->device, ctrl->slot_device_offset);
6781da177e4SLinus Torvalds 
6791da177e4SLinus Torvalds 	status = (readl(ctrl->hpc_reg + INT_INPUT_CLEAR) & (0x01L << hp_slot));
6801da177e4SLinus Torvalds 
6811da177e4SLinus Torvalds 	return(status == 0) ? 1 : 0;
6821da177e4SLinus Torvalds }
6831da177e4SLinus Torvalds 
6841da177e4SLinus Torvalds 
6851da177e4SLinus Torvalds static inline int get_presence_status(struct controller *ctrl, struct slot *slot)
6861da177e4SLinus Torvalds {
6871da177e4SLinus Torvalds 	int presence_save = 0;
6881da177e4SLinus Torvalds 	u8 hp_slot;
6891da177e4SLinus Torvalds 	u32 tempdword;
6901da177e4SLinus Torvalds 
6911da177e4SLinus Torvalds 	hp_slot = slot->device - ctrl->slot_device_offset;
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds 	tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
6941da177e4SLinus Torvalds 	presence_save = (int) ((((~tempdword) >> 23) | ((~tempdword) >> 15)) >> hp_slot) & 0x02;
6951da177e4SLinus Torvalds 
6961da177e4SLinus Torvalds 	return presence_save;
6971da177e4SLinus Torvalds }
6981da177e4SLinus Torvalds 
6991da177e4SLinus Torvalds #define SLOT_NAME_SIZE 10
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
7021da177e4SLinus Torvalds {
7031da177e4SLinus Torvalds 	snprintf(buffer, buffer_size, "%d", slot->number);
7041da177e4SLinus Torvalds }
7051da177e4SLinus Torvalds 
7061da177e4SLinus Torvalds 
7071da177e4SLinus Torvalds static inline int wait_for_ctrl_irq(struct controller *ctrl)
7081da177e4SLinus Torvalds {
7091da177e4SLinus Torvalds         DECLARE_WAITQUEUE(wait, current);
7101da177e4SLinus Torvalds 	int retval = 0;
7111da177e4SLinus Torvalds 
7121da177e4SLinus Torvalds 	dbg("%s - start\n", __FUNCTION__);
7131da177e4SLinus Torvalds 	add_wait_queue(&ctrl->queue, &wait);
7141da177e4SLinus Torvalds 	/* Sleep for up to 1 second to wait for the LED to change. */
7151da177e4SLinus Torvalds 	msleep_interruptible(1000);
7161da177e4SLinus Torvalds 	remove_wait_queue(&ctrl->queue, &wait);
7171da177e4SLinus Torvalds 	if (signal_pending(current))
7181da177e4SLinus Torvalds 		retval =  -EINTR;
7191da177e4SLinus Torvalds 
7201da177e4SLinus Torvalds 	dbg("%s - end\n", __FUNCTION__);
7211da177e4SLinus Torvalds 	return retval;
7221da177e4SLinus Torvalds }
7231da177e4SLinus Torvalds 
7241da177e4SLinus Torvalds #endif
7251da177e4SLinus Torvalds 
726