1 #include <linux/debugfs.h>
3 #include <linux/export.h>
5 #include <linux/pci_hotplug.h>
7 #define debugfs_create_atomic_t LINUX_BACKPORT(debugfs_create_atomic_t)
9 static int debugfs_atomic_t_set(void *data, u64 val)
11 atomic_set((atomic_t *)data, val);
14 static int debugfs_atomic_t_get(void *data, u64 *val)
16 *val = atomic_read((atomic_t *)data);
19 DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
20 debugfs_atomic_t_set, "%lld\n");
21 DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, "%lld\n");
22 DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, "%lld\n");
25 * debugfs_create_atomic_t - create a debugfs file that is used to read and
26 * write an atomic_t value
27 * @name: a pointer to a string containing the name of the file to create.
28 * @mode: the permission that the file should have
29 * @parent: a pointer to the parent dentry for this file. This should be a
30 * directory dentry if set. If this parameter is %NULL, then the
31 * file will be created in the root of the debugfs filesystem.
32 * @value: a pointer to the variable that the file should read to and write
35 struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
36 struct dentry *parent, atomic_t *value)
38 /* if there are no write bits set, make read only */
39 if (!(mode & S_IWUGO))
40 return debugfs_create_file(name, mode, parent, value,
42 /* if there are no read bits set, make write only */
43 if (!(mode & S_IRUGO))
44 return debugfs_create_file(name, mode, parent, value,
47 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t);
49 EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
51 const unsigned char pcie_link_speed[] = {
52 PCI_SPEED_UNKNOWN, /* 0 */
53 PCIE_SPEED_2_5GT, /* 1 */
54 PCIE_SPEED_5_0GT, /* 2 */
55 PCIE_SPEED_8_0GT, /* 3 */
56 PCI_SPEED_UNKNOWN, /* 4 */
57 PCI_SPEED_UNKNOWN, /* 5 */
58 PCI_SPEED_UNKNOWN, /* 6 */
59 PCI_SPEED_UNKNOWN, /* 7 */
60 PCI_SPEED_UNKNOWN, /* 8 */
61 PCI_SPEED_UNKNOWN, /* 9 */
62 PCI_SPEED_UNKNOWN, /* A */
63 PCI_SPEED_UNKNOWN, /* B */
64 PCI_SPEED_UNKNOWN, /* C */
65 PCI_SPEED_UNKNOWN, /* D */
66 PCI_SPEED_UNKNOWN, /* E */
67 PCI_SPEED_UNKNOWN /* F */
71 * pcie_get_minimum_link - determine minimum link settings of a PCI device
72 * @dev: PCI device to query
73 * @speed: storage for minimum speed
74 * @width: storage for minimum width
76 * This function will walk up the PCI device chain and determine the minimum
77 * link width and speed of the device.
79 #define pcie_get_minimum_link LINUX_BACKPORT(pcie_get_minimum_link)
80 int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,
81 enum pcie_link_width *width)
85 *speed = PCI_SPEED_UNKNOWN;
86 *width = PCIE_LNK_WIDTH_UNKNOWN;
90 enum pci_bus_speed next_speed;
91 enum pcie_link_width next_width;
93 ret = pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
97 next_speed = pcie_link_speed[lnksta & PCI_EXP_LNKSTA_CLS];
98 next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >>
99 PCI_EXP_LNKSTA_NLW_SHIFT;
101 if (next_speed < *speed)
104 if (next_width < *width)
107 dev = dev->bus->self;
112 EXPORT_SYMBOL(pcie_get_minimum_link);