Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spec-sw
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
fmc-projects
spec
spec-sw
Commits
1d8bb157
There was an error fetching the commit references. Please try again later.
Commit
1d8bb157
authored
11 years ago
by
garcialasheras
Committed by
Federico Vaga
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
tools: Tools detached from kernel: no modules required
parent
cfb9e36f
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/speclib.c
+58
-5
58 additions, 5 deletions
tools/speclib.c
tools/speclib.h
+6
-0
6 additions, 0 deletions
tools/speclib.h
with
64 additions
and
5 deletions
tools/speclib.c
+
58
−
5
View file @
1d8bb157
...
@@ -27,6 +27,54 @@ struct spec_private {
...
@@ -27,6 +27,54 @@ struct spec_private {
uint32_t
vuart_base
;
uint32_t
vuart_base
;
};
};
/*
* Check if the PCI device at bus/def_fn is a SPEC board.
* Return 1 if the device is a SPEC and 0 if it is not.
* If there is an error accessing the files, return -1
*/
static
int
spec_check_id
(
int
bus
,
int
dev
)
{
unsigned
int
vendor
,
device
;
char
buf
[
128
];
FILE
*
f
;
// check device
snprintf
(
buf
,
sizeof
buf
,
"/sys/bus/pci/devices/0000:%02x:%02x.0/device"
,
bus
,
dev
);
f
=
fopen
(
buf
,
"r"
);
if
(
f
==
NULL
){
fprintf
(
stderr
,
"error accessing to file
\n
"
);
return
-
1
;
}
fscanf
(
f
,
"%x"
,
&
device
);
fclose
(
f
);
// check vendor
snprintf
(
buf
,
sizeof
buf
,
"/sys/bus/pci/devices/0000:%02x:%02x.0/vendor"
,
bus
,
dev
);
f
=
fopen
(
buf
,
"r"
);
if
(
f
==
NULL
){
fprintf
(
stderr
,
"error accessing to file
\n
"
);
return
-
1
;
}
fscanf
(
f
,
"%x"
,
&
vendor
);
fclose
(
f
);
if
(
device
==
PCI_DEVICE_ID_SPEC
&&
vendor
==
PCI_VENDOR_ID_CERN
)
return
1
;
if
(
device
==
PCI_DEVICE_ID_GN4124
&&
vendor
==
PCI_VENDOR_ID_GENNUM
)
return
1
;
return
0
;
}
/*
/*
* Checks if there's a SPEC card at bus/def_fn.
* Checks if there's a SPEC card at bus/def_fn.
* If one (or both) parameters are < 0, takes first available card
* If one (or both) parameters are < 0, takes first available card
...
@@ -38,7 +86,7 @@ static int spec_scan(int *bus, int *devfn)
...
@@ -38,7 +86,7 @@ static int spec_scan(int *bus, int *devfn)
int
n
,
found
=
0
;
int
n
,
found
=
0
;
int
my_bus
,
my_devfn
;
int
my_bus
,
my_devfn
;
n
=
scandir
(
"/sys/bus/pci/d
rivers/spec
"
,
&
namelist
,
0
,
0
);
n
=
scandir
(
"/sys/bus/pci/d
evices/
"
,
&
namelist
,
0
,
0
);
if
(
n
<
0
)
if
(
n
<
0
)
{
{
perror
(
"scandir"
);
perror
(
"scandir"
);
...
@@ -50,10 +98,15 @@ static int spec_scan(int *bus, int *devfn)
...
@@ -50,10 +98,15 @@ static int spec_scan(int *bus, int *devfn)
"0000:%02x:%02x.0"
,
"0000:%02x:%02x.0"
,
&
my_bus
,
&
my_devfn
)
==
2
)
&
my_bus
,
&
my_devfn
)
==
2
)
{
{
if
(
*
bus
<
0
)
*
bus
=
my_bus
;
if
(
*
bus
>=
0
)
my_bus
=
*
bus
;
if
(
*
devfn
<
0
)
*
devfn
=
my_devfn
;
if
(
*
devfn
>=
0
)
my_devfn
=
*
devfn
;
if
(
*
bus
==
my_bus
&&
*
devfn
==
my_devfn
)
if
(
spec_check_id
(
my_bus
,
my_devfn
))
{
*
bus
=
my_bus
;
*
devfn
=
my_devfn
;
found
=
1
;
found
=
1
;
}
}
}
free
(
namelist
[
n
]);
free
(
namelist
[
n
]);
}
}
...
@@ -79,7 +132,7 @@ static void *spec_map_area(int bus, int dev, int bar, size_t size)
...
@@ -79,7 +132,7 @@ static void *spec_map_area(int bus, int dev, int bar, size_t size)
int
fd
;
int
fd
;
void
*
ptr
;
void
*
ptr
;
snprintf
(
path
,
sizeof
(
path
),
"/sys/bus/pci/d
rivers/spec
"
snprintf
(
path
,
sizeof
(
path
),
"/sys/bus/pci/d
evices/
"
"/0000:%02x:%02x.0/resource%d"
,
bus
,
dev
,
bar
);
"/0000:%02x:%02x.0/resource%d"
,
bus
,
dev
,
bar
);
fd
=
open
(
path
,
O_RDWR
|
O_SYNC
);
fd
=
open
(
path
,
O_RDWR
|
O_SYNC
);
...
...
This diff is collapsed.
Click to expand it.
tools/speclib.h
+
6
−
0
View file @
1d8bb157
...
@@ -3,6 +3,12 @@
...
@@ -3,6 +3,12 @@
#include
<stdint.h>
#include
<stdint.h>
/* Vendor/Device ID to identify the SPEC */
#define PCI_VENDOR_ID_CERN 0x10dc
#define PCI_DEVICE_ID_SPEC 0x018d
#define PCI_VENDOR_ID_GENNUM 0x1a39
#define PCI_DEVICE_ID_GN4124 0x0004
/* 'Opens' the SPEC card at PCI bus [bus], device/function [dev].
/* 'Opens' the SPEC card at PCI bus [bus], device/function [dev].
Returns a handle to the card or NULL in case of failure. */
Returns a handle to the card or NULL in case of failure. */
void
*
spec_open
(
int
bus
,
int
dev
);
void
*
spec_open
(
int
bus
,
int
dev
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment