+
+/*
+ * Read data from a physical address.
+ */
+
+
+static unsigned int
+ml_phys_read_data(pmap_paddr_t paddr, int size )
+{
+ mapwindow_t *map;
+ unsigned int result;
+
+ mp_disable_preemption();
+
+ map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | (paddr & PG_FRAME) | INTEL_PTE_REF));
+
+ switch (size) {
+ unsigned char s1;
+ unsigned short s2;
+ case 1:
+ s1 = *(unsigned char *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK));
+ result = s1;
+ break;
+ case 2:
+ s2 = *(unsigned short *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK));
+ result = s2;
+ break;
+ case 4:
+ default:
+ result = *(unsigned int *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK));
+ break;
+ }
+ pmap_put_mapwindow(map);
+
+ mp_enable_preemption();
+
+ return result;
+}
+
+static unsigned long long
+ml_phys_read_long_long(pmap_paddr_t paddr )
+{
+ mapwindow_t *map;
+ unsigned long long result;
+
+ mp_disable_preemption();
+
+ map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | (paddr & PG_FRAME) | INTEL_PTE_REF));
+
+ result = *(unsigned long long *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK));
+
+ pmap_put_mapwindow(map);
+
+ mp_enable_preemption();
+
+ return result;
+}
+
+unsigned int ml_phys_read( vm_offset_t paddr)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr, 4);
+}
+
+unsigned int ml_phys_read_word(vm_offset_t paddr) {
+
+ return ml_phys_read_data((pmap_paddr_t)paddr, 4);
+}
+
+unsigned int ml_phys_read_64(addr64_t paddr64)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr64, 4);
+}
+
+unsigned int ml_phys_read_word_64(addr64_t paddr64)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr64, 4);
+}
+
+unsigned int ml_phys_read_half(vm_offset_t paddr)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr, 2);
+}
+
+unsigned int ml_phys_read_half_64(addr64_t paddr64)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr64, 2);
+}
+
+unsigned int ml_phys_read_byte(vm_offset_t paddr)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr, 1);
+}
+
+unsigned int ml_phys_read_byte_64(addr64_t paddr64)
+{
+ return ml_phys_read_data((pmap_paddr_t)paddr64, 1);
+}
+
+unsigned long long ml_phys_read_double(vm_offset_t paddr)
+{
+ return ml_phys_read_long_long((pmap_paddr_t)paddr);
+}
+
+unsigned long long ml_phys_read_double_64(addr64_t paddr64)
+{
+ return ml_phys_read_long_long((pmap_paddr_t)paddr64);
+}
+
+
+
+/*
+ * Write data to a physical address.
+ */
+
+static void
+ml_phys_write_data(pmap_paddr_t paddr, unsigned long data, int size)
+{
+ mapwindow_t *map;
+
+ mp_disable_preemption();
+
+ map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | INTEL_PTE_RW | (paddr & PG_FRAME) |
+ INTEL_PTE_REF | INTEL_PTE_MOD));
+
+ switch (size) {
+ case 1:
+ *(unsigned char *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK)) = (unsigned char)data;
+ break;
+ case 2:
+ *(unsigned short *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK)) = (unsigned short)data;
+ break;
+ case 4:
+ default:
+ *(unsigned int *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK)) = (uint32_t)data;
+ break;
+ }
+ pmap_put_mapwindow(map);
+
+ mp_enable_preemption();
+}
+
+static void
+ml_phys_write_long_long(pmap_paddr_t paddr, unsigned long long data)
+{
+ mapwindow_t *map;
+
+ mp_disable_preemption();
+
+ map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | INTEL_PTE_RW | (paddr & PG_FRAME) |
+ INTEL_PTE_REF | INTEL_PTE_MOD));
+
+ *(unsigned long long *)((uintptr_t)map->prv_CADDR | ((uint32_t)paddr & INTEL_OFFMASK)) = data;
+
+ pmap_put_mapwindow(map);
+
+ mp_enable_preemption();
+}
+
+
+
+void ml_phys_write_byte(vm_offset_t paddr, unsigned int data)
+{
+ ml_phys_write_data((pmap_paddr_t)paddr, data, 1);
+}
+
+void ml_phys_write_byte_64(addr64_t paddr64, unsigned int data)
+{
+ ml_phys_write_data((pmap_paddr_t)paddr64, data, 1);
+}
+
+void ml_phys_write_half(vm_offset_t paddr, unsigned int data)
+{
+ ml_phys_write_data((pmap_paddr_t)paddr, data, 2);
+}
+
+void ml_phys_write_half_64(addr64_t paddr64, unsigned int data)
+{
+ ml_phys_write_data((pmap_paddr_t)paddr64, data, 2);
+}
+
+void ml_phys_write(vm_offset_t paddr, unsigned int data)
+{
+ ml_phys_write_data((pmap_paddr_t)paddr, data, 4);
+}
+
+void ml_phys_write_64(addr64_t paddr64, unsigned int data)