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