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