@@ -58,25 +58,23 @@ PCI::MMIOAccess::MMIOAccess(ACPI_RAW::MCFG& raw_mcfg)
58
58
, m_mapped_address(ChangeableAddress(0xFFFF , 0xFF , 0xFF , 0xFF ))
59
59
{
60
60
kprintf (" PCI: Using MMIO Mechanism for PCI Configuartion Space Access\n " );
61
- m_mmio_window = *AnonymousVMObject::create_with_size (PAGE_ROUND_UP (PCI_MMIO_CONFIG_SPACE_SIZE));
62
- m_mmio_window_region = MM.allocate_kernel_region_with_vmobject (*m_mmio_window, m_mmio_window->size (), " PCI MMIO" , Region::Access::Read | Region::Access::Write);
61
+ m_mmio_window_region = MM.allocate_kernel_region (PAGE_ROUND_UP (PCI_MMIO_CONFIG_SPACE_SIZE), " PCI MMIO" , Region::Access::Read | Region::Access::Write);
63
62
64
- auto checkup_region = MM.allocate_kernel_region ((PAGE_SIZE * 2 ), " PCI MCFG Checkup" , Region::Access::Read | Region::Access::Write);
63
+ auto checkup_region = MM.allocate_kernel_region (PhysicalAddress ( page_base_of (( u32 )&raw_mcfg)), (PAGE_SIZE * 2 ), " PCI MCFG Checkup" , Region::Access::Read | Region::Access::Write);
65
64
#ifdef PCI_DEBUG
66
65
dbgprintf (" PCI: Checking MCFG Table length to choose the correct mapping size\n " );
67
66
#endif
68
- mmap_region (*checkup_region, PhysicalAddress (( u32 )&raw_mcfg & 0xfffff000 ));
69
- ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)( checkup_region->vaddr ().get () + ((u32 )&raw_mcfg & 0xfff ) );
67
+
68
+ ACPI_RAW::SDTHeader* sdt = (ACPI_RAW::SDTHeader*)checkup_region->vaddr ().offset ( offset_in_page ((u32 )&raw_mcfg)). as_ptr ( );
70
69
u32 length = sdt->length ;
71
70
u8 revision = sdt->revision ;
72
71
73
72
kprintf (" PCI: MCFG, length - %u, revision %d\n " , length, revision);
74
73
checkup_region->unmap ();
75
74
76
- auto mcfg_region = MM.allocate_kernel_region (PAGE_ROUND_UP (length) + PAGE_SIZE, " PCI Parsing MCFG" , Region::Access::Read | Region::Access::Write);
77
- mmap_region (*mcfg_region, PhysicalAddress ((u32 )&raw_mcfg & 0xfffff000 ));
75
+ auto mcfg_region = MM.allocate_kernel_region (PhysicalAddress (page_base_of ((u32 )&raw_mcfg)), PAGE_ROUND_UP (length) + PAGE_SIZE, " PCI Parsing MCFG" , Region::Access::Read | Region::Access::Write);
78
76
79
- ACPI_RAW::MCFG & mcfg = *(( ACPI_RAW::MCFG*)( mcfg_region->vaddr ().get () + ((u32 )&raw_mcfg & 0xfff )) );
77
+ auto & mcfg = *(ACPI_RAW::MCFG*)mcfg_region->vaddr ().offset ( offset_in_page ((u32 )&raw_mcfg)). as_ptr ( );
80
78
#ifdef PCI_DEBUG
81
79
dbgprintf (" PCI: Checking MCFG @ V 0x%x, P 0x%x\n " , &mcfg, &raw_mcfg);
82
80
#endif
@@ -116,7 +114,8 @@ void PCI::MMIOAccess::map_device(Address address)
116
114
#ifdef PCI_DEBUG
117
115
dbgprintf (" PCI: Mapping device @ pci (%w:%b:%b.%b), V 0x%x, P 0x%x\n " , address.seg (), address.bus (), address.slot (), address.function (), m_mmio_window_region->vaddr ().get (), device_physical_mmio_space.get ());
118
116
#endif
119
- MM.map_for_kernel (m_mmio_window_region->vaddr (), device_physical_mmio_space);
117
+ m_mmio_window_region->vmobject ().physical_pages ()[0 ] = PhysicalPage::create (device_physical_mmio_space,false ,false );
118
+ m_mmio_window_region->remap ();
120
119
m_mapped_address = address;
121
120
}
122
121
@@ -205,33 +204,6 @@ void PCI::MMIOAccess::enumerate_all(Function<void(Address, ID)>& callback)
205
204
}
206
205
}
207
206
208
- void PCI::MMIOAccess::mmap (VirtualAddress vaddr, PhysicalAddress paddr, u32 length)
209
- {
210
- unsigned i = 0 ;
211
- while (length >= PAGE_SIZE) {
212
- MM.map_for_kernel (VirtualAddress (vaddr.offset (i * PAGE_SIZE).get ()), PhysicalAddress (paddr.offset (i * PAGE_SIZE).get ()));
213
- #ifdef PCI_DEBUG
214
- dbgprintf (" PCI: map - V 0x%x -> P 0x%x\n " , vaddr.offset (i * PAGE_SIZE).get (), paddr.offset (i * PAGE_SIZE).get ());
215
- #endif
216
- length -= PAGE_SIZE;
217
- i++;
218
- }
219
- if (length > 0 ) {
220
- MM.map_for_kernel (vaddr.offset (i * PAGE_SIZE), paddr.offset (i * PAGE_SIZE), true );
221
- }
222
- #ifdef PCI_DEBUG
223
- dbgprintf (" PCI: Finished mapping\n " );
224
- #endif
225
- }
226
-
227
- void PCI::MMIOAccess::mmap_region (Region& region, PhysicalAddress paddr)
228
- {
229
- #ifdef PCI_DEBUG
230
- dbgprintf (" PCI: Mapping region, size - %u\n " , region.size ());
231
- #endif
232
- mmap (region.vaddr (), paddr, region.size ());
233
- }
234
-
235
207
PCI::MMIOSegment::MMIOSegment (PhysicalAddress segment_base_addr, u8 start_bus, u8 end_bus)
236
208
: m_base_addr(segment_base_addr)
237
209
, m_start_bus(start_bus)
0 commit comments