18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci#ifndef __IBMPHP_H
38c2ecf20Sopenharmony_ci#define __IBMPHP_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * IBM Hot Plug Controller Driver
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Written By: Jyoti Shah, Tong Yu, Irene Zubarev, IBM Corporation
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
118c2ecf20Sopenharmony_ci * Copyright (C) 2001-2003 IBM Corp.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * All rights reserved.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * Send feedback to <gregkh@us.ibm.com>
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/pci_hotplug.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciextern int ibmphp_debug;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#if !defined(MODULE)
248c2ecf20Sopenharmony_ci	#define MY_NAME "ibmphpd"
258c2ecf20Sopenharmony_ci#else
268c2ecf20Sopenharmony_ci	#define MY_NAME THIS_MODULE->name
278c2ecf20Sopenharmony_ci#endif
288c2ecf20Sopenharmony_ci#define debug(fmt, arg...) do { if (ibmphp_debug == 1) printk(KERN_DEBUG "%s: " fmt, MY_NAME, ## arg); } while (0)
298c2ecf20Sopenharmony_ci#define debug_pci(fmt, arg...) do { if (ibmphp_debug) printk(KERN_DEBUG "%s: " fmt, MY_NAME, ## arg); } while (0)
308c2ecf20Sopenharmony_ci#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME, ## arg)
318c2ecf20Sopenharmony_ci#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME, ## arg)
328c2ecf20Sopenharmony_ci#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME, ## arg)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* EBDA stuff */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/***********************************************************
388c2ecf20Sopenharmony_ci* SLOT CAPABILITY                                          *
398c2ecf20Sopenharmony_ci***********************************************************/
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define EBDA_SLOT_133_MAX		0x20
428c2ecf20Sopenharmony_ci#define EBDA_SLOT_100_MAX		0x10
438c2ecf20Sopenharmony_ci#define EBDA_SLOT_66_MAX		0x02
448c2ecf20Sopenharmony_ci#define EBDA_SLOT_PCIX_CAP		0x08
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/************************************************************
488c2ecf20Sopenharmony_ci*  RESOURCE TYPE                                             *
498c2ecf20Sopenharmony_ci************************************************************/
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define EBDA_RSRC_TYPE_MASK		0x03
528c2ecf20Sopenharmony_ci#define EBDA_IO_RSRC_TYPE		0x00
538c2ecf20Sopenharmony_ci#define EBDA_MEM_RSRC_TYPE		0x01
548c2ecf20Sopenharmony_ci#define EBDA_PFM_RSRC_TYPE		0x03
558c2ecf20Sopenharmony_ci#define EBDA_RES_RSRC_TYPE		0x02
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*************************************************************
598c2ecf20Sopenharmony_ci*  IO RESTRICTION TYPE                                       *
608c2ecf20Sopenharmony_ci*************************************************************/
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define EBDA_IO_RESTRI_MASK		0x0c
638c2ecf20Sopenharmony_ci#define EBDA_NO_RESTRI			0x00
648c2ecf20Sopenharmony_ci#define EBDA_AVO_VGA_ADDR		0x04
658c2ecf20Sopenharmony_ci#define EBDA_AVO_VGA_ADDR_AND_ALIA	0x08
668c2ecf20Sopenharmony_ci#define EBDA_AVO_ISA_ADDR		0x0c
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/**************************************************************
708c2ecf20Sopenharmony_ci*  DEVICE TYPE DEF                                            *
718c2ecf20Sopenharmony_ci**************************************************************/
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#define EBDA_DEV_TYPE_MASK		0x10
748c2ecf20Sopenharmony_ci#define EBDA_PCI_DEV			0x10
758c2ecf20Sopenharmony_ci#define EBDA_NON_PCI_DEV		0x00
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/***************************************************************
798c2ecf20Sopenharmony_ci*  PRIMARY DEF DEFINITION                                      *
808c2ecf20Sopenharmony_ci***************************************************************/
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define EBDA_PRI_DEF_MASK		0x20
838c2ecf20Sopenharmony_ci#define EBDA_PRI_PCI_BUS_INFO		0x20
848c2ecf20Sopenharmony_ci#define EBDA_NORM_DEV_RSRC_INFO		0x00
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci//--------------------------------------------------------------
888c2ecf20Sopenharmony_ci// RIO TABLE DATA STRUCTURE
898c2ecf20Sopenharmony_ci//--------------------------------------------------------------
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistruct rio_table_hdr {
928c2ecf20Sopenharmony_ci	u8 ver_num;
938c2ecf20Sopenharmony_ci	u8 scal_count;
948c2ecf20Sopenharmony_ci	u8 riodev_count;
958c2ecf20Sopenharmony_ci	u16 offset;
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci//-------------------------------------------------------------
998c2ecf20Sopenharmony_ci// SCALABILITY DETAIL
1008c2ecf20Sopenharmony_ci//-------------------------------------------------------------
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct scal_detail {
1038c2ecf20Sopenharmony_ci	u8 node_id;
1048c2ecf20Sopenharmony_ci	u32 cbar;
1058c2ecf20Sopenharmony_ci	u8 port0_node_connect;
1068c2ecf20Sopenharmony_ci	u8 port0_port_connect;
1078c2ecf20Sopenharmony_ci	u8 port1_node_connect;
1088c2ecf20Sopenharmony_ci	u8 port1_port_connect;
1098c2ecf20Sopenharmony_ci	u8 port2_node_connect;
1108c2ecf20Sopenharmony_ci	u8 port2_port_connect;
1118c2ecf20Sopenharmony_ci	u8 chassis_num;
1128c2ecf20Sopenharmony_ci//	struct list_head scal_detail_list;
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci//--------------------------------------------------------------
1168c2ecf20Sopenharmony_ci// RIO DETAIL
1178c2ecf20Sopenharmony_ci//--------------------------------------------------------------
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistruct rio_detail {
1208c2ecf20Sopenharmony_ci	u8 rio_node_id;
1218c2ecf20Sopenharmony_ci	u32 bbar;
1228c2ecf20Sopenharmony_ci	u8 rio_type;
1238c2ecf20Sopenharmony_ci	u8 owner_id;
1248c2ecf20Sopenharmony_ci	u8 port0_node_connect;
1258c2ecf20Sopenharmony_ci	u8 port0_port_connect;
1268c2ecf20Sopenharmony_ci	u8 port1_node_connect;
1278c2ecf20Sopenharmony_ci	u8 port1_port_connect;
1288c2ecf20Sopenharmony_ci	u8 first_slot_num;
1298c2ecf20Sopenharmony_ci	u8 status;
1308c2ecf20Sopenharmony_ci	u8 wpindex;
1318c2ecf20Sopenharmony_ci	u8 chassis_num;
1328c2ecf20Sopenharmony_ci	struct list_head rio_detail_list;
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistruct opt_rio {
1368c2ecf20Sopenharmony_ci	u8 rio_type;
1378c2ecf20Sopenharmony_ci	u8 chassis_num;
1388c2ecf20Sopenharmony_ci	u8 first_slot_num;
1398c2ecf20Sopenharmony_ci	u8 middle_num;
1408c2ecf20Sopenharmony_ci	struct list_head opt_rio_list;
1418c2ecf20Sopenharmony_ci};
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistruct opt_rio_lo {
1448c2ecf20Sopenharmony_ci	u8 rio_type;
1458c2ecf20Sopenharmony_ci	u8 chassis_num;
1468c2ecf20Sopenharmony_ci	u8 first_slot_num;
1478c2ecf20Sopenharmony_ci	u8 middle_num;
1488c2ecf20Sopenharmony_ci	u8 pack_count;
1498c2ecf20Sopenharmony_ci	struct list_head opt_rio_lo_list;
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/****************************************************************
1538c2ecf20Sopenharmony_ci*  HPC DESCRIPTOR NODE                                          *
1548c2ecf20Sopenharmony_ci****************************************************************/
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistruct ebda_hpc_list {
1578c2ecf20Sopenharmony_ci	u8 format;
1588c2ecf20Sopenharmony_ci	u16 num_ctlrs;
1598c2ecf20Sopenharmony_ci	short phys_addr;
1608c2ecf20Sopenharmony_ci//      struct list_head ebda_hpc_list;
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci/*****************************************************************
1638c2ecf20Sopenharmony_ci*   IN HPC DATA STRUCTURE, THE ASSOCIATED SLOT AND BUS           *
1648c2ecf20Sopenharmony_ci*   STRUCTURE                                                    *
1658c2ecf20Sopenharmony_ci*****************************************************************/
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistruct ebda_hpc_slot {
1688c2ecf20Sopenharmony_ci	u8 slot_num;
1698c2ecf20Sopenharmony_ci	u32 slot_bus_num;
1708c2ecf20Sopenharmony_ci	u8 ctl_index;
1718c2ecf20Sopenharmony_ci	u8 slot_cap;
1728c2ecf20Sopenharmony_ci};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cistruct ebda_hpc_bus {
1758c2ecf20Sopenharmony_ci	u32 bus_num;
1768c2ecf20Sopenharmony_ci	u8 slots_at_33_conv;
1778c2ecf20Sopenharmony_ci	u8 slots_at_66_conv;
1788c2ecf20Sopenharmony_ci	u8 slots_at_66_pcix;
1798c2ecf20Sopenharmony_ci	u8 slots_at_100_pcix;
1808c2ecf20Sopenharmony_ci	u8 slots_at_133_pcix;
1818c2ecf20Sopenharmony_ci};
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/********************************************************************
1858c2ecf20Sopenharmony_ci*   THREE TYPE OF HOT PLUG CONTROLLER                                *
1868c2ecf20Sopenharmony_ci********************************************************************/
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistruct isa_ctlr_access {
1898c2ecf20Sopenharmony_ci	u16 io_start;
1908c2ecf20Sopenharmony_ci	u16 io_end;
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistruct pci_ctlr_access {
1948c2ecf20Sopenharmony_ci	u8 bus;
1958c2ecf20Sopenharmony_ci	u8 dev_fun;
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistruct wpeg_i2c_ctlr_access {
1998c2ecf20Sopenharmony_ci	ulong wpegbbar;
2008c2ecf20Sopenharmony_ci	u8 i2c_addr;
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define HPC_DEVICE_ID		0x0246
2048c2ecf20Sopenharmony_ci#define HPC_SUBSYSTEM_ID	0x0247
2058c2ecf20Sopenharmony_ci#define HPC_PCI_OFFSET		0x40
2068c2ecf20Sopenharmony_ci/*************************************************************************
2078c2ecf20Sopenharmony_ci*   RSTC DESCRIPTOR NODE                                                 *
2088c2ecf20Sopenharmony_ci*************************************************************************/
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cistruct ebda_rsrc_list {
2118c2ecf20Sopenharmony_ci	u8 format;
2128c2ecf20Sopenharmony_ci	u16 num_entries;
2138c2ecf20Sopenharmony_ci	u16 phys_addr;
2148c2ecf20Sopenharmony_ci	struct ebda_rsrc_list *next;
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/***************************************************************************
2198c2ecf20Sopenharmony_ci*   PCI RSRC NODE                                                          *
2208c2ecf20Sopenharmony_ci***************************************************************************/
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistruct ebda_pci_rsrc {
2238c2ecf20Sopenharmony_ci	u8 rsrc_type;
2248c2ecf20Sopenharmony_ci	u8 bus_num;
2258c2ecf20Sopenharmony_ci	u8 dev_fun;
2268c2ecf20Sopenharmony_ci	u32 start_addr;
2278c2ecf20Sopenharmony_ci	u32 end_addr;
2288c2ecf20Sopenharmony_ci	u8 marked;	/* for NVRAM */
2298c2ecf20Sopenharmony_ci	struct list_head ebda_pci_rsrc_list;
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci/***********************************************************
2348c2ecf20Sopenharmony_ci* BUS_INFO DATE STRUCTURE                                  *
2358c2ecf20Sopenharmony_ci***********************************************************/
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cistruct bus_info {
2388c2ecf20Sopenharmony_ci	u8 slot_min;
2398c2ecf20Sopenharmony_ci	u8 slot_max;
2408c2ecf20Sopenharmony_ci	u8 slot_count;
2418c2ecf20Sopenharmony_ci	u8 busno;
2428c2ecf20Sopenharmony_ci	u8 controller_id;
2438c2ecf20Sopenharmony_ci	u8 current_speed;
2448c2ecf20Sopenharmony_ci	u8 current_bus_mode;
2458c2ecf20Sopenharmony_ci	u8 index;
2468c2ecf20Sopenharmony_ci	u8 slots_at_33_conv;
2478c2ecf20Sopenharmony_ci	u8 slots_at_66_conv;
2488c2ecf20Sopenharmony_ci	u8 slots_at_66_pcix;
2498c2ecf20Sopenharmony_ci	u8 slots_at_100_pcix;
2508c2ecf20Sopenharmony_ci	u8 slots_at_133_pcix;
2518c2ecf20Sopenharmony_ci	struct list_head bus_info_list;
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci/***********************************************************
2568c2ecf20Sopenharmony_ci* GLOBAL VARIABLES                                         *
2578c2ecf20Sopenharmony_ci***********************************************************/
2588c2ecf20Sopenharmony_ciextern struct list_head ibmphp_ebda_pci_rsrc_head;
2598c2ecf20Sopenharmony_ciextern struct list_head ibmphp_slot_head;
2608c2ecf20Sopenharmony_ci/***********************************************************
2618c2ecf20Sopenharmony_ci* FUNCTION PROTOTYPES                                      *
2628c2ecf20Sopenharmony_ci***********************************************************/
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_civoid ibmphp_free_ebda_hpc_queue(void);
2658c2ecf20Sopenharmony_ciint ibmphp_access_ebda(void);
2668c2ecf20Sopenharmony_cistruct slot *ibmphp_get_slot_from_physical_num(u8);
2678c2ecf20Sopenharmony_ciint ibmphp_get_total_hp_slots(void);
2688c2ecf20Sopenharmony_civoid ibmphp_free_ibm_slot(struct slot *);
2698c2ecf20Sopenharmony_civoid ibmphp_free_bus_info_queue(void);
2708c2ecf20Sopenharmony_civoid ibmphp_free_ebda_pci_rsrc_queue(void);
2718c2ecf20Sopenharmony_cistruct bus_info *ibmphp_find_same_bus_num(u32);
2728c2ecf20Sopenharmony_ciint ibmphp_get_bus_index(u8);
2738c2ecf20Sopenharmony_ciu16 ibmphp_get_total_controllers(void);
2748c2ecf20Sopenharmony_ciint ibmphp_register_pci(void);
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/* passed parameters */
2778c2ecf20Sopenharmony_ci#define MEM		0
2788c2ecf20Sopenharmony_ci#define IO		1
2798c2ecf20Sopenharmony_ci#define PFMEM		2
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci/* bit masks */
2828c2ecf20Sopenharmony_ci#define RESTYPE		0x03
2838c2ecf20Sopenharmony_ci#define IOMASK		0x00	/* will need to take its complement */
2848c2ecf20Sopenharmony_ci#define MMASK		0x01
2858c2ecf20Sopenharmony_ci#define PFMASK		0x03
2868c2ecf20Sopenharmony_ci#define PCIDEVMASK	0x10	/* we should always have PCI devices */
2878c2ecf20Sopenharmony_ci#define PRIMARYBUSMASK	0x20
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci/* pci specific defines */
2908c2ecf20Sopenharmony_ci#define PCI_VENDOR_ID_NOTVALID		0xFFFF
2918c2ecf20Sopenharmony_ci#define PCI_HEADER_TYPE_MULTIDEVICE	0x80
2928c2ecf20Sopenharmony_ci#define PCI_HEADER_TYPE_MULTIBRIDGE	0x81
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci#define LATENCY		0x64
2958c2ecf20Sopenharmony_ci#define CACHE		64
2968c2ecf20Sopenharmony_ci#define DEVICEENABLE	0x015F		/* CPQ has 0x0157 */
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci#define IOBRIDGE	0x1000		/* 4k */
2998c2ecf20Sopenharmony_ci#define MEMBRIDGE	0x100000	/* 1M */
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci/* irqs */
3028c2ecf20Sopenharmony_ci#define SCSI_IRQ	0x09
3038c2ecf20Sopenharmony_ci#define LAN_IRQ		0x0A
3048c2ecf20Sopenharmony_ci#define OTHER_IRQ	0x0B
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci/* Data Structures */
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci/* type is of the form x x xx xx
3098c2ecf20Sopenharmony_ci *                     | |  |  |_ 00 - I/O, 01 - Memory, 11 - PFMemory
3108c2ecf20Sopenharmony_ci *                     | |  - 00 - No Restrictions, 01 - Avoid VGA, 10 - Avoid
3118c2ecf20Sopenharmony_ci *                     | |    VGA and their aliases, 11 - Avoid ISA
3128c2ecf20Sopenharmony_ci *                     | - 1 - PCI device, 0 - non pci device
3138c2ecf20Sopenharmony_ci *                     - 1 - Primary PCI Bus Information (0 if Normal device)
3148c2ecf20Sopenharmony_ci * the IO restrictions [2:3] are only for primary buses
3158c2ecf20Sopenharmony_ci */
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/* we need this struct because there could be several resource blocks
3198c2ecf20Sopenharmony_ci * allocated per primary bus in the EBDA
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_cistruct range_node {
3228c2ecf20Sopenharmony_ci	int rangeno;
3238c2ecf20Sopenharmony_ci	u32 start;
3248c2ecf20Sopenharmony_ci	u32 end;
3258c2ecf20Sopenharmony_ci	struct range_node *next;
3268c2ecf20Sopenharmony_ci};
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cistruct bus_node {
3298c2ecf20Sopenharmony_ci	u8 busno;
3308c2ecf20Sopenharmony_ci	int noIORanges;
3318c2ecf20Sopenharmony_ci	struct range_node *rangeIO;
3328c2ecf20Sopenharmony_ci	int noMemRanges;
3338c2ecf20Sopenharmony_ci	struct range_node *rangeMem;
3348c2ecf20Sopenharmony_ci	int noPFMemRanges;
3358c2ecf20Sopenharmony_ci	struct range_node *rangePFMem;
3368c2ecf20Sopenharmony_ci	int needIOUpdate;
3378c2ecf20Sopenharmony_ci	int needMemUpdate;
3388c2ecf20Sopenharmony_ci	int needPFMemUpdate;
3398c2ecf20Sopenharmony_ci	struct resource_node *firstIO;	/* first IO resource on the Bus */
3408c2ecf20Sopenharmony_ci	struct resource_node *firstMem;	/* first memory resource on the Bus */
3418c2ecf20Sopenharmony_ci	struct resource_node *firstPFMem;	/* first prefetchable memory resource on the Bus */
3428c2ecf20Sopenharmony_ci	struct resource_node *firstPFMemFromMem;	/* when run out of pfmem available, taking from Mem */
3438c2ecf20Sopenharmony_ci	struct list_head bus_list;
3448c2ecf20Sopenharmony_ci};
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_cistruct resource_node {
3478c2ecf20Sopenharmony_ci	int rangeno;
3488c2ecf20Sopenharmony_ci	u8 busno;
3498c2ecf20Sopenharmony_ci	u8 devfunc;
3508c2ecf20Sopenharmony_ci	u32 start;
3518c2ecf20Sopenharmony_ci	u32 end;
3528c2ecf20Sopenharmony_ci	u32 len;
3538c2ecf20Sopenharmony_ci	int type;		/* MEM, IO, PFMEM */
3548c2ecf20Sopenharmony_ci	u8 fromMem;		/* this is to indicate that the range is from
3558c2ecf20Sopenharmony_ci				 * from the Memory bucket rather than from PFMem */
3568c2ecf20Sopenharmony_ci	struct resource_node *next;
3578c2ecf20Sopenharmony_ci	struct resource_node *nextRange;	/* for the other mem range on bus */
3588c2ecf20Sopenharmony_ci};
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_cistruct res_needed {
3618c2ecf20Sopenharmony_ci	u32 mem;
3628c2ecf20Sopenharmony_ci	u32 pfmem;
3638c2ecf20Sopenharmony_ci	u32 io;
3648c2ecf20Sopenharmony_ci	u8 not_correct;		/* needed for return */
3658c2ecf20Sopenharmony_ci	int devices[32];	/* for device numbers behind this bridge */
3668c2ecf20Sopenharmony_ci};
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci/* functions */
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ciint ibmphp_rsrc_init(void);
3718c2ecf20Sopenharmony_ciint ibmphp_add_resource(struct resource_node *);
3728c2ecf20Sopenharmony_ciint ibmphp_remove_resource(struct resource_node *);
3738c2ecf20Sopenharmony_ciint ibmphp_find_resource(struct bus_node *, u32, struct resource_node **, int);
3748c2ecf20Sopenharmony_ciint ibmphp_check_resource(struct resource_node *, u8);
3758c2ecf20Sopenharmony_ciint ibmphp_remove_bus(struct bus_node *, u8);
3768c2ecf20Sopenharmony_civoid ibmphp_free_resources(void);
3778c2ecf20Sopenharmony_ciint ibmphp_add_pfmem_from_mem(struct resource_node *);
3788c2ecf20Sopenharmony_cistruct bus_node *ibmphp_find_res_bus(u8);
3798c2ecf20Sopenharmony_civoid ibmphp_print_test(void);	/* for debugging purposes */
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ciint ibmphp_hpc_readslot(struct slot *, u8, u8 *);
3828c2ecf20Sopenharmony_ciint ibmphp_hpc_writeslot(struct slot *, u8);
3838c2ecf20Sopenharmony_civoid ibmphp_lock_operations(void);
3848c2ecf20Sopenharmony_civoid ibmphp_unlock_operations(void);
3858c2ecf20Sopenharmony_ciint ibmphp_hpc_start_poll_thread(void);
3868c2ecf20Sopenharmony_civoid ibmphp_hpc_stop_poll_thread(void);
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
3928c2ecf20Sopenharmony_ci// HPC return codes
3938c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
3948c2ecf20Sopenharmony_ci#define HPC_ERROR			0xFF
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci//-----------------------------------------------------------------------------
3978c2ecf20Sopenharmony_ci// BUS INFO
3988c2ecf20Sopenharmony_ci//-----------------------------------------------------------------------------
3998c2ecf20Sopenharmony_ci#define BUS_SPEED			0x30
4008c2ecf20Sopenharmony_ci#define BUS_MODE			0x40
4018c2ecf20Sopenharmony_ci#define BUS_MODE_PCIX			0x01
4028c2ecf20Sopenharmony_ci#define BUS_MODE_PCI			0x00
4038c2ecf20Sopenharmony_ci#define BUS_SPEED_2			0x20
4048c2ecf20Sopenharmony_ci#define BUS_SPEED_1			0x10
4058c2ecf20Sopenharmony_ci#define BUS_SPEED_33			0x00
4068c2ecf20Sopenharmony_ci#define BUS_SPEED_66			0x01
4078c2ecf20Sopenharmony_ci#define BUS_SPEED_100			0x02
4088c2ecf20Sopenharmony_ci#define BUS_SPEED_133			0x03
4098c2ecf20Sopenharmony_ci#define BUS_SPEED_66PCIX		0x04
4108c2ecf20Sopenharmony_ci#define BUS_SPEED_66UNKNOWN		0x05
4118c2ecf20Sopenharmony_ci#define BUS_STATUS_AVAILABLE		0x01
4128c2ecf20Sopenharmony_ci#define BUS_CONTROL_AVAILABLE		0x02
4138c2ecf20Sopenharmony_ci#define SLOT_LATCH_REGS_SUPPORTED	0x10
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci#define PRGM_MODEL_REV_LEVEL		0xF0
4168c2ecf20Sopenharmony_ci#define MAX_ADAPTER_NONE		0x09
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4198c2ecf20Sopenharmony_ci// HPC 'write' operations/commands
4208c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4218c2ecf20Sopenharmony_ci//	Command			Code	State	Write to reg
4228c2ecf20Sopenharmony_ci//					Machine	at index
4238c2ecf20Sopenharmony_ci//-------------------------	----	-------	------------
4248c2ecf20Sopenharmony_ci#define HPC_CTLR_ENABLEIRQ	0x00	// N	15
4258c2ecf20Sopenharmony_ci#define HPC_CTLR_DISABLEIRQ	0x01	// N	15
4268c2ecf20Sopenharmony_ci#define HPC_SLOT_OFF		0x02	// Y	0-14
4278c2ecf20Sopenharmony_ci#define HPC_SLOT_ON		0x03	// Y	0-14
4288c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTNOFF	0x04	// N	0-14
4298c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTNON		0x05	// N	0-14
4308c2ecf20Sopenharmony_ci#define HPC_CTLR_CLEARIRQ	0x06	// N	15
4318c2ecf20Sopenharmony_ci#define HPC_CTLR_RESET		0x07	// Y	15
4328c2ecf20Sopenharmony_ci#define HPC_CTLR_IRQSTEER	0x08	// N	15
4338c2ecf20Sopenharmony_ci#define HPC_BUS_33CONVMODE	0x09	// Y	31-34
4348c2ecf20Sopenharmony_ci#define HPC_BUS_66CONVMODE	0x0A	// Y	31-34
4358c2ecf20Sopenharmony_ci#define HPC_BUS_66PCIXMODE	0x0B	// Y	31-34
4368c2ecf20Sopenharmony_ci#define HPC_BUS_100PCIXMODE	0x0C	// Y	31-34
4378c2ecf20Sopenharmony_ci#define HPC_BUS_133PCIXMODE	0x0D	// Y	31-34
4388c2ecf20Sopenharmony_ci#define HPC_ALLSLOT_OFF		0x11	// Y	15
4398c2ecf20Sopenharmony_ci#define HPC_ALLSLOT_ON		0x12	// Y	15
4408c2ecf20Sopenharmony_ci#define HPC_SLOT_BLINKLED	0x13	// N	0-14
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4438c2ecf20Sopenharmony_ci// read commands
4448c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4458c2ecf20Sopenharmony_ci#define READ_SLOTSTATUS		0x01
4468c2ecf20Sopenharmony_ci#define READ_EXTSLOTSTATUS	0x02
4478c2ecf20Sopenharmony_ci#define READ_BUSSTATUS		0x03
4488c2ecf20Sopenharmony_ci#define READ_CTLRSTATUS		0x04
4498c2ecf20Sopenharmony_ci#define READ_ALLSTAT		0x05
4508c2ecf20Sopenharmony_ci#define READ_ALLSLOT		0x06
4518c2ecf20Sopenharmony_ci#define READ_SLOTLATCHLOWREG	0x07
4528c2ecf20Sopenharmony_ci#define READ_REVLEVEL		0x08
4538c2ecf20Sopenharmony_ci#define READ_HPCOPTIONS		0x09
4548c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4558c2ecf20Sopenharmony_ci// slot status
4568c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4578c2ecf20Sopenharmony_ci#define HPC_SLOT_POWER		0x01
4588c2ecf20Sopenharmony_ci#define HPC_SLOT_CONNECT	0x02
4598c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTN		0x04
4608c2ecf20Sopenharmony_ci#define HPC_SLOT_PRSNT2		0x08
4618c2ecf20Sopenharmony_ci#define HPC_SLOT_PRSNT1		0x10
4628c2ecf20Sopenharmony_ci#define HPC_SLOT_PWRGD		0x20
4638c2ecf20Sopenharmony_ci#define HPC_SLOT_BUS_SPEED	0x40
4648c2ecf20Sopenharmony_ci#define HPC_SLOT_LATCH		0x80
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4678c2ecf20Sopenharmony_ci// HPC_SLOT_POWER status return codes
4688c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4698c2ecf20Sopenharmony_ci#define HPC_SLOT_POWER_OFF	0x00
4708c2ecf20Sopenharmony_ci#define HPC_SLOT_POWER_ON	0x01
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4738c2ecf20Sopenharmony_ci// HPC_SLOT_CONNECT status return codes
4748c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4758c2ecf20Sopenharmony_ci#define HPC_SLOT_CONNECTED	0x00
4768c2ecf20Sopenharmony_ci#define HPC_SLOT_DISCONNECTED	0x01
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4798c2ecf20Sopenharmony_ci// HPC_SLOT_ATTN status return codes
4808c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4818c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTN_OFF	0x00
4828c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTN_ON	0x01
4838c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTN_BLINK	0x02
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4868c2ecf20Sopenharmony_ci// HPC_SLOT_PRSNT status return codes
4878c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4888c2ecf20Sopenharmony_ci#define HPC_SLOT_EMPTY		0x00
4898c2ecf20Sopenharmony_ci#define HPC_SLOT_PRSNT_7	0x01
4908c2ecf20Sopenharmony_ci#define HPC_SLOT_PRSNT_15	0x02
4918c2ecf20Sopenharmony_ci#define HPC_SLOT_PRSNT_25	0x03
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4948c2ecf20Sopenharmony_ci// HPC_SLOT_PWRGD status return codes
4958c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
4968c2ecf20Sopenharmony_ci#define HPC_SLOT_PWRGD_FAULT_NONE	0x00
4978c2ecf20Sopenharmony_ci#define HPC_SLOT_PWRGD_GOOD		0x01
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5008c2ecf20Sopenharmony_ci// HPC_SLOT_BUS_SPEED status return codes
5018c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5028c2ecf20Sopenharmony_ci#define HPC_SLOT_BUS_SPEED_OK	0x00
5038c2ecf20Sopenharmony_ci#define HPC_SLOT_BUS_SPEED_MISM	0x01
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5068c2ecf20Sopenharmony_ci// HPC_SLOT_LATCH status return codes
5078c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5088c2ecf20Sopenharmony_ci#define HPC_SLOT_LATCH_OPEN	0x01	// NOTE : in PCI spec bit off = open
5098c2ecf20Sopenharmony_ci#define HPC_SLOT_LATCH_CLOSED	0x00	// NOTE : in PCI spec bit on  = closed
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5138c2ecf20Sopenharmony_ci// extended slot status
5148c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5158c2ecf20Sopenharmony_ci#define HPC_SLOT_PCIX		0x01
5168c2ecf20Sopenharmony_ci#define HPC_SLOT_SPEED1		0x02
5178c2ecf20Sopenharmony_ci#define HPC_SLOT_SPEED2		0x04
5188c2ecf20Sopenharmony_ci#define HPC_SLOT_BLINK_ATTN	0x08
5198c2ecf20Sopenharmony_ci#define HPC_SLOT_RSRVD1		0x10
5208c2ecf20Sopenharmony_ci#define HPC_SLOT_RSRVD2		0x20
5218c2ecf20Sopenharmony_ci#define HPC_SLOT_BUS_MODE	0x40
5228c2ecf20Sopenharmony_ci#define HPC_SLOT_RSRVD3		0x80
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5258c2ecf20Sopenharmony_ci// HPC_XSLOT_PCIX_CAP status return codes
5268c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5278c2ecf20Sopenharmony_ci#define HPC_SLOT_PCIX_NO	0x00
5288c2ecf20Sopenharmony_ci#define HPC_SLOT_PCIX_YES	0x01
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5318c2ecf20Sopenharmony_ci// HPC_XSLOT_SPEED status return codes
5328c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5338c2ecf20Sopenharmony_ci#define HPC_SLOT_SPEED_33	0x00
5348c2ecf20Sopenharmony_ci#define HPC_SLOT_SPEED_66	0x01
5358c2ecf20Sopenharmony_ci#define HPC_SLOT_SPEED_133	0x02
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5388c2ecf20Sopenharmony_ci// HPC_XSLOT_ATTN_BLINK status return codes
5398c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5408c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTN_BLINK_OFF	0x00
5418c2ecf20Sopenharmony_ci#define HPC_SLOT_ATTN_BLINK_ON	0x01
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5448c2ecf20Sopenharmony_ci// HPC_XSLOT_BUS_MODE status return codes
5458c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5468c2ecf20Sopenharmony_ci#define HPC_SLOT_BUS_MODE_OK	0x00
5478c2ecf20Sopenharmony_ci#define HPC_SLOT_BUS_MODE_MISM	0x01
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5508c2ecf20Sopenharmony_ci// Controller status
5518c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5528c2ecf20Sopenharmony_ci#define HPC_CTLR_WORKING	0x01
5538c2ecf20Sopenharmony_ci#define HPC_CTLR_FINISHED	0x02
5548c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT0	0x04
5558c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT1	0x08
5568c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULE2	0x10
5578c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT3	0x20
5588c2ecf20Sopenharmony_ci#define HPC_CTLR_IRQ_ROUTG	0x40
5598c2ecf20Sopenharmony_ci#define HPC_CTLR_IRQ_PENDG	0x80
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5628c2ecf20Sopenharmony_ci// HPC_CTLR_WORKING status return codes
5638c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5648c2ecf20Sopenharmony_ci#define HPC_CTLR_WORKING_NO	0x00
5658c2ecf20Sopenharmony_ci#define HPC_CTLR_WORKING_YES	0x01
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5688c2ecf20Sopenharmony_ci// HPC_CTLR_FINISHED status return codes
5698c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5708c2ecf20Sopenharmony_ci#define HPC_CTLR_FINISHED_NO	0x00
5718c2ecf20Sopenharmony_ci#define HPC_CTLR_FINISHED_YES	0x01
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5748c2ecf20Sopenharmony_ci// HPC_CTLR_RESULT status return codes
5758c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5768c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT_SUCCESS	0x00
5778c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT_FAILED	0x01
5788c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT_RSVD	0x02
5798c2ecf20Sopenharmony_ci#define HPC_CTLR_RESULT_NORESP	0x03
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5838c2ecf20Sopenharmony_ci// macro for slot info
5848c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
5858c2ecf20Sopenharmony_ci#define SLOT_POWER(s)	((u8) ((s & HPC_SLOT_POWER) \
5868c2ecf20Sopenharmony_ci	? HPC_SLOT_POWER_ON : HPC_SLOT_POWER_OFF))
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci#define SLOT_CONNECT(s)	((u8) ((s & HPC_SLOT_CONNECT) \
5898c2ecf20Sopenharmony_ci	? HPC_SLOT_DISCONNECTED : HPC_SLOT_CONNECTED))
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci#define SLOT_ATTN(s, es)	((u8) ((es & HPC_SLOT_BLINK_ATTN) \
5928c2ecf20Sopenharmony_ci	? HPC_SLOT_ATTN_BLINK \
5938c2ecf20Sopenharmony_ci	: ((s & HPC_SLOT_ATTN) ? HPC_SLOT_ATTN_ON : HPC_SLOT_ATTN_OFF)))
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci#define SLOT_PRESENT(s)	((u8) ((s & HPC_SLOT_PRSNT1) \
5968c2ecf20Sopenharmony_ci	? ((s & HPC_SLOT_PRSNT2) ? HPC_SLOT_EMPTY : HPC_SLOT_PRSNT_15) \
5978c2ecf20Sopenharmony_ci	: ((s & HPC_SLOT_PRSNT2) ? HPC_SLOT_PRSNT_25 : HPC_SLOT_PRSNT_7)))
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci#define SLOT_PWRGD(s)	((u8) ((s & HPC_SLOT_PWRGD) \
6008c2ecf20Sopenharmony_ci	? HPC_SLOT_PWRGD_GOOD : HPC_SLOT_PWRGD_FAULT_NONE))
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci#define SLOT_BUS_SPEED(s)	((u8) ((s & HPC_SLOT_BUS_SPEED) \
6038c2ecf20Sopenharmony_ci	? HPC_SLOT_BUS_SPEED_MISM : HPC_SLOT_BUS_SPEED_OK))
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci#define SLOT_LATCH(s)	((u8) ((s & HPC_SLOT_LATCH) \
6068c2ecf20Sopenharmony_ci	? HPC_SLOT_LATCH_CLOSED : HPC_SLOT_LATCH_OPEN))
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci#define SLOT_PCIX(es)	((u8) ((es & HPC_SLOT_PCIX) \
6098c2ecf20Sopenharmony_ci	? HPC_SLOT_PCIX_YES : HPC_SLOT_PCIX_NO))
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci#define SLOT_SPEED(es)	((u8) ((es & HPC_SLOT_SPEED2) \
6128c2ecf20Sopenharmony_ci	? ((es & HPC_SLOT_SPEED1) ? HPC_SLOT_SPEED_133   \
6138c2ecf20Sopenharmony_ci				: HPC_SLOT_SPEED_66)   \
6148c2ecf20Sopenharmony_ci	: HPC_SLOT_SPEED_33))
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_ci#define SLOT_BUS_MODE(es)	((u8) ((es & HPC_SLOT_BUS_MODE) \
6178c2ecf20Sopenharmony_ci	? HPC_SLOT_BUS_MODE_MISM : HPC_SLOT_BUS_MODE_OK))
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci//--------------------------------------------------------------------------
6208c2ecf20Sopenharmony_ci// macro for bus info
6218c2ecf20Sopenharmony_ci//---------------------------------------------------------------------------
6228c2ecf20Sopenharmony_ci#define CURRENT_BUS_SPEED(s)	((u8) (s & BUS_SPEED_2) \
6238c2ecf20Sopenharmony_ci	? ((s & BUS_SPEED_1) ? BUS_SPEED_133 : BUS_SPEED_100) \
6248c2ecf20Sopenharmony_ci	: ((s & BUS_SPEED_1) ? BUS_SPEED_66 : BUS_SPEED_33))
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci#define CURRENT_BUS_MODE(s)	((u8) (s & BUS_MODE) ? BUS_MODE_PCIX : BUS_MODE_PCI)
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci#define READ_BUS_STATUS(s)	((u8) (s->options & BUS_STATUS_AVAILABLE))
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci#define READ_BUS_MODE(s)	((s->revision & PRGM_MODEL_REV_LEVEL) >= 0x20)
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci#define SET_BUS_STATUS(s)	((u8) (s->options & BUS_CONTROL_AVAILABLE))
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci#define READ_SLOT_LATCH(s)	((u8) (s->options & SLOT_LATCH_REGS_SUPPORTED))
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
6378c2ecf20Sopenharmony_ci// macro for controller info
6388c2ecf20Sopenharmony_ci//----------------------------------------------------------------------------
6398c2ecf20Sopenharmony_ci#define CTLR_WORKING(c) ((u8) ((c & HPC_CTLR_WORKING) \
6408c2ecf20Sopenharmony_ci	? HPC_CTLR_WORKING_YES : HPC_CTLR_WORKING_NO))
6418c2ecf20Sopenharmony_ci#define CTLR_FINISHED(c) ((u8) ((c & HPC_CTLR_FINISHED) \
6428c2ecf20Sopenharmony_ci	? HPC_CTLR_FINISHED_YES : HPC_CTLR_FINISHED_NO))
6438c2ecf20Sopenharmony_ci#define CTLR_RESULT(c) ((u8) ((c & HPC_CTLR_RESULT1)  \
6448c2ecf20Sopenharmony_ci	? ((c & HPC_CTLR_RESULT0) ? HPC_CTLR_RESULT_NORESP \
6458c2ecf20Sopenharmony_ci				: HPC_CTLR_RESULT_RSVD)  \
6468c2ecf20Sopenharmony_ci	: ((c & HPC_CTLR_RESULT0) ? HPC_CTLR_RESULT_FAILED \
6478c2ecf20Sopenharmony_ci				: HPC_CTLR_RESULT_SUCCESS)))
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci// command that affect the state machine of HPC
6508c2ecf20Sopenharmony_ci#define NEEDTOCHECK_CMDSTATUS(c) ((c == HPC_SLOT_OFF)        || \
6518c2ecf20Sopenharmony_ci				  (c == HPC_SLOT_ON)         || \
6528c2ecf20Sopenharmony_ci				  (c == HPC_CTLR_RESET)      || \
6538c2ecf20Sopenharmony_ci				  (c == HPC_BUS_33CONVMODE)  || \
6548c2ecf20Sopenharmony_ci				  (c == HPC_BUS_66CONVMODE)  || \
6558c2ecf20Sopenharmony_ci				  (c == HPC_BUS_66PCIXMODE)  || \
6568c2ecf20Sopenharmony_ci				  (c == HPC_BUS_100PCIXMODE) || \
6578c2ecf20Sopenharmony_ci				  (c == HPC_BUS_133PCIXMODE) || \
6588c2ecf20Sopenharmony_ci				  (c == HPC_ALLSLOT_OFF)     || \
6598c2ecf20Sopenharmony_ci				  (c == HPC_ALLSLOT_ON))
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci/* Core part of the driver */
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci#define ENABLE		1
6658c2ecf20Sopenharmony_ci#define DISABLE		0
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci#define CARD_INFO	0x07
6688c2ecf20Sopenharmony_ci#define PCIX133		0x07
6698c2ecf20Sopenharmony_ci#define PCIX66		0x05
6708c2ecf20Sopenharmony_ci#define PCI66		0x04
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ciextern struct pci_bus *ibmphp_pci_bus;
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci/* Variables */
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_cistruct pci_func {
6778c2ecf20Sopenharmony_ci	struct pci_dev *dev;	/* from the OS */
6788c2ecf20Sopenharmony_ci	u8 busno;
6798c2ecf20Sopenharmony_ci	u8 device;
6808c2ecf20Sopenharmony_ci	u8 function;
6818c2ecf20Sopenharmony_ci	struct resource_node *io[6];
6828c2ecf20Sopenharmony_ci	struct resource_node *mem[6];
6838c2ecf20Sopenharmony_ci	struct resource_node *pfmem[6];
6848c2ecf20Sopenharmony_ci	struct pci_func *next;
6858c2ecf20Sopenharmony_ci	int devices[32];	/* for bridge config */
6868c2ecf20Sopenharmony_ci	u8 irq[4];		/* for interrupt config */
6878c2ecf20Sopenharmony_ci	u8 bus;			/* flag for unconfiguring, to say if PPB */
6888c2ecf20Sopenharmony_ci};
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_cistruct slot {
6918c2ecf20Sopenharmony_ci	u8 bus;
6928c2ecf20Sopenharmony_ci	u8 device;
6938c2ecf20Sopenharmony_ci	u8 number;
6948c2ecf20Sopenharmony_ci	u8 real_physical_slot_num;
6958c2ecf20Sopenharmony_ci	u32 capabilities;
6968c2ecf20Sopenharmony_ci	u8 supported_speed;
6978c2ecf20Sopenharmony_ci	u8 supported_bus_mode;
6988c2ecf20Sopenharmony_ci	u8 flag;		/* this is for disable slot and polling */
6998c2ecf20Sopenharmony_ci	u8 ctlr_index;
7008c2ecf20Sopenharmony_ci	struct hotplug_slot hotplug_slot;
7018c2ecf20Sopenharmony_ci	struct controller *ctrl;
7028c2ecf20Sopenharmony_ci	struct pci_func *func;
7038c2ecf20Sopenharmony_ci	u8 irq[4];
7048c2ecf20Sopenharmony_ci	int bit_mode;		/* 0 = 32, 1 = 64 */
7058c2ecf20Sopenharmony_ci	struct bus_info *bus_on;
7068c2ecf20Sopenharmony_ci	struct list_head ibm_slot_list;
7078c2ecf20Sopenharmony_ci	u8 status;
7088c2ecf20Sopenharmony_ci	u8 ext_status;
7098c2ecf20Sopenharmony_ci	u8 busstatus;
7108c2ecf20Sopenharmony_ci};
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_cistruct controller {
7138c2ecf20Sopenharmony_ci	struct ebda_hpc_slot *slots;
7148c2ecf20Sopenharmony_ci	struct ebda_hpc_bus *buses;
7158c2ecf20Sopenharmony_ci	struct pci_dev *ctrl_dev; /* in case where controller is PCI */
7168c2ecf20Sopenharmony_ci	u8 starting_slot_num;	/* starting and ending slot #'s this ctrl controls*/
7178c2ecf20Sopenharmony_ci	u8 ending_slot_num;
7188c2ecf20Sopenharmony_ci	u8 revision;
7198c2ecf20Sopenharmony_ci	u8 options;		/* which options HPC supports */
7208c2ecf20Sopenharmony_ci	u8 status;
7218c2ecf20Sopenharmony_ci	u8 ctlr_id;
7228c2ecf20Sopenharmony_ci	u8 slot_count;
7238c2ecf20Sopenharmony_ci	u8 bus_count;
7248c2ecf20Sopenharmony_ci	u8 ctlr_relative_id;
7258c2ecf20Sopenharmony_ci	u32 irq;
7268c2ecf20Sopenharmony_ci	union {
7278c2ecf20Sopenharmony_ci		struct isa_ctlr_access isa_ctlr;
7288c2ecf20Sopenharmony_ci		struct pci_ctlr_access pci_ctlr;
7298c2ecf20Sopenharmony_ci		struct wpeg_i2c_ctlr_access wpeg_ctlr;
7308c2ecf20Sopenharmony_ci	} u;
7318c2ecf20Sopenharmony_ci	u8 ctlr_type;
7328c2ecf20Sopenharmony_ci	struct list_head ebda_hpc_list;
7338c2ecf20Sopenharmony_ci};
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci/* Functions */
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ciint ibmphp_init_devno(struct slot **);	/* This function is called from EBDA, so we need it not be static */
7388c2ecf20Sopenharmony_ciint ibmphp_do_disable_slot(struct slot *slot_cur);
7398c2ecf20Sopenharmony_ciint ibmphp_update_slot_info(struct slot *);	/* This function is called from HPC, so we need it to not be be static */
7408c2ecf20Sopenharmony_ciint ibmphp_configure_card(struct pci_func *, u8);
7418c2ecf20Sopenharmony_ciint ibmphp_unconfigure_card(struct slot **, int);
7428c2ecf20Sopenharmony_ciextern const struct hotplug_slot_ops ibmphp_hotplug_slot_ops;
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_cistatic inline struct slot *to_slot(struct hotplug_slot *hotplug_slot)
7458c2ecf20Sopenharmony_ci{
7468c2ecf20Sopenharmony_ci	return container_of(hotplug_slot, struct slot, hotplug_slot);
7478c2ecf20Sopenharmony_ci}
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci#endif				//__IBMPHP_H
7508c2ecf20Sopenharmony_ci
751