0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/module.h>
0016 #include <linux/kernel.h>
0017 #include <linux/types.h>
0018 #include <linux/pci.h>
0019 #include "shpchp.h"
0020
0021
0022
0023
0024 static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
0025 {
0026 struct pci_dev *pdev;
0027 int index, busnr;
0028 struct resource *res;
0029 struct pci_bus *bus;
0030 size_t len = 0;
0031
0032 pdev = to_pci_dev(dev);
0033 bus = pdev->subordinate;
0034
0035 len += sysfs_emit_at(buf, len, "Free resources: memory\n");
0036 pci_bus_for_each_resource(bus, res, index) {
0037 if (res && (res->flags & IORESOURCE_MEM) &&
0038 !(res->flags & IORESOURCE_PREFETCH)) {
0039 len += sysfs_emit_at(buf, len,
0040 "start = %8.8llx, length = %8.8llx\n",
0041 (unsigned long long)res->start,
0042 (unsigned long long)resource_size(res));
0043 }
0044 }
0045 len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
0046 pci_bus_for_each_resource(bus, res, index) {
0047 if (res && (res->flags & IORESOURCE_MEM) &&
0048 (res->flags & IORESOURCE_PREFETCH)) {
0049 len += sysfs_emit_at(buf, len,
0050 "start = %8.8llx, length = %8.8llx\n",
0051 (unsigned long long)res->start,
0052 (unsigned long long)resource_size(res));
0053 }
0054 }
0055 len += sysfs_emit_at(buf, len, "Free resources: IO\n");
0056 pci_bus_for_each_resource(bus, res, index) {
0057 if (res && (res->flags & IORESOURCE_IO)) {
0058 len += sysfs_emit_at(buf, len,
0059 "start = %8.8llx, length = %8.8llx\n",
0060 (unsigned long long)res->start,
0061 (unsigned long long)resource_size(res));
0062 }
0063 }
0064 len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n");
0065 for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
0066 if (!pci_find_bus(pci_domain_nr(bus), busnr))
0067 break;
0068 }
0069 if (busnr < bus->busn_res.end)
0070 len += sysfs_emit_at(buf, len,
0071 "start = %8.8x, length = %8.8x\n",
0072 busnr, (int)(bus->busn_res.end - busnr));
0073
0074 return len;
0075 }
0076 static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
0077
0078 int shpchp_create_ctrl_files(struct controller *ctrl)
0079 {
0080 return device_create_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
0081 }
0082
0083 void shpchp_remove_ctrl_files(struct controller *ctrl)
0084 {
0085 device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
0086 }