Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Simple PCIe FMC carrier SPEC
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
50
Issues
50
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Simple PCIe FMC carrier SPEC
Commits
d6c64e9d
Commit
d6c64e9d
authored
Nov 15, 2017
by
Federico Vaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel: remap useful PCI resources
Signed-off-by:
Federico Vaga
<
federico.vaga@vaga.pv.it
>
parent
28e85f6a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
+33
-3
spec-core.c
kernel/spec-core.c
+33
-3
No files found.
kernel/spec-core.c
View file @
d6c64e9d
...
...
@@ -11,6 +11,7 @@
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/pci.h>
...
...
@@ -36,13 +37,14 @@ static struct class *spec_class;
* @cdev Char device descriptor
* @dev Linux device instance descriptor
* @flags collection of bit flags
* @remap ioremap of PCI bar 0, 2, 4
*/
struct
spec_dev
{
struct
cdev
cdev
;
struct
device
dev
;
DECLARE_BITMAP
(
flags
,
SPEC_FLAG_BITS
);
void
__iomem
*
remap
[
3
];
/* ioremap of bar 0, 2, 4 */
};
...
...
@@ -150,12 +152,17 @@ static void spec_release(struct device *dev)
{
struct
spec_dev
*
spec
=
dev_get_drvdata
(
dev
);
struct
pci_dev
*
pdev
=
to_pci_dev
(
dev
->
parent
);
int
minor
=
MINOR
(
dev
->
devt
);
int
minor
=
MINOR
(
dev
->
devt
)
,
i
;
pci_disable_device
(
pdev
);
pci_set_drvdata
(
pdev
,
NULL
);
cdev_del
(
&
spec
->
cdev
);
for
(
i
=
0
;
i
<
3
;
i
++
)
{
if
(
spec
->
remap
[
i
])
iounmap
(
spec
->
remap
[
i
]);
spec
->
remap
[
i
]
=
NULL
;
}
kfree
(
spec
);
spec_minor_put
(
minor
);
}
...
...
@@ -165,7 +172,7 @@ static int spec_probe(struct pci_dev *pdev,
const
struct
pci_device_id
*
id
)
{
struct
spec_dev
*
spec
;
int
err
,
minor
;
int
err
,
minor
,
i
;
minor
=
spec_minor_get
();
if
(
minor
>=
SPEC_MINOR_MAX
)
...
...
@@ -187,6 +194,23 @@ static int spec_probe(struct pci_dev *pdev,
spec
->
dev
.
release
=
spec_release
;
dev_set_drvdata
(
&
spec
->
dev
,
spec
);
/* 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
)
goto
err_remap
;
cdev_init
(
&
spec
->
cdev
,
&
spec_fops
);
spec
->
cdev
.
owner
=
THIS_MODULE
;
err
=
cdev_add
(
&
spec
->
cdev
,
spec
->
dev
.
devt
,
1
);
...
...
@@ -212,6 +236,12 @@ err_enable:
err_dev_reg:
cdev_del
(
&
spec
->
cdev
);
err_cdev:
for
(
i
=
0
;
i
<
3
;
i
++
)
{
if
(
spec
->
remap
[
i
])
iounmap
(
spec
->
remap
[
i
]);
spec
->
remap
[
i
]
=
NULL
;
}
err_remap:
kfree
(
spec
);
err_alloc:
spec_minor_put
(
minor
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment