[PATCH] fix missing includes
[linux-2.6/zen-sources.git] / drivers / pci / pcie / portdrv_pci.c
blob02260141dc8107be19d943f4e35475b65559cf30
1 /*
2 * File: portdrv_pci.c
3 * Purpose: PCI Express Port Bus Driver
5 * Copyright (C) 2004 Intel
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */
9 #include <linux/module.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/pm.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/pcieport_if.h>
18 #include "portdrv.h"
21 * Version Information
23 #define DRIVER_VERSION "v1.0"
24 #define DRIVER_AUTHOR "tom.l.nguyen@intel.com"
25 #define DRIVER_DESC "PCIE Port Bus Driver"
26 MODULE_AUTHOR(DRIVER_AUTHOR);
27 MODULE_DESCRIPTION(DRIVER_DESC);
28 MODULE_LICENSE("GPL");
30 /* global data */
31 static const char device_name[] = "pcieport-driver";
33 static void pci_save_msi_state(struct pci_dev *dev)
35 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
36 int i = 0, pos;
37 u16 control;
39 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)
40 return;
42 pci_read_config_dword(dev, pos, &p_ext->saved_msi_config_space[i++]);
43 control = p_ext->saved_msi_config_space[0] >> 16;
44 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
45 &p_ext->saved_msi_config_space[i++]);
46 if (control & PCI_MSI_FLAGS_64BIT) {
47 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
48 &p_ext->saved_msi_config_space[i++]);
49 pci_read_config_dword(dev, pos + PCI_MSI_DATA_64,
50 &p_ext->saved_msi_config_space[i++]);
51 } else
52 pci_read_config_dword(dev, pos + PCI_MSI_DATA_32,
53 &p_ext->saved_msi_config_space[i++]);
54 if (control & PCI_MSI_FLAGS_MASKBIT)
55 pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT,
56 &p_ext->saved_msi_config_space[i++]);
59 static void pci_restore_msi_state(struct pci_dev *dev)
61 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
62 int i = 0, pos;
63 u16 control;
65 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)
66 return;
68 control = p_ext->saved_msi_config_space[i++] >> 16;
69 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
70 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
71 p_ext->saved_msi_config_space[i++]);
72 if (control & PCI_MSI_FLAGS_64BIT) {
73 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
74 p_ext->saved_msi_config_space[i++]);
75 pci_write_config_dword(dev, pos + PCI_MSI_DATA_64,
76 p_ext->saved_msi_config_space[i++]);
77 } else
78 pci_write_config_dword(dev, pos + PCI_MSI_DATA_32,
79 p_ext->saved_msi_config_space[i++]);
80 if (control & PCI_MSI_FLAGS_MASKBIT)
81 pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT,
82 p_ext->saved_msi_config_space[i++]);
85 static void pcie_portdrv_save_config(struct pci_dev *dev)
87 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
89 pci_save_state(dev);
90 if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
91 pci_save_msi_state(dev);
94 static int pcie_portdrv_restore_config(struct pci_dev *dev)
96 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
97 int retval;
99 pci_restore_state(dev);
100 if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
101 pci_restore_msi_state(dev);
102 retval = pci_enable_device(dev);
103 if (retval)
104 return retval;
105 pci_set_master(dev);
106 return 0;
110 * pcie_portdrv_probe - Probe PCI-Express port devices
111 * @dev: PCI-Express port device being probed
113 * If detected invokes the pcie_port_device_register() method for
114 * this port device.
117 static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
118 const struct pci_device_id *id )
120 int status;
122 status = pcie_port_device_probe(dev);
123 if (status)
124 return status;
126 if (pci_enable_device(dev) < 0)
127 return -ENODEV;
129 pci_set_master(dev);
130 if (!dev->irq) {
131 printk(KERN_WARNING
132 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
133 __FUNCTION__, dev->device, dev->vendor);
135 if (pcie_port_device_register(dev))
136 return -ENOMEM;
138 return 0;
141 static void pcie_portdrv_remove (struct pci_dev *dev)
143 pcie_port_device_remove(dev);
144 kfree(pci_get_drvdata(dev));
147 #ifdef CONFIG_PM
148 static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
150 int ret = pcie_port_device_suspend(dev, state);
152 pcie_portdrv_save_config(dev);
153 return ret;
156 static int pcie_portdrv_resume (struct pci_dev *dev)
158 pcie_portdrv_restore_config(dev);
159 return pcie_port_device_resume(dev);
161 #endif
164 * LINUX Device Driver Model
166 static const struct pci_device_id port_pci_ids[] = { {
167 /* handle any PCI-Express port */
168 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
169 }, { /* end: all zeroes */ }
171 MODULE_DEVICE_TABLE(pci, port_pci_ids);
173 static struct pci_driver pcie_portdrv = {
174 .name = (char *)device_name,
175 .id_table = &port_pci_ids[0],
177 .probe = pcie_portdrv_probe,
178 .remove = pcie_portdrv_remove,
180 #ifdef CONFIG_PM
181 .suspend = pcie_portdrv_suspend,
182 .resume = pcie_portdrv_resume,
183 #endif /* PM */
186 static int __init pcie_portdrv_init(void)
188 int retval = 0;
190 pcie_port_bus_register();
191 retval = pci_register_driver(&pcie_portdrv);
192 if (retval)
193 pcie_port_bus_unregister();
194 return retval;
197 static void __exit pcie_portdrv_exit(void)
199 pci_unregister_driver(&pcie_portdrv);
200 pcie_port_bus_unregister();
203 module_init(pcie_portdrv_init);
204 module_exit(pcie_portdrv_exit);