.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Regular cardbus driver ("yenta_socket") |
---|
3 | 4 | * |
---|
.. | .. |
---|
172 | 173 | |
---|
173 | 174 | static ssize_t show_yenta_registers(struct device *yentadev, struct device_attribute *attr, char *buf) |
---|
174 | 175 | { |
---|
175 | | - struct pci_dev *dev = to_pci_dev(yentadev); |
---|
176 | | - struct yenta_socket *socket = pci_get_drvdata(dev); |
---|
| 176 | + struct yenta_socket *socket = dev_get_drvdata(yentadev); |
---|
177 | 177 | int offset = 0, i; |
---|
178 | 178 | |
---|
179 | 179 | offset = snprintf(buf, PAGE_SIZE, "CB registers:"); |
---|
180 | 180 | for (i = 0; i < 0x24; i += 4) { |
---|
181 | 181 | unsigned val; |
---|
182 | 182 | if (!(i & 15)) |
---|
183 | | - offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); |
---|
| 183 | + offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); |
---|
184 | 184 | val = cb_readl(socket, i); |
---|
185 | | - offset += snprintf(buf + offset, PAGE_SIZE - offset, " %08x", val); |
---|
| 185 | + offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %08x", val); |
---|
186 | 186 | } |
---|
187 | 187 | |
---|
188 | | - offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:"); |
---|
| 188 | + offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:"); |
---|
189 | 189 | for (i = 0; i < 0x45; i++) { |
---|
190 | 190 | unsigned char val; |
---|
191 | 191 | if (!(i & 7)) { |
---|
.. | .. |
---|
193 | 193 | memcpy(buf + offset, " -", 2); |
---|
194 | 194 | offset += 2; |
---|
195 | 195 | } else |
---|
196 | | - offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); |
---|
| 196 | + offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); |
---|
197 | 197 | } |
---|
198 | 198 | val = exca_readb(socket, i); |
---|
199 | | - offset += snprintf(buf + offset, PAGE_SIZE - offset, " %02x", val); |
---|
| 199 | + offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %02x", val); |
---|
200 | 200 | } |
---|
201 | 201 | buf[offset++] = '\n'; |
---|
202 | 202 | return offset; |
---|
.. | .. |
---|
694 | 694 | struct pci_bus_region region; |
---|
695 | 695 | unsigned mask; |
---|
696 | 696 | |
---|
697 | | - res = dev->resource + PCI_BRIDGE_RESOURCES + nr; |
---|
| 697 | + res = &dev->resource[nr]; |
---|
698 | 698 | /* Already allocated? */ |
---|
699 | 699 | if (res->parent) |
---|
700 | 700 | return 0; |
---|
.. | .. |
---|
711 | 711 | region.end = config_readl(socket, addr_end) | ~mask; |
---|
712 | 712 | if (region.start && region.end > region.start && !override_bios) { |
---|
713 | 713 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
---|
714 | | - if (pci_claim_resource(dev, PCI_BRIDGE_RESOURCES + nr) == 0) |
---|
| 714 | + if (pci_claim_resource(dev, nr) == 0) |
---|
715 | 715 | return 0; |
---|
716 | 716 | dev_info(&dev->dev, |
---|
717 | 717 | "Preassigned resource %d busy or not available, reconfiguring...\n", |
---|
.. | .. |
---|
745 | 745 | return 0; |
---|
746 | 746 | } |
---|
747 | 747 | |
---|
| 748 | +static void yenta_free_res(struct yenta_socket *socket, int nr) |
---|
| 749 | +{ |
---|
| 750 | + struct pci_dev *dev = socket->dev; |
---|
| 751 | + struct resource *res; |
---|
| 752 | + |
---|
| 753 | + res = &dev->resource[nr]; |
---|
| 754 | + if (res->start != 0 && res->end != 0) |
---|
| 755 | + release_resource(res); |
---|
| 756 | + |
---|
| 757 | + res->start = res->end = res->flags = 0; |
---|
| 758 | +} |
---|
| 759 | + |
---|
748 | 760 | /* |
---|
749 | 761 | * Allocate the bridge mappings for the device.. |
---|
750 | 762 | */ |
---|
751 | 763 | static void yenta_allocate_resources(struct yenta_socket *socket) |
---|
752 | 764 | { |
---|
753 | 765 | int program = 0; |
---|
754 | | - program += yenta_allocate_res(socket, 0, IORESOURCE_IO, |
---|
| 766 | + program += yenta_allocate_res(socket, PCI_CB_BRIDGE_IO_0_WINDOW, |
---|
| 767 | + IORESOURCE_IO, |
---|
755 | 768 | PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0); |
---|
756 | | - program += yenta_allocate_res(socket, 1, IORESOURCE_IO, |
---|
| 769 | + program += yenta_allocate_res(socket, PCI_CB_BRIDGE_IO_1_WINDOW, |
---|
| 770 | + IORESOURCE_IO, |
---|
757 | 771 | PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1); |
---|
758 | | - program += yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH, |
---|
| 772 | + program += yenta_allocate_res(socket, PCI_CB_BRIDGE_MEM_0_WINDOW, |
---|
| 773 | + IORESOURCE_MEM | IORESOURCE_PREFETCH, |
---|
759 | 774 | PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0); |
---|
760 | | - program += yenta_allocate_res(socket, 3, IORESOURCE_MEM, |
---|
| 775 | + program += yenta_allocate_res(socket, PCI_CB_BRIDGE_MEM_1_WINDOW, |
---|
| 776 | + IORESOURCE_MEM, |
---|
761 | 777 | PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1); |
---|
762 | 778 | if (program) |
---|
763 | 779 | pci_setup_cardbus(socket->dev->subordinate); |
---|
.. | .. |
---|
769 | 785 | */ |
---|
770 | 786 | static void yenta_free_resources(struct yenta_socket *socket) |
---|
771 | 787 | { |
---|
772 | | - int i; |
---|
773 | | - for (i = 0; i < 4; i++) { |
---|
774 | | - struct resource *res; |
---|
775 | | - res = socket->dev->resource + PCI_BRIDGE_RESOURCES + i; |
---|
776 | | - if (res->start != 0 && res->end != 0) |
---|
777 | | - release_resource(res); |
---|
778 | | - res->start = res->end = res->flags = 0; |
---|
779 | | - } |
---|
| 788 | + yenta_free_res(socket, PCI_CB_BRIDGE_IO_0_WINDOW); |
---|
| 789 | + yenta_free_res(socket, PCI_CB_BRIDGE_IO_1_WINDOW); |
---|
| 790 | + yenta_free_res(socket, PCI_CB_BRIDGE_MEM_0_WINDOW); |
---|
| 791 | + yenta_free_res(socket, PCI_CB_BRIDGE_MEM_1_WINDOW); |
---|
780 | 792 | } |
---|
781 | 793 | |
---|
782 | 794 | |
---|