Skip to content

Commit 3a8d3d5

Browse files
Merge pull request xapi-project#1789 from johnelse/cp-8358
CP-8358: PCI subsystem device/vendor ID handling
2 parents 08758c3 + 903c986 commit 3a8d3d5

File tree

9 files changed

+322
-106
lines changed

9 files changed

+322
-106
lines changed

ocaml/idl/datamodel.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open Datamodel_types
1818
(* IMPORTANT: Please bump schema vsn if you change/add/remove a _field_.
1919
You do not have to bump vsn if you change/add/remove a message *)
2020
let schema_major_vsn = 5
21-
let schema_minor_vsn = 81
21+
let schema_minor_vsn = 82
2222

2323
(* Historical schema versions just in case this is useful later *)
2424
let rio_schema_major_vsn = 5
@@ -58,7 +58,7 @@ let clearwater_felton_release_schema_major_vsn = 5
5858
let clearwater_felton_release_schema_minor_vsn = 70
5959

6060
let creedence_release_schema_major_vsn = 5
61-
let creedence_release_schema_minor_vsn = 71
61+
let creedence_release_schema_minor_vsn = 72
6262

6363
let augusta_release_schema_major_vsn = 5
6464
let augusta_release_schema_minor_vsn = 81
@@ -7746,6 +7746,10 @@ let pci =
77467746
"VMs that currently have a function of this PCI device passed-through to them" ~internal_only:true;
77477747
field ~qualifier:DynamicRO ~ty:(Set (Ref _pci)) ~lifecycle:[Published, rel_boston, ""] "dependencies" "List of dependent PCI devices" ~ignore_foreign_key:true;
77487748
field ~qualifier:RW ~ty:(Map (String,String)) ~lifecycle:[Published, rel_boston, ""] "other_config" "Additional configuration" ~default_value:(Some (VMap []));
7749+
field ~qualifier:StaticRO ~ty:String ~lifecycle:[] "subsystem_vendor_id" "Subsystem vendor ID" ~default_value:(Some (VString "")) ~internal_only:true;
7750+
field ~qualifier:StaticRO ~ty:String ~lifecycle:[Published, rel_creedence, ""] "subsystem_vendor_name" "Subsystem vendor name" ~default_value:(Some (VString ""));
7751+
field ~qualifier:StaticRO ~ty:String ~lifecycle:[] "subsystem_device_id" "Subsystem device ID" ~default_value:(Some (VString "")) ~internal_only:true;
7752+
field ~qualifier:StaticRO ~ty:String ~lifecycle:[Published, rel_creedence, ""] "subsystem_device_name" "Subsystem device name" ~default_value:(Some (VString ""));
77497753
]
77507754
()
77517755

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
################### DO NOT EDIT###################
2+
plugin0 foo
3+
plugin0.framebufferlength 0x10000000
4+
plugin0.vgpu_type bar
5+
plugin0.vdev_id "0x1111:0x2222"
6+
plugin0.pdev_id "0x3333"
7+
plugin0.max_instance 8
8+
plugin0.num_heads 2
9+
plugin0.max_resolution 1920x1200
10+
plugin0.mappable_video_size 0x400000
11+
plugin0.frame_rate_limiter 1
12+
plugin0.frl_config 0x2D
13+
14+
connect0.up vmiop-display
15+
connect0.down vmiop-presentation
16+
################### DO NOT EDIT###################
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
################### DO NOT EDIT###################
2+
plugin0 foo
3+
plugin0.framebufferlength 0x10000000
4+
plugin0.vgpu_type bar
5+
plugin0.vdev_id "0x1111:0x2222"
6+
plugin0.pdev_id "0x3333:0x4444"
7+
plugin0.max_instance 8
8+
plugin0.num_heads 2
9+
plugin0.max_resolution 1920x1200
10+
plugin0.mappable_video_size 0x400000
11+
plugin0.frame_rate_limiter 1
12+
plugin0.frl_config 0x2D
13+
14+
connect0.up vmiop-display
15+
connect0.down vmiop-presentation
16+
################### DO NOT EDIT###################

ocaml/test/test_common.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,13 @@ let make_vdi ~__context ?(ref=Ref.make ()) ?(uuid=make_uuid ()) ?(name_label="")
182182
let make_pci ~__context ?(ref=Ref.make ()) ?(uuid=make_uuid ()) ?(class_id="")
183183
?(class_name="") ?(vendor_id="") ?(vendor_name="") ?(device_id="")
184184
?(device_name="") ?(host=Ref.null) ?(pci_id="") ?(functions=0L)
185-
?(dependencies=[]) ?(other_config=[]) () =
185+
?(dependencies=[]) ?(other_config=[]) ?(subsystem_vendor_id="")
186+
?(subsystem_vendor_name="") ?(subsystem_device_id="")
187+
?(subsystem_device_name="") () =
186188
Db.PCI.create ~__context ~ref ~uuid ~class_id ~class_name ~vendor_id
187189
~vendor_name ~device_id ~device_name ~host ~pci_id ~functions ~dependencies
188-
~other_config;
190+
~other_config ~subsystem_vendor_id ~subsystem_vendor_name
191+
~subsystem_device_id ~subsystem_device_name;
189192
ref
190193

191194
let make_pgpu ~__context ?(ref=Ref.make ()) ?(uuid=make_uuid ()) ?(pCI=Ref.null)

ocaml/test/test_pci_helpers.ml

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ let print_host_pcis () =
2929
(fun p ->
3030
let x_to_str = Printf.sprintf "%04Lx" in
3131
Printf.printf "%s " (String.concat " "
32-
[p.id; x_to_str p.vendor_id; p.vendor_name; x_to_str p.device_id;
33-
p.device_name; x_to_str p.class_id; p.class_name]);
32+
[
33+
p.pci_id;
34+
x_to_str p.vendor.id;
35+
p.vendor.name;
36+
x_to_str p.device.id;
37+
p.device.name;
38+
x_to_str p.pci_class.id;
39+
p.pci_class.name
40+
]);
3441
List.iter (fun s -> print_string (s ^ ", ")) p.related;
3542
print_newline ())
3643
pcis
@@ -55,14 +62,20 @@ module ParseLspciLine = Generic.Make(struct
5562
let string_of_input_t str = str
5663
let string_of_output_t pci = Xapi_pci_helpers.(
5764
Printf.sprintf
58-
"{%s; %Lx; %s; %Lx; %s; %Lx; %s; [%s]}"
59-
pci.id
60-
pci.vendor_id
61-
pci.vendor_name
62-
pci.device_id
63-
pci.device_name
64-
pci.class_id
65-
pci.class_name
65+
"{%s; %Lx; %s; %Lx; %s; %Lx; %s; %s; %s; [%s]}"
66+
pci.pci_id
67+
pci.vendor.id
68+
pci.vendor.name
69+
pci.device.id
70+
pci.device.name
71+
pci.pci_class.id
72+
pci.pci_class.name
73+
(match pci.subsystem_vendor with
74+
| Some vendor -> Printf.sprintf "Some {%Lx; %s}" vendor.id vendor.name
75+
| None -> "None")
76+
(match pci.subsystem_device with
77+
| Some device -> Printf.sprintf "Some {%Lx; %s}" device.id device.name
78+
| None -> "None")
6679
(String.concat "; " pci.related))
6780
end
6881

@@ -77,50 +90,70 @@ module ParseLspciLine = Generic.Make(struct
7790
* subvendor IDs can be parsed. *)
7891
"0000:44:00.0 \"0001\" \"0003\" \"0001\" -ra1 \"0001\" \"0002\"",
7992
Xapi_pci_helpers.({
80-
id = "0000:44:00.0";
81-
vendor_id = 0x0003L;
82-
vendor_name = "SimpleVendorName3";
83-
device_id = 0x0001L;
84-
device_name = "SimpleDeviceName-3-1";
85-
class_id = 0x00L;
86-
class_name = "Class Name";
93+
pci_id = "0000:44:00.0";
94+
vendor = {id = 0x0003L; name = "SimpleVendorName3"};
95+
device = {id = 0x0001L; name = "SimpleDeviceName-3-1"};
96+
pci_class = {id = 0x00L; name = "Class Name"};
97+
subsystem_vendor = Some {id = 0x0001L; name = "SimpleVendorName1"};
98+
subsystem_device = Some {id = 0x0002L; name = "SimpleSubDeviceName-3-1-1-2"};
8799
related = []
88100
});
89101
(* Test that a device present in pci.ids without subdevice or
90102
* subvendor IDs can be parsed. *)
91103
"0000:45:00.0 \"0001\" \"0003\" \"0001\" -ra1 \"\" \"\"",
92104
Xapi_pci_helpers.({
93-
id = "0000:45:00.0";
94-
vendor_id = 0x0003L;
95-
vendor_name = "SimpleVendorName3";
96-
device_id = 0x0001L;
97-
device_name = "SimpleDeviceName-3-1";
98-
class_id = 0x00L;
99-
class_name = "Class Name";
105+
pci_id = "0000:45:00.0";
106+
vendor = {id = 0x0003L; name = "SimpleVendorName3"};
107+
device = {id = 0x0001L; name = "SimpleDeviceName-3-1"};
108+
pci_class = {id = 0x00L; name = "Class Name"};
109+
subsystem_vendor = None;
110+
subsystem_device = None;
100111
related = []
101112
});
113+
(* Test that a device present in pci.ids with an unknown subsystem device
114+
* ID can be parsed. *)
115+
"0000:0a:00.0 \"0001\" \"0003\" \"0001\" -ra1 \"0001\" \"0123\"",
116+
Xapi_pci_helpers.({
117+
pci_id = "0000:0a:00.0";
118+
vendor = {id = 0x0003L; name = "SimpleVendorName3"};
119+
device = {id = 0x0001L; name = "SimpleDeviceName-3-1"};
120+
pci_class = {id = 0x00L; name = "Class Name"};
121+
subsystem_vendor = Some {id = 0x0001L; name = "SimpleVendorName1"};
122+
subsystem_device = Some {id = 0x0123L; name = "Unknown (0123)"};
123+
related = [];
124+
});
125+
(* Test that a device present in pci.ids with an unknown subsystem vendor
126+
* ID and an unknown subsystem device ID can be parsed. *)
127+
"0000:0a:00.0 \"0001\" \"0003\" \"0001\" -ra1 \"0123\" \"0123\"",
128+
Xapi_pci_helpers.({
129+
pci_id = "0000:0a:00.0";
130+
vendor = {id = 0x0003L; name = "SimpleVendorName3"};
131+
device = {id = 0x0001L; name = "SimpleDeviceName-3-1"};
132+
pci_class = {id = 0x00L; name = "Class Name"};
133+
subsystem_vendor = Some {id = 0x0123L; name = "Unknown (0123)"};
134+
subsystem_device = Some {id = 0x0123L; name = "Unknown (0123)"};
135+
related = [];
136+
});
102137
(* Test that a device not preset in pci.ids can be parsed. *)
103138
"0000:46:00.0 \"0001\" \"0055\" \"abcd\" -ra1 \"\" \"\"",
104139
Xapi_pci_helpers.({
105-
id = "0000:46:00.0";
106-
vendor_id = 0x0055L;
107-
vendor_name = "Unknown (0055)";
108-
device_id = 0xabcdL;
109-
device_name = "Unknown (abcd)";
110-
class_id = 0x00L;
111-
class_name = "Class Name";
140+
pci_id = "0000:46:00.0";
141+
vendor = {id = 0x0055L; name = "Unknown (0055)"};
142+
device = {id = 0xabcdL; name = "Unknown (abcd)"};
143+
pci_class = {id = 0x00L; name = "Class Name"};
144+
subsystem_vendor = None;
145+
subsystem_device = None;
112146
related = [];
113147
});
114148
(* Test that an unknown device from a known vendor can be parsed. *)
115149
"0000:47:00.0 \"0001\" \"0003\" \"abcd\" -ra1 \"\" \"\"",
116150
Xapi_pci_helpers.({
117-
id = "0000:47:00.0";
118-
vendor_id = 0x0003L;
119-
vendor_name = "SimpleVendorName3";
120-
device_id = 0xabcdL;
121-
device_name = "Unknown (abcd)";
122-
class_id = 0x00L;
123-
class_name = "Class Name";
151+
pci_id = "0000:47:00.0";
152+
vendor = {id = 0x0003L; name = "SimpleVendorName3"};
153+
device = {id = 0xabcdL; name = "Unknown (abcd)"};
154+
pci_class = {id = 0x00L; name = "Class Name"};
155+
subsystem_vendor = None;
156+
subsystem_device = None;
124157
related = [];
125158
});
126159
]

ocaml/test/test_vgpu_type.ml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,67 @@
1414

1515
open OUnit
1616
open Test_common
17+
open Test_highlevel
1718
open Test_vgpu_common
1819
open Xapi_vgpu_type
1920

20-
(* This test generates a lot of print --- set skip to false to enable *)
21-
let skip = true
22-
let k100_path = "/usr/share/nvidia/vgx/grid_k100.conf"
21+
let string_of_vgpu_conf conf =
22+
Printf.sprintf "%04Lx %s %04Lx %04Lx %Ld"
23+
conf.pdev_id
24+
(match conf.psubdev_id with
25+
| Some id -> Printf.sprintf "Some %04Lx" id
26+
| None -> "None")
27+
conf.vdev_id
28+
conf.vsubdev_id
29+
conf.framebufferlength
2330

2431
let print_vgpu_conf conf =
25-
Printf.printf "%04Lx %04Lx %04Lx %Ld\n"
26-
conf.pdev_id conf.vdev_id conf.vsubdev_id conf.framebufferlength
32+
Printf.printf "%s\n" (string_of_vgpu_conf conf)
2733

28-
let test_of_conf_file path () =
29-
skip_if skip "Generates print...";
30-
if (Sys.file_exists path && not (Sys.is_directory path)) then begin
31-
let vgpu_conf = of_conf_file path in
32-
print_vgpu_conf vgpu_conf
34+
module OfConfFile = Generic.Make(struct
35+
module Io = struct
36+
type input_t = string
37+
type output_t = vgpu_conf
38+
39+
let string_of_input_t x = x
40+
let string_of_output_t = string_of_vgpu_conf
3341
end
3442

43+
let transform = of_conf_file
44+
45+
let tests = [
46+
"ocaml/test/data/test_vgpu_subdevid.conf",
47+
{
48+
pdev_id = 0x3333L;
49+
psubdev_id = Some 0x4444L;
50+
vdev_id = 0x1111L;
51+
vsubdev_id = 0x2222L;
52+
framebufferlength = 0x10000000L;
53+
num_heads = 2L;
54+
max_instance = 8L;
55+
max_x = 1920L;
56+
max_y = 1200L;
57+
file_path = "ocaml/test/data/test_vgpu_subdevid.conf";
58+
};
59+
"ocaml/test/data/test_vgpu_nosubdevid.conf",
60+
{
61+
pdev_id = 0x3333L;
62+
psubdev_id = None;
63+
vdev_id = 0x1111L;
64+
vsubdev_id = 0x2222L;
65+
framebufferlength = 0x10000000L;
66+
num_heads = 2L;
67+
max_instance = 8L;
68+
max_x = 1920L;
69+
max_y = 1200L;
70+
file_path = "ocaml/test/data/test_vgpu_nosubdevid.conf";
71+
};
72+
]
73+
end)
74+
75+
(* This test generates a lot of print --- set skip to false to enable *)
76+
let skip = true
77+
3578
let print_nv_types () =
3679
skip_if skip "Generates print...";
3780
try
@@ -91,7 +134,7 @@ let test_find_or_create () =
91134
let test =
92135
"test_vgpu_type" >:::
93136
[
94-
"test_of_conf_file" >:: test_of_conf_file k100_path;
137+
"test_of_conf_file" >:: OfConfFile.test;
95138
"print_nv_types" >:: print_nv_types;
96139
"test_find_or_create" >:: test_find_or_create;
97140
]

0 commit comments

Comments
 (0)