Commit e8e9b34c authored by Gavin Shan's avatar Gavin Shan Committed by Benjamin Herrenschmidt

powerpc/eeh: Create eeh_dev from pci_dn instead of device_node

The patch adds function traverse_pci_dn(), which is similar to
traverse_pci_devices() except it takes pci_dn, not device_node
as parameter. The pci_dev.c has been reworked to create eeh_dev
from pci_dn, instead of device_node.
Signed-off-by: default avatarGavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent c035ff1d
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
struct pci_dev; struct pci_dev;
struct pci_bus; struct pci_bus;
struct device_node; struct device_node;
struct pci_dn;
#ifdef CONFIG_EEH #ifdef CONFIG_EEH
...@@ -137,6 +138,7 @@ struct eeh_dev { ...@@ -137,6 +138,7 @@ struct eeh_dev {
struct list_head list; /* Form link list in the PE */ struct list_head list; /* Form link list in the PE */
struct pci_controller *phb; /* Associated PHB */ struct pci_controller *phb; /* Associated PHB */
struct device_node *dn; /* Associated device node */ struct device_node *dn; /* Associated device node */
struct pci_dn *pdn; /* Associated PCI device node */
struct pci_dev *pdev; /* Associated PCI device */ struct pci_dev *pdev; /* Associated PCI device */
struct pci_bus *bus; /* PCI bus for partial hotplug */ struct pci_bus *bus; /* PCI bus for partial hotplug */
}; };
...@@ -146,6 +148,11 @@ static inline struct device_node *eeh_dev_to_of_node(struct eeh_dev *edev) ...@@ -146,6 +148,11 @@ static inline struct device_node *eeh_dev_to_of_node(struct eeh_dev *edev)
return edev ? edev->dn : NULL; return edev ? edev->dn : NULL;
} }
static inline struct pci_dn *eeh_dev_to_pdn(struct eeh_dev *edev)
{
return edev ? edev->pdn : NULL;
}
static inline struct pci_dev *eeh_dev_to_pci_dev(struct eeh_dev *edev) static inline struct pci_dev *eeh_dev_to_pci_dev(struct eeh_dev *edev)
{ {
return edev ? edev->pdev : NULL; return edev ? edev->pdev : NULL;
...@@ -272,7 +279,7 @@ void eeh_pe_restore_bars(struct eeh_pe *pe); ...@@ -272,7 +279,7 @@ void eeh_pe_restore_bars(struct eeh_pe *pe);
const char *eeh_pe_loc_get(struct eeh_pe *pe); const char *eeh_pe_loc_get(struct eeh_pe *pe);
struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe); struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
void *eeh_dev_init(struct device_node *dn, void *data); void *eeh_dev_init(struct pci_dn *pdn, void *data);
void eeh_dev_phb_init_dynamic(struct pci_controller *phb); void eeh_dev_phb_init_dynamic(struct pci_controller *phb);
int eeh_init(void); int eeh_init(void);
int __init eeh_ops_register(struct eeh_ops *ops); int __init eeh_ops_register(struct eeh_ops *ops);
...@@ -323,7 +330,7 @@ static inline int eeh_init(void) ...@@ -323,7 +330,7 @@ static inline int eeh_init(void)
return 0; return 0;
} }
static inline void *eeh_dev_init(struct device_node *dn, void *data) static inline void *eeh_dev_init(struct pci_dn *pdn, void *data)
{ {
return NULL; return NULL;
} }
......
...@@ -213,8 +213,14 @@ static inline struct eeh_dev *of_node_to_eeh_dev(struct device_node *dn) ...@@ -213,8 +213,14 @@ static inline struct eeh_dev *of_node_to_eeh_dev(struct device_node *dn)
return PCI_DN(dn)->edev; return PCI_DN(dn)->edev;
} }
static inline struct eeh_dev *pdn_to_eeh_dev(struct pci_dn *pdn)
{
return pdn ? pdn->edev : NULL;
}
#else #else
#define of_node_to_eeh_dev(x) (NULL) #define of_node_to_eeh_dev(x) (NULL)
#define pdn_to_eeh_dev(x) (NULL)
#endif #endif
/** Find the bus corresponding to the indicated device node */ /** Find the bus corresponding to the indicated device node */
......
...@@ -33,9 +33,14 @@ extern struct pci_dev *isa_bridge_pcidev; /* may be NULL if no ISA bus */ ...@@ -33,9 +33,14 @@ extern struct pci_dev *isa_bridge_pcidev; /* may be NULL if no ISA bus */
/* PCI device_node operations */ /* PCI device_node operations */
struct device_node; struct device_node;
struct pci_dn;
typedef void *(*traverse_func)(struct device_node *me, void *data); typedef void *(*traverse_func)(struct device_node *me, void *data);
void *traverse_pci_devices(struct device_node *start, traverse_func pre, void *traverse_pci_devices(struct device_node *start, traverse_func pre,
void *data); void *data);
void *traverse_pci_dn(struct pci_dn *root,
void *(*fn)(struct pci_dn *, void *),
void *data);
extern void pci_devs_phb_init(void); extern void pci_devs_phb_init(void);
extern void pci_devs_phb_init_dynamic(struct pci_controller *phb); extern void pci_devs_phb_init_dynamic(struct pci_controller *phb);
......
...@@ -43,13 +43,13 @@ ...@@ -43,13 +43,13 @@
/** /**
* eeh_dev_init - Create EEH device according to OF node * eeh_dev_init - Create EEH device according to OF node
* @dn: device node * @pdn: PCI device node
* @data: PHB * @data: PHB
* *
* It will create EEH device according to the given OF node. The function * It will create EEH device according to the given OF node. The function
* might be called by PCI emunation, DR, PHB hotplug. * might be called by PCI emunation, DR, PHB hotplug.
*/ */
void *eeh_dev_init(struct device_node *dn, void *data) void *eeh_dev_init(struct pci_dn *pdn, void *data)
{ {
struct pci_controller *phb = data; struct pci_controller *phb = data;
struct eeh_dev *edev; struct eeh_dev *edev;
...@@ -63,8 +63,8 @@ void *eeh_dev_init(struct device_node *dn, void *data) ...@@ -63,8 +63,8 @@ void *eeh_dev_init(struct device_node *dn, void *data)
} }
/* Associate EEH device with OF node */ /* Associate EEH device with OF node */
PCI_DN(dn)->edev = edev; pdn->edev = edev;
edev->dn = dn; edev->pdn = pdn;
edev->phb = phb; edev->phb = phb;
INIT_LIST_HEAD(&edev->list); INIT_LIST_HEAD(&edev->list);
...@@ -80,16 +80,16 @@ void *eeh_dev_init(struct device_node *dn, void *data) ...@@ -80,16 +80,16 @@ void *eeh_dev_init(struct device_node *dn, void *data)
*/ */
void eeh_dev_phb_init_dynamic(struct pci_controller *phb) void eeh_dev_phb_init_dynamic(struct pci_controller *phb)
{ {
struct device_node *dn = phb->dn; struct pci_dn *root = phb->pci_data;
/* EEH PE for PHB */ /* EEH PE for PHB */
eeh_phb_pe_create(phb); eeh_phb_pe_create(phb);
/* EEH device for PHB */ /* EEH device for PHB */
eeh_dev_init(dn, phb); eeh_dev_init(root, phb);
/* EEH devices for children OF nodes */ /* EEH devices for children OF nodes */
traverse_pci_devices(dn, eeh_dev_init, phb); traverse_pci_dn(root, eeh_dev_init, phb);
} }
/** /**
......
...@@ -246,6 +246,46 @@ void *traverse_pci_devices(struct device_node *start, traverse_func pre, ...@@ -246,6 +246,46 @@ void *traverse_pci_devices(struct device_node *start, traverse_func pre,
return NULL; return NULL;
} }
static struct pci_dn *pci_dn_next_one(struct pci_dn *root,
struct pci_dn *pdn)
{
struct list_head *next = pdn->child_list.next;
if (next != &pdn->child_list)
return list_entry(next, struct pci_dn, list);
while (1) {
if (pdn == root)
return NULL;
next = pdn->list.next;
if (next != &pdn->parent->child_list)
break;
pdn = pdn->parent;
}
return list_entry(next, struct pci_dn, list);
}
void *traverse_pci_dn(struct pci_dn *root,
void *(*fn)(struct pci_dn *, void *),
void *data)
{
struct pci_dn *pdn = root;
void *ret;
/* Only scan the child nodes */
for (pdn = pci_dn_next_one(root, pdn); pdn;
pdn = pci_dn_next_one(root, pdn)) {
ret = fn(pdn, data);
if (ret)
return ret;
}
return NULL;
}
/** /**
* pci_devs_phb_init_dynamic - setup pci devices under this PHB * pci_devs_phb_init_dynamic - setup pci devices under this PHB
* phb: pci-to-host bridge (top-level bridge connecting to cpu) * phb: pci-to-host bridge (top-level bridge connecting to cpu)
......
...@@ -265,7 +265,7 @@ static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long act ...@@ -265,7 +265,7 @@ static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long act
update_dn_pci_info(np, pci->phb); update_dn_pci_info(np, pci->phb);
/* Create EEH device for the OF node */ /* Create EEH device for the OF node */
eeh_dev_init(np, pci->phb); eeh_dev_init(PCI_DN(np), pci->phb);
} }
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment