hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/mcb/mcb-pci.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * MEN Chameleon Bus.
34 *
45 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
56 * Author: Johannes Thumshirn <johannes.thumshirn@men.de>
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the Free
9
- * Software Foundation; version 2 of the License.
107 */
118
129 #include <linux/module.h>
....@@ -34,7 +31,7 @@
3431 {
3532 struct resource *res;
3633 struct priv *priv;
37
- int ret;
34
+ int ret, table_size;
3835 unsigned long flags;
3936
4037 priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
....@@ -93,7 +90,30 @@
9390 if (ret < 0)
9491 goto out_mcb_bus;
9592
96
- dev_dbg(&pdev->dev, "Found %d cells\n", ret);
93
+ table_size = ret;
94
+
95
+ if (table_size < CHAM_HEADER_SIZE) {
96
+ /* Release the previous resources */
97
+ devm_iounmap(&pdev->dev, priv->base);
98
+ devm_release_mem_region(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE);
99
+
100
+ /* Then, allocate it again with the actual chameleon table size */
101
+ res = devm_request_mem_region(&pdev->dev, priv->mapbase,
102
+ table_size,
103
+ KBUILD_MODNAME);
104
+ if (!res) {
105
+ dev_err(&pdev->dev, "Failed to request PCI memory\n");
106
+ ret = -EBUSY;
107
+ goto out_mcb_bus;
108
+ }
109
+
110
+ priv->base = devm_ioremap(&pdev->dev, priv->mapbase, table_size);
111
+ if (!priv->base) {
112
+ dev_err(&pdev->dev, "Cannot ioremap\n");
113
+ ret = -ENOMEM;
114
+ goto out_mcb_bus;
115
+ }
116
+ }
97117
98118 mcb_bus_add_devices(priv->bus);
99119
....@@ -134,3 +154,4 @@
134154 MODULE_AUTHOR("Johannes Thumshirn <johannes.thumshirn@men.de>");
135155 MODULE_LICENSE("GPL");
136156 MODULE_DESCRIPTION("MCB over PCI support");
157
+MODULE_IMPORT_NS(MCB);