nv: finalize nvdev (#11117)

* nv: finalize nvdev

* typo
This commit is contained in:
nimlgen
2025-07-07 16:31:59 +03:00
committed by GitHub
parent fa59c05282
commit 9a573a1d99
4 changed files with 11 additions and 5 deletions
-5
View File
@@ -853,8 +853,3 @@ class AMDDevice(HCQCompiled):
self.allocator._copyout(sqtt_buf:=memoryview(bytearray(wptr)), buf0)
Compiled.profile_events += [ProfileSQTTEvent(self.device, i, bytes(sqtt_buf), bool((self.sqtt_itrace_se_mask >> i) & 0b1))]
super()._at_profile_finalize()
def finalize(self):
try: self.synchronize() # Try to finalize device in any case.
except RuntimeError as e: print(f"{self.device} synchronization failed before finalizing: {e}")
if hasattr(self.iface, 'device_fini'): self.iface.device_fini()
+2
View File
@@ -482,6 +482,8 @@ class PCIIface(PCIIfaceBase):
res = self.dev_impl.gsp.rpc_rm_control(obj, cmd, params, self.root)
return type(params).from_buffer_copy(res) if params is not None else None
def device_fini(self): self.dev_impl.fini()
class NVDevice(HCQCompiled[NVSignal]):
devices: ClassVar[list[HCQCompiled]] = []
signal_pages: ClassVar[list[HCQBuffer]] = []
+7
View File
@@ -434,6 +434,13 @@ class HCQCompiled(Compiled, Generic[SignalType]):
except Exception: errs += f"\n{iface_t.__name__}: {traceback.format_exc()}"
raise RuntimeError(f"Cannot find a usable interface for {type(self).__name__[:-6]}:{self.device_id}:\n{errs}")
def finalize(self):
try: self.synchronize() # Try to finalize device in any case.
except RuntimeError as e: print(f"{self.device} synchronization failed before finalizing: {e}")
# If the device has an interface, call its device_fini method to clean up resources.
if hasattr(self, 'iface') and hasattr(self.iface, 'device_fini'): self.iface.device_fini()
class HCQBuffer:
def __init__(self, va_addr:sint, size:int, texture_info:Any=None, meta:Any=None, _base:HCQBuffer|None=None, view:MMIOInterface|None=None):
self.va_addr, self.size, self.texture_info, self.meta, self._base, self.view = va_addr, size, texture_info, meta, _base, view
+2
View File
@@ -90,6 +90,8 @@ class NVDev(PCIDevImplBase):
for ip in [self.flcn, self.gsp]: ip.init_sw()
for ip in [self.flcn, self.gsp]: ip.init_hw()
def fini(self): System.pci_reset(self.devfmt) # Reset the device to clean up resources. TODO: Consider a warm start process.
def reg(self, reg:str) -> NVReg: return self.__dict__[reg]
def wreg(self, addr, value):
self.mmio[addr // 4] = value