X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/b0d623f7f2ae71ed96e60569f61f9a9a27016e80..04b8595b18b1b41ac7a206e4b3d51a635f8413d7:/bsd/dev/memdev.c?ds=sidebyside diff --git a/bsd/dev/memdev.c b/bsd/dev/memdev.c index fe07f5e53..5a659bebd 100644 --- a/bsd/dev/memdev.c +++ b/bsd/dev/memdev.c @@ -113,7 +113,7 @@ static int mdevrw(dev_t dev, struct uio *uio, int ioflag); static char * nonspace(char *pos, char *end); static char * getspace(char *pos, char *end); -static char * cvtnum(char *pos, char *end, unsigned int *num); +static char * cvtnum(char *pos, char *end, uint64_t *num); #endif /* CONFIG_MEMDEV_INSECURE */ @@ -175,7 +175,7 @@ int mdevBMajor = -1; int mdevCMajor = -1; static int mdevioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p, int is_char); -dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys); +dev_t mdevadd(int devid, uint64_t base, unsigned int size, int phys); dev_t mdevlookup(int devid); void mdevremoveall(void); @@ -354,6 +354,7 @@ static int mdevioctl(dev_t dev, u_long cmd, caddr_t data, __unused int flag, u_int32_t *f; u_int64_t *o; int devid; + dk_memdev_info_t * memdev_info; devid = minor(dev); /* Get minor device number */ @@ -364,6 +365,7 @@ static int mdevioctl(dev_t dev, u_long cmd, caddr_t data, __unused int flag, f = (u_int32_t*)data; o = (u_int64_t *)data; + memdev_info = (dk_memdev_info_t *) data; switch (cmd) { @@ -408,7 +410,22 @@ static int mdevioctl(dev_t dev, u_long cmd, caddr_t data, __unused int flag, if(!(mdev[devid].mdFlags & mdInited)) return (ENXIO); *o = ((mdev[devid].mdSize << 12) + mdev[devid].mdSecsize - 1) / mdev[devid].mdSecsize; break; - + + /* + * We're interested in the following bits of information: + * Are you a memory-backed device (always yes, in this case)? + * Physical memory (mdPhys)? + * What is your base page? + * What is your size? + */ + case DKIOCGETMEMDEVINFO: + if (!(mdev[devid].mdFlags & mdInited)) return (ENXIO); + memdev_info->mi_mdev = TRUE; + memdev_info->mi_phys = (mdev[devid].mdFlags & mdPhys) ? TRUE : FALSE; + memdev_info->mi_base = mdev[devid].mdBase; + memdev_info->mi_size = mdev[devid].mdSize; + break; + default: error = ENOTTY; break; @@ -436,8 +453,8 @@ void mdevinit(__unused int the_cnt) { #ifdef CONFIG_MEMDEV_INSECURE int devid, phys; - ppnum_t base; - unsigned int size; + uint64_t base; + uint64_t size; char *ba, *lp; dev_t dev; @@ -476,7 +493,7 @@ void mdevinit(__unused int the_cnt) { if((ba[0] != ' ') && (ba[0] != 0)) continue; /* End must be null or space */ } - dev = mdevadd(devid, base >> 12, size >> 12, phys); /* Go add the device */ + dev = mdevadd(devid, base >> 12, (unsigned)size >> 12, phys); /* Go add the device */ } #endif /* CONFIG_MEMDEV_INSECURE */ @@ -509,7 +526,7 @@ char *getspace(char *pos, char *end) { /* Find next non-space in string */ } } -char *cvtnum(char *pos, char *end, unsigned int *num) { /* Convert to a number */ +char *cvtnum(char *pos, char *end, uint64_t *num) { /* Convert to a number */ int rad, dig; @@ -543,7 +560,7 @@ char *cvtnum(char *pos, char *end, unsigned int *num) { /* Convert to a number #endif /* CONFIG_MEMDEV_INSECURE */ -dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys) { +dev_t mdevadd(int devid, uint64_t base, unsigned int size, int phys) { int i; @@ -556,7 +573,7 @@ dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys) { continue; /* Skip check */ } if(!(((base + size -1 ) < mdev[i].mdBase) || ((mdev[i].mdBase + mdev[i].mdSize - 1) < base))) { /* Is there any overlap? */ - panic("mdevadd: attempt to add overlapping memory device at %08lX-%08lX\n", (long) mdev[i].mdBase, (long) mdev[i].mdBase + mdev[i].mdSize - 1); + panic("mdevadd: attempt to add overlapping memory device at %016llX-%016llX\n", mdev[i].mdBase, mdev[i].mdBase + mdev[i].mdSize - 1); } } if(devid < 0) { /* Do we have free slots? */ @@ -567,7 +584,7 @@ dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys) { if(devid >= 16) { /* Giving us something bogus? */ panic("mdevadd: attempt to explicitly add a bogus memory device: %08X\n", devid); } - if(mdev[devid].mdFlags &mdInited) { /* Already there? */ + if(mdev[devid].mdFlags & mdInited) { /* Already there? */ panic("mdevadd: attempt to explicitly add a previously defined memory device: %08X\n", devid); } } @@ -611,8 +628,8 @@ dev_t mdevadd(int devid, ppnum_t base, unsigned int size, int phys) { mdev[devid].mdSecsize = DEV_BSIZE; /* Set starting block size */ if(phys) mdev[devid].mdFlags |= mdPhys; /* Show that we are in physical memory */ mdev[devid].mdFlags |= mdInited; /* Show we are all set up */ - printf("Added memory device md%x/rmd%x (%08X/%08X) at %08X for %08X\n", - devid, devid, mdev[devid].mdBDev, mdev[devid].mdCDev, base << 12, size << 12); + printf("Added memory device md%x/rmd%x (%08X/%08X) at %016llX for %016llX\n", + devid, devid, mdev[devid].mdBDev, mdev[devid].mdCDev, base << 12, (uint64_t)size << 12); return mdev[devid].mdBDev; }