Linux Audio

Check our new training course

Linux BSP development engineering services

Need help to port Linux and bootloaders to your hardware?
Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0+
 2/*
 3 * Compaq Hot Plug Controller Driver
 4 *
 5 * Copyright (c) 1995,2001 Compaq Computer Corporation
 6 * Copyright (c) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
 7 * Copyright (c) 2001 IBM Corp.
 8 *
 9 * All rights reserved.
10 *
11 * Send feedback to <greg@kroah.com>
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/types.h>
18#include <linux/pci.h>
19#include "shpchp.h"
20
21
22/* A few routines that create sysfs entries for the hot plug controller */
23
24static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
25{
26	struct pci_dev *pdev;
27	char *out = buf;
28	int index, busnr;
29	struct resource *res;
30	struct pci_bus *bus;
 
 
31
32	pdev = to_pci_dev(dev);
33	bus = pdev->subordinate;
34
35	out += sprintf(buf, "Free resources: memory\n");
36	pci_bus_for_each_resource(bus, res, index) {
37		if (res && (res->flags & IORESOURCE_MEM) &&
38				!(res->flags & IORESOURCE_PREFETCH)) {
39			out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
40				       (unsigned long long)res->start,
41				       (unsigned long long)resource_size(res));
 
42		}
43	}
44	out += sprintf(out, "Free resources: prefetchable memory\n");
45	pci_bus_for_each_resource(bus, res, index) {
46		if (res && (res->flags & IORESOURCE_MEM) &&
47			       (res->flags & IORESOURCE_PREFETCH)) {
48			out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
49				       (unsigned long long)res->start,
50				       (unsigned long long)resource_size(res));
 
51		}
52	}
53	out += sprintf(out, "Free resources: IO\n");
54	pci_bus_for_each_resource(bus, res, index) {
55		if (res && (res->flags & IORESOURCE_IO)) {
56			out += sprintf(out, "start = %8.8llx, length = %8.8llx\n",
57				       (unsigned long long)res->start,
58				       (unsigned long long)resource_size(res));
 
59		}
60	}
61	out += sprintf(out, "Free resources: bus numbers\n");
62	for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
63		if (!pci_find_bus(pci_domain_nr(bus), busnr))
64			break;
65	}
66	if (busnr < bus->busn_res.end)
67		out += sprintf(out, "start = %8.8x, length = %8.8x\n",
68				busnr, (int)(bus->busn_res.end - busnr));
 
69
70	return out - buf;
71}
72static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
73
74int shpchp_create_ctrl_files(struct controller *ctrl)
75{
76	return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
77}
78
79void shpchp_remove_ctrl_files(struct controller *ctrl)
80{
81	device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
82}
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0+
 2/*
 3 * Compaq Hot Plug Controller Driver
 4 *
 5 * Copyright (c) 1995,2001 Compaq Computer Corporation
 6 * Copyright (c) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
 7 * Copyright (c) 2001 IBM Corp.
 8 *
 9 * All rights reserved.
10 *
11 * Send feedback to <greg@kroah.com>
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/types.h>
18#include <linux/pci.h>
19#include "shpchp.h"
20
21
22/* A few routines that create sysfs entries for the hot plug controller */
23
24static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
25{
26	struct pci_dev *pdev;
 
 
27	struct resource *res;
28	struct pci_bus *bus;
29	size_t len = 0;
30	int busnr;
31
32	pdev = to_pci_dev(dev);
33	bus = pdev->subordinate;
34
35	len += sysfs_emit_at(buf, len, "Free resources: memory\n");
36	pci_bus_for_each_resource(bus, res) {
37		if (res && (res->flags & IORESOURCE_MEM) &&
38				!(res->flags & IORESOURCE_PREFETCH)) {
39			len += sysfs_emit_at(buf, len,
40					     "start = %8.8llx, length = %8.8llx\n",
41					     (unsigned long long)res->start,
42					     (unsigned long long)resource_size(res));
43		}
44	}
45	len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
46	pci_bus_for_each_resource(bus, res) {
47		if (res && (res->flags & IORESOURCE_MEM) &&
48			       (res->flags & IORESOURCE_PREFETCH)) {
49			len += sysfs_emit_at(buf, len,
50					     "start = %8.8llx, length = %8.8llx\n",
51					     (unsigned long long)res->start,
52					     (unsigned long long)resource_size(res));
53		}
54	}
55	len += sysfs_emit_at(buf, len, "Free resources: IO\n");
56	pci_bus_for_each_resource(bus, res) {
57		if (res && (res->flags & IORESOURCE_IO)) {
58			len += sysfs_emit_at(buf, len,
59					     "start = %8.8llx, length = %8.8llx\n",
60					     (unsigned long long)res->start,
61					     (unsigned long long)resource_size(res));
62		}
63	}
64	len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n");
65	for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
66		if (!pci_find_bus(pci_domain_nr(bus), busnr))
67			break;
68	}
69	if (busnr < bus->busn_res.end)
70		len += sysfs_emit_at(buf, len,
71				     "start = %8.8x, length = %8.8x\n",
72				     busnr, (int)(bus->busn_res.end - busnr));
73
74	return len;
75}
76static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
77
78int shpchp_create_ctrl_files(struct controller *ctrl)
79{
80	return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
81}
82
83void shpchp_remove_ctrl_files(struct controller *ctrl)
84{
85	device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
86}