]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
add a reset pci device function
authorVincent Hanquez <vincent.hanquez@eu.citrix.com>
Thu, 9 Apr 2009 12:13:35 +0000 (13:13 +0100)
committerVincent Hanquez <vincent.hanquez@eu.citrix.com>
Thu, 9 Apr 2009 12:13:35 +0000 (13:13 +0100)
xenops/device.ml
xenops/device.mli

index 7f080e5972e7d7a64c15f06f3e8520cb5ebb5851..2bc6b108471785a1ac2a47be7704e50f4635997a 100644 (file)
@@ -921,15 +921,17 @@ let write_string_to_file file s =
        let fn_write_string fd = Unixext.really_write fd s 0 (String.length s) in
        Unixext.with_file file [ Unix.O_WRONLY ] 0o640 fn_write_string
 
+let do_flr device =
+       let doflr = "/sys/bus/pci/drivers/pciback/do_flr" in
+       try write_string_to_file doflr device with _ -> ()
+
 let bind pcidevs =
        let bind_to_pciback device =
                let newslot = "/sys/bus/pci/drivers/pciback/new_slot" in
-               let bind =  "/sys/bus/pci/drivers/pciback/bind" in
-               let doflr =  "/sys/bus/pci/drivers/pciback/do_flr" in
+               let bind = "/sys/bus/pci/drivers/pciback/bind" in
                write_string_to_file newslot device;
                write_string_to_file bind device;
-               try write_string_to_file doflr device
-               with _ -> ()
+               do_flr device;
                in
        List.iter (fun (domain, bus, slot, func) ->
                let devstr = sprintf "%.4x:%.2x:%.2x.%.1x" domain bus slot func in
@@ -951,8 +953,7 @@ let bind pcidevs =
        ) pcidevs;
        ()
 
-let clean_shutdown ~xs (x: device) =
-       debug "Device.Pci.clean_shutdown %s" (string_of_device x);
+let enumerate_devs ~xs (x: device) =
        let backend_path = backend_path_of_device ~xs x in
        let num =
                try int_of_string (xs.Xs.read (backend_path ^ "/num_devs"))
@@ -968,12 +969,24 @@ let clean_shutdown ~xs (x: device) =
                with _ ->
                        ()
        done;
-       let devs =
-               List.rev (List.fold_left (fun acc dev ->
-                       match dev with
-                       | None -> acc
-                       | Some dev -> dev :: acc
-               ) [] (Array.to_list devs)) in
+       List.rev (List.fold_left (fun acc dev ->
+               match dev with
+               | None -> acc
+               | Some dev -> dev :: acc
+       ) [] (Array.to_list devs))
+
+let reset ~xs (x: device) =
+       debug "Device.Pci.reset %s" (string_of_device x);
+       let pcidevs = enumerate_devs ~xs x in
+       List.iter (fun (domain, bus, slot, func) ->
+               let devstr = sprintf "%.4x:%.2x:%.2x.%.1x" domain bus slot func in
+               do_flr devstr
+       ) pcidevs;
+       ()
+
+let clean_shutdown ~xs (x: device) =
+       debug "Device.Pci.clean_shutdown %s" (string_of_device x);
+       let devs = enumerate_devs ~xs x in
        Xc.with_intf (fun xc ->
                let hvm =
                        try (Xc.domain_getinfo xc x.frontend.domid).Xc.hvm_guest
index afd66a76ae37d2cbfdf4b02f71fa0c6d68db6ee2..04735852ab752fc14bdf7351d5fde686ee02f0a2 100644 (file)
@@ -130,6 +130,7 @@ sig
               -> (int * int * int * int) list -> Xc.domid -> int -> unit
        val release : xc:Xc.handle -> xs:Xs.xsh -> hvm:bool
               -> (int * int * int * int) list -> Xc.domid -> int -> unit
+       val reset : xs:Xs.xsh -> device -> unit
        val bind : (int * int * int * int) list -> unit
 end