From cd9c4160ff72ef812df0ad6a76d30a49fbd6ecab Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Tue, 7 Jul 2009 22:49:09 +0100 Subject: [PATCH] add a way to specify power_mgmt and msitranslate per pci device. rename pci_msitranslate into global_pci_msitranslate. --- xenvm/vmact.ml | 2 +- xenvm/vmconfig.ml | 65 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/xenvm/vmact.ml b/xenvm/vmact.ml index c87ef3f..7ac8a9d 100644 --- a/xenvm/vmact.ml +++ b/xenvm/vmact.ml @@ -158,7 +158,7 @@ let add_devices xc xs domid state restore = ) devs in if !bind then Device.PCI.bind devs; - Device.PCI.add ~xc ~xs ~hvm:cfg.hvm ~msitranslate:cfg.pci_msitranslate devs domid devid + Device.PCI.add ~xc ~xs ~hvm:cfg.hvm ~msitranslate:cfg.global_pci_msitranslate devs domid devid ) cfg.pcis; (* add device model *) diff --git a/xenvm/vmconfig.ml b/xenvm/vmconfig.ml index 43b3670..96651f1 100644 --- a/xenvm/vmconfig.ml +++ b/xenvm/vmconfig.ml @@ -38,7 +38,13 @@ let snapshot_mode_of_string s = | _ -> failwith "unknown snapshot mode" type config_pci = { - pci_bind: bool; pci_domain: int; pci_bus: int; pci_slot: int; pci_func: int; + pci_bind: bool; + pci_domain: int; + pci_bus: int; + pci_slot: int; + pci_func: int; + pci_msitranslate: int option; + pci_power_mgmt: int option; } type config_disk = { @@ -110,7 +116,7 @@ type config = { vpt_align: int option; extra_local_watches: string list; extra_vm_watches: string list; - pci_msitranslate: int; + global_pci_msitranslate: int; sound: string option; inject_sci: int; } @@ -119,12 +125,35 @@ module Config = struct let config_pci_of_string s = (* format is : domain:bus:slot.func *) - let pcistruct = - try Scanf.sscanf s "%d,bind,%x:%x:%x.%x" (fun id a b c d -> id, true, (a, b, c, d)) - with _ -> - Scanf.sscanf s "%d,%x:%x:%x.%x" (fun id a b c d -> id, false, (a, b, c, d)) + let l = String.split ',' s in + let id, bind, pcidev_str, params = + match l with + | id :: "bind" :: pcidev :: params -> + int_of_string id, true, pcidev, params + | id :: pcidev :: params -> + int_of_string id, false, pcidev, params + | _ -> + failwith "unexpected format for pci config" + in + let pcidev = + try Scanf.sscanf pcidev_str "%x:%x:%x.%x" (fun a b c d -> (a, b, c, d)) + with _ -> failwith "unexpected format for pci descriptor" + in + let split_kv s = + match String.split ~limit:2 '=' s with + | k :: v :: [] -> k, v + | _ -> failwith "expected key value in params" + in + let params = List.map split_kv params in + let msitranslate = + try Some (int_of_string (snd (List.find (fun p -> fst p = "msitranslate") params))) + with Not_found -> None + in + let power_mgmt = + try Some (int_of_string (snd (List.find (fun p -> fst p = "power_mgmt") params))) + with Not_found -> None in - pcistruct + id, bind, pcidev, msitranslate, power_mgmt let config_nic_of_string vm_uuid s = let generate_random_mac () = @@ -266,7 +295,7 @@ let get cfg field = | "vpt-align" -> string_of_int_option cfg.vpt_align | "power-management" -> string_of_int cfg.power_management | "oem-features" -> string_of_int cfg.oem_features - | "pci-msitranslate" -> string_of_int cfg.pci_msitranslate + | "pci-msitranslate" -> string_of_int cfg.global_pci_msitranslate | "inject-sci" -> string_of_int cfg.inject_sci | _ -> raise (Unknown_field field) @@ -297,7 +326,7 @@ let set cfg field value = | "vpt-align" -> { cfg with vpt_align = int_option_of_string value } | "power-management" -> { cfg with power_management = int_of_string value } | "oem-features" -> { cfg with oem_features = int_of_string value } - | "pci-msitranslate" -> { cfg with pci_msitranslate = int_of_string value } + | "pci-msitranslate" -> { cfg with global_pci_msitranslate = int_of_string value } | "inject-sci" -> { cfg with inject_sci = int_of_string value } | _ -> raise (Unknown_field field) @@ -513,14 +542,22 @@ let of_file error_report file = end; let pcis = let ids = ref [] in - List.iter (fun (id, _, _) -> + List.iter (fun (id, _, _, _, _) -> if not (List.mem id !ids) then ids := id :: !ids ) !pcis; List.map (fun id -> - let ds = List.map (fun (_, bind, (a, b, c, d)) -> - { pci_bind = bind; pci_domain = a; pci_bus = b; pci_slot = c; pci_func = d; } - ) (List.filter (fun (x, _, _) -> x = id) !pcis) in + let ds = List.map (fun (_, bind, (a, b, c, d), msitranslate, power_mgmt) -> + { + pci_bind = bind; + pci_domain = a; + pci_bus = b; + pci_slot = c; + pci_func = d; + pci_msitranslate = msitranslate; + pci_power_mgmt = power_mgmt; + } + ) (List.filter (fun (x, _, _, _, _) -> x = id) !pcis) in id, ds ) !ids in @@ -598,7 +635,7 @@ let of_file error_report file = snapshot_mode = !snapshot_mode; extra_local_watches = List.rev !extra_local_watches; extra_vm_watches = List.rev !extra_vm_watches; - pci_msitranslate = !pci_msitranslate; + global_pci_msitranslate = !pci_msitranslate; sound = !sound; inject_sci = !inject_sci; } -- 2.39.5