Remove the BUILD_INFO_FILE variable
[akaros.git] / kern / arch / x86 / devarch.c
index ca742d6..2a45f6e 100644 (file)
@@ -90,10 +90,10 @@ static struct dirtab archdir[Qmax] = {
 #define MSR_MAX_VAR_COUNTERS 16
 #define MSR_MAX_FIX_COUNTERS 4
 
-static const struct address_range msr_rd_wlist[] = {
+static struct address_range msr_rd_wlist[] = {
        ADDRESS_RANGE(0x00000000, 0xffffffff),
 };
-static const struct address_range msr_wr_wlist[] = {
+static struct address_range msr_wr_wlist[] = {
        ADDRESS_RANGE(MSR_IA32_PERFCTR0,
                                  MSR_IA32_PERFCTR0 + MSR_MAX_VAR_COUNTERS - 1),
        ADDRESS_RANGE(MSR_ARCH_PERFMON_EVENTSEL0,
@@ -200,8 +200,8 @@ int iounused(int start, int end)
        struct io_map *map;
 
        for (map = iomap.map; map; map = map->next) {
-               if (((start >= map->start) && (start < map->end))
-                       || ((start <= map->start) && (end > map->start)))
+               if (((start >= map->start) && (start < map->end)) ||
+                   ((start <= map->start) && (end > map->start)))
                        return 0;
        }
        return 1;
@@ -322,7 +322,7 @@ static struct perf_context *arch_create_perf_context(void)
 {
        ERRSTACK(1);
        struct perf_context *pc = kzmalloc(sizeof(struct perf_context),
-                                                                          KMALLOC_WAIT);
+                                          MEM_WAIT);
 
        if (waserror()) {
                kfree(pc);
@@ -344,8 +344,8 @@ static void arch_free_perf_context(struct perf_context *pc)
 }
 
 static const uint8_t *arch_read_core_set(struct core_set *cset,
-                                                                                const uint8_t *kptr,
-                                                                                const uint8_t *ktop)
+                                         const uint8_t *kptr,
+                                         const uint8_t *ktop)
 {
        int i, nb;
        uint32_t n;
@@ -364,7 +364,7 @@ static const uint8_t *arch_read_core_set(struct core_set *cset,
 }
 
 static long arch_perf_write(struct perf_context *pc, const void *udata,
-                                                       long usize)
+                            long usize)
 {
        ERRSTACK(1);
        void *kdata;
@@ -400,7 +400,7 @@ static long arch_perf_write(struct perf_context *pc, const void *udata,
                        ped = perfmon_open_event(&cset, pc->ps, &pev);
 
                        pc->resp_size = sizeof(uint32_t);
-                       pc->resp = kmalloc(pc->resp_size, KMALLOC_WAIT);
+                       pc->resp = kmalloc(pc->resp_size, MEM_WAIT);
                        put_le_u32(pc->resp, (uint32_t) ped);
                        break;
                }
@@ -416,13 +416,14 @@ static long arch_perf_write(struct perf_context *pc, const void *udata,
 
                        pef = perfmon_get_event_status(pc->ps, (int) ped);
 
-                       mvalues = kzmalloc(num_cores * sizeof(mvalues), KMALLOC_WAIT);
+                       mvalues = kzmalloc(num_cores * sizeof(mvalues),
+                                          MEM_WAIT);
                        for (i = 0; i < num_cores; i++)
                                mvalues[i] = pef->cores_values[i];
 
                        pc->resp_size = 3 * sizeof(uint64_t) + sizeof(uint32_t) +
                                num_cores * sizeof(uint64_t);
-                       pc->resp = kmalloc(pc->resp_size, KMALLOC_WAIT);
+                       pc->resp = kmalloc(pc->resp_size, MEM_WAIT);
 
                        rptr = put_le_u64(pc->resp, pef->ev.event);
                        rptr = put_le_u64(rptr, pef->ev.flags);
@@ -451,7 +452,7 @@ static long arch_perf_write(struct perf_context *pc, const void *udata,
                        perfmon_get_cpu_caps(&pcc);
 
                        pc->resp_size = 6 * sizeof(uint32_t);
-                       pc->resp = kmalloc(pc->resp_size, KMALLOC_WAIT);
+                       pc->resp = kmalloc(pc->resp_size, MEM_WAIT);
 
                        rptr = put_le_u32(pc->resp, pcc.perfmon_version);
                        rptr = put_le_u32(rptr, pcc.proc_arch_events);
@@ -543,12 +544,13 @@ static long archread(struct chan *c, void *a, long n, int64_t offset)
                        return readmem(offset, a, n, KADDR(0), REAL_MEM_SIZE);
                case Qmsr:
                        if (!address_range_find(msr_rd_wlist, ARRAY_SIZE(msr_rd_wlist),
-                                                                       (uintptr_t) offset))
-                               error(EPERM, ERROR_FIXME);
+                                               (uintptr_t) offset))
+                               error(EPERM, "MSR 0x%x not in read whitelist", offset);
                        core_set_init(&cset);
                        core_set_fill_available(&cset);
                        msr_set_address(&msra, (uint32_t) offset);
-                       values = kzmalloc(num_cores * sizeof(uint64_t), KMALLOC_WAIT);
+                       values = kzmalloc(num_cores * sizeof(uint64_t),
+                                         MEM_WAIT);
                        if (!values)
                                error(ENOMEM, ERROR_FIXME);
                        msr_set_values(&msrv, values, num_cores);
@@ -558,16 +560,22 @@ static long archread(struct chan *c, void *a, long n, int64_t offset)
                        if (likely(!err)) {
                                if (n >= num_cores * sizeof(uint64_t)) {
                                        if (!memcpy_to_user_errno(current, a, values,
-                                                                                         num_cores * sizeof(uint64_t)))
+                                                                 num_cores * sizeof(uint64_t)))
                                                n = num_cores * sizeof(uint64_t);
                                        else
                                                n = -1;
                                } else {
                                        kfree(values);
-                                       error(ERANGE, ERROR_FIXME);
+                                       error(ERANGE, "Not enough space for MSR read");
                                }
                        } else {
-                               n = -1;
+                               switch (-err) {
+                               case (EFAULT):
+                                       error(-err, "read_msr() faulted on MSR 0x%x", offset);
+                               case (ERANGE):
+                                       error(-err, "Not enough space for MSR read");
+                               };
+                               error(-err, "MSR read failed");
                        }
                        kfree(values);
                        return n;
@@ -602,7 +610,7 @@ static long archread(struct chan *c, void *a, long n, int64_t offset)
                                if (offset-- > 0)
                                        continue;
                                snprintf(p, n * Linelen, "%#8p %#8p %-12.12s\n", map->start,
-                                                map->end - 1, map->tag);
+                                        map->end - 1, map->tag);
                                p += Linelen;
                                n--;
                        }
@@ -664,10 +672,10 @@ static long archwrite(struct chan *c, void *a, long n, int64_t offset)
                        return n;
                case Qmsr:
                        if (!address_range_find(msr_wr_wlist, ARRAY_SIZE(msr_wr_wlist),
-                                                                       (uintptr_t) offset))
-                               error(EPERM, ERROR_FIXME);
+                                               (uintptr_t) offset))
+                               error(EPERM, "MSR 0x%x not in write whitelist", offset);
                        if (n != sizeof(uint64_t))
-                               error(EINVAL, ERROR_FIXME);
+                               error(EINVAL, "Tried to write more than a u64 (%p)", n);
                        if (memcpy_from_user_errno(current, &value, a, sizeof(value)))
                                return -1;
 
@@ -677,8 +685,15 @@ static long archwrite(struct chan *c, void *a, long n, int64_t offset)
                        msr_set_value(&msrv, value);
 
                        err = msr_cores_write(&cset, &msra, &msrv);
-                       if (unlikely(err))
-                               error(-err, ERROR_FIXME);
+                       if (unlikely(err)) {
+                               switch (-err) {
+                               case (EFAULT):
+                                       error(-err, "write_msr() faulted on MSR 0x%x", offset);
+                               case (ERANGE):
+                                       error(-err, "Not enough space for MSR write");
+                               };
+                               error(-err, "MSR write failed");
+                       }
                        return sizeof(uint64_t);
                case Qperf: {
                        struct perf_context *pc = (struct perf_context *) c->aux;
@@ -693,11 +708,21 @@ static long archwrite(struct chan *c, void *a, long n, int64_t offset)
        return 0;
 }
 
+static void archinit(void)
+{
+       int ret;
+
+       ret = address_range_init(msr_rd_wlist, ARRAY_SIZE(msr_rd_wlist));
+       assert(!ret);
+       ret = address_range_init(msr_wr_wlist, ARRAY_SIZE(msr_wr_wlist));
+       assert(!ret);
+}
+
 struct dev archdevtab __devtab = {
        .name = "arch",
 
        .reset = devreset,
-       .init = devinit,
+       .init = archinit,
        .shutdown = devshutdown,
        .attach = archattach,
        .walk = archwalk,