Commit 5f7187a0 authored by Federico Vaga's avatar Federico Vaga

sw:drv: map memory only when necessary

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 2d24d3ed
......@@ -617,13 +617,17 @@ static const struct device_type spec_dev_type = {
*/
int spec_fpga_init(struct spec_dev *spec)
{
struct resource *r0 = &spec->pdev->resource[0];
int err;
spec->fpga = spec->remap[0];
spec->fpga = ioremap(r0->start, resource_size(r0));
if (!spec->fpga)
return -ENOMEM;
spec->meta = spec->fpga + SPEC_META_BASE;
if (!spec_fpga_is_valid(spec))
return -EINVAL;
if (!spec_fpga_is_valid(spec)) {
err = -EINVAL;
goto err_valid;
}
memset(&spec->dev, 0, sizeof(spec->dev));
spec->dev.parent = &spec->pdev->dev;
......@@ -693,6 +697,8 @@ err_vic:
device_unregister(&spec->dev);
err_dev:
err_name:
err_valid:
iounmap(spec->fpga);
return err;
}
......@@ -704,6 +710,7 @@ int spec_fpga_exit(struct spec_dev *spec)
spec_fpga_devices_exit(spec);
spec_fpga_vic_exit(spec);
device_unregister(&spec->dev);
iounmap(spec->fpga);
return 0;
}
......@@ -230,7 +230,7 @@ static int spec_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
struct spec_dev *spec;
int err, i;
int err;
spec = kzalloc(sizeof(*spec), GFP_KERNEL);
if (!spec)
......@@ -248,26 +248,6 @@ static int spec_probe(struct pci_dev *pdev,
}
pci_set_master(pdev);
/* Remap our 3 bars */
for (i = err = 0; i < 3; i++) {
struct resource *r = pdev->resource + (2 * i);
if (!r->start)
continue;
if (r->flags & IORESOURCE_MEM) {
spec->remap[i] = ioremap(r->start,
r->end + 1 - r->start);
if (!spec->remap[i])
err = -ENOMEM;
}
}
if (err) {
dev_err(&pdev->dev, "Failed to remap memory (%d)\n",
err);
goto err_remap;
}
err = mfd_add_devices(&pdev->dev, mfd_id++,
spec_mfd_devs,
ARRAY_SIZE(spec_mfd_devs),
......@@ -304,11 +284,6 @@ err_sysfs:
err_sgpio:
mfd_remove_devices(&pdev->dev);
err_mfd:
for (i = 0; i < 3; i++) {
if (spec->remap[i])
iounmap(spec->remap[i]);
}
err_remap:
pci_disable_device(pdev);
err_enable:
kfree(spec);
......@@ -319,7 +294,6 @@ err_enable:
static void spec_remove(struct pci_dev *pdev)
{
struct spec_dev *spec = pci_get_drvdata(pdev);
int i;
spec_dbg_exit(spec);
spec_fpga_exit(spec);
......@@ -327,9 +301,6 @@ static void spec_remove(struct pci_dev *pdev)
spec_gpio_exit(spec);
mfd_remove_devices(&pdev->dev);
for (i = 0; i < 3; i++)
if (spec->remap[i])
iounmap(spec->remap[i]);
pci_disable_device(pdev);
kfree(spec);
}
......
......@@ -104,7 +104,6 @@ struct spec_meta_id {
* @dev Linux device instance descriptor
* @mtx: protect bootselect usage, fpga device load
* @flags collection of bit flags
* @remap ioremap of PCI bar 0, 2, 4
* @slot_info: information about FMC slot
* @i2c_pdev: platform device for I2C master
* @i2c_adapter: the I2C master device to be used
......@@ -114,7 +113,6 @@ struct spec_dev {
struct device dev;
DECLARE_BITMAP(flags, SPEC_FLAG_BITS);
void __iomem *remap[3]; /* ioremap of bar 0, 2, 4 */
void __iomem *fpga;
struct spec_meta_id __iomem *meta;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment