+/*
+ * void pmap_init_sharedpage(void);
+ *
+ * Hack map for the 64-bit commpage
+ */
+
+void pmap_init_sharedpage(vm_offset_t cpg){
+
+ addr64_t cva, cpoff;
+ ppnum_t cpphys;
+
+ sharedPmap = pmap_create(0, FALSE); /* Get a pmap to hold the common segment */
+ if(!sharedPmap) { /* Check for errors */
+ panic("pmap_init_sharedpage: couldn't make sharedPmap\n");
+ }
+
+ for(cpoff = 0; cpoff < _COMM_PAGE_AREA_USED; cpoff += 4096) { /* Step along now */
+
+ cpphys = pmap_find_phys(kernel_pmap, (addr64_t)cpg + cpoff);
+ if(!cpphys) {
+ panic("pmap_init_sharedpage: compage %016llX not mapped in kernel\n", cpg + cpoff);
+ }
+
+ cva = mapping_make(sharedPmap, (addr64_t)((uint32_t)_COMM_PAGE_BASE_ADDRESS) + cpoff,
+ cpphys, mmFlgPerm, 1, VM_PROT_READ | VM_PROT_EXECUTE); /* Map the page read/execute only */
+ if(cva) { /* Check for errors */
+ panic("pmap_init_sharedpage: couldn't map commpage page - cva = %016llX\n", cva);
+ }
+
+ }
+
+ return;
+}
+
+
+/*
+ * void pmap_map_sharedpage(pmap_t pmap);
+ *
+ * Maps the last segment in a 64-bit address space
+ *
+ *
+ */
+
+void pmap_map_sharedpage(task_t task, pmap_t pmap){
+
+ kern_return_t ret;
+
+ if(task_has_64BitAddr(task) || _cpu_capabilities & k64Bit) { /* Should we map the 64-bit page -1? */
+ ret = pmap_nest(pmap, sharedPmap, 0xFFFFFFFFF0000000ULL, 0x00000000F0000000ULL,
+ 0x0000000010000000ULL); /* Nest the highest possible segment to map comm page */
+ if(ret != KERN_SUCCESS) { /* Did it work? */
+ panic("pmap_map_sharedpage: couldn't nest shared page - ret = %08X\n", ret);
+ }
+ }
+
+ return;
+}
+
+
+/*
+ * void pmap_unmap_sharedpage(pmap_t pmap);
+ *
+ * Unmaps the last segment in a 64-bit address space
+ *
+ */
+
+void pmap_unmap_sharedpage(pmap_t pmap){
+
+ kern_return_t ret;
+ mapping_t *mp;
+ boolean_t inter;
+ int gotnest;
+ addr64_t nextva;
+
+ if(BootProcInfo.pf.Available & pf64Bit) { /* Are we on a 64-bit machine? */
+
+ inter = ml_set_interrupts_enabled(FALSE); /* Disable interruptions for now */
+ mp = hw_find_map(pmap, 0xFFFFFFFFF0000000ULL, &nextva); /* Find the mapping for this address */
+ if((unsigned int)mp == mapRtBadLk) { /* Did we lock up ok? */
+ panic("pmap_unmap_sharedpage: mapping lock failure - rc = %p, pmap = %p\n", mp, pmap); /* Die... */
+ }
+
+ gotnest = 0; /* Assume nothing here */
+ if(mp) {
+ gotnest = ((mp->mpFlags & mpType) == mpNest);
+ /* Remember if we have a nest here */
+ mapping_drop_busy(mp); /* We have everything we need from the mapping */
+ }
+ ml_set_interrupts_enabled(inter); /* Put interrupts back to what they were */
+
+ if(!gotnest) return; /* Leave if there isn't any nesting here */
+
+ ret = pmap_unnest(pmap, 0xFFFFFFFFF0000000ULL, 0x0000000010000000ULL); /* Unnest the max 64-bit page */
+
+ if(ret != KERN_SUCCESS) { /* Did it work? */
+ panic("pmap_unmap_sharedpage: couldn't unnest shared page - ret = %08X\n", ret);
+ }
+ }
+
+ return;
+}
+