diff --git a/driver/driver.go b/driver/driver.go index bb882d9c..0dcf0a0f 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -143,6 +143,7 @@ type DeviceProperties struct { func (d *Driver) RegisterGPU( commandProcessorPort sim.Port, properties DeviceProperties, + gmmuPageTable vm.PageTable, ) { d.GPUs = append(d.GPUs, commandProcessorPort) @@ -157,8 +158,13 @@ func (d *Driver) RegisterGPU( } gpuDevice.SetTotalMemSize(properties.DRAMSize) d.memAllocator.RegisterDevice(gpuDevice) - d.devices = append(d.devices, gpuDevice) + + for _, page := range d.memAllocator.GetVAddrToPageMapping() { + if page.DeviceID == uint64(gpuDevice.ID) { + gmmuPageTable.Insert(page) + } + } } // Tick ticks diff --git a/driver/internal/memoryallocator.go b/driver/internal/memoryallocator.go index 1a887ea5..83f4c909 100644 --- a/driver/internal/memoryallocator.go +++ b/driver/internal/memoryallocator.go @@ -22,6 +22,8 @@ type MemoryAllocator interface { vAddr uint64, unified bool, ) vm.Page + + GetVAddrToPageMapping() map[uint64]vm.Page } // NewMemoryAllocator creates a new memory allocator. @@ -285,3 +287,13 @@ func (a *memoryAllocatorImpl) Free(ptr uint64) { a.removePage(ptr) } + +func (a *memoryAllocatorImpl) GetVAddrToPageMapping() map[uint64]vm.Page { + a.Lock() + defer a.Unlock() + copy := make(map[uint64]vm.Page, len(a.vAddrToPageMapping)) + for vAddr, page := range a.vAddrToPageMapping { + copy[vAddr] = page + } + return copy +}