Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CPU_UCODE not working in a custom kernel



On Fri, Jan 13, 2012 at 05:49:41PM -0800, Paul Goyette wrote:
> On Fri, 13 Jan 2012, Paul Goyette wrote:
> 
> >I've got a custom kernel with most everything stripped out.  It
> >built fine yesterday, but today, after adding "options CPU_UCODE"
> >it fails to build.
> >
> >It appears that the file firmload.c is not being included in the
> >build, probably because my stripped down kernel does not include
> >any of the devices that would drag in firmload.c (a quick check
> >shows that the list of drivers would be ral and bwi).
> 
> The following patch seems to make this work again.  Should I commit it?

Yes, you should commit your patch.

I have attached a patch that configures the kernel for CPU_UCODE using
the linker and config(1) instead of #ifdef.  Please give it a try.  I'd
like to commit a change like this, soon.

Dave

-- 
David Young
dyoung%pobox.com@localhost    Urbana, IL    (217) 721-9981
Index: ./sys/arch/x86/x86/cpu_ucode_amd.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/cpu_ucode_amd.c,v
retrieving revision 1.1
diff -u -p -r1.1 cpu_ucode_amd.c
--- ./sys/arch/x86/x86/cpu_ucode_amd.c  13 Jan 2012 16:05:15 -0000      1.1
+++ ./sys/arch/x86/x86/cpu_ucode_amd.c  14 Jan 2012 04:10:14 -0000
@@ -32,7 +32,6 @@
 __KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.1 2012/01/13 16:05:15 cegger 
Exp $");
 
 #include "opt_xen.h"
-#include "opt_cpu_ucode.h"
 
 #include <sys/param.h>
 #include <sys/conf.h>
Index: ./sys/arch/x86/x86/cpu_ucode.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/cpu_ucode.c,v
retrieving revision 1.1
diff -u -p -r1.1 cpu_ucode.c
--- ./sys/arch/x86/x86/cpu_ucode.c      13 Jan 2012 16:05:15 -0000      1.1
+++ ./sys/arch/x86/x86/cpu_ucode.c      14 Jan 2012 04:10:14 -0000
@@ -31,8 +31,6 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.1 2012/01/13 16:05:15 cegger Exp 
$");
 
-#include "opt_cpu_ucode.h"
-
 #include <sys/param.h>
 #include <sys/cpuio.h>
 #include <sys/cpu.h>
Index: ./sys/arch/xen/conf/files.xen
===================================================================
RCS file: /cvsroot/src/sys/arch/xen/conf/files.xen,v
retrieving revision 1.124
diff -u -p -r1.124 files.xen
--- ./sys/arch/xen/conf/files.xen       13 Jan 2012 16:05:15 -0000      1.124
+++ ./sys/arch/xen/conf/files.xen       14 Jan 2012 04:10:14 -0000
@@ -93,9 +93,8 @@ file  arch/xen/x86/xen_pmap.c
 file   arch/xen/x86/xen_intr.c
 file   arch/xen/x86/xenfunc.c
 
-defflag        CPU_UCODE
-file   arch/xen/xen/xen_ucode.c        dom0ops | cpu_ucode needs-flag
-file   arch/x86/x86/cpu_ucode_amd.c    dom0ops | cpu_ucode needs-flag
+file   arch/xen/xen/xen_ucode.c        dom0ops | cpu_ucode
+file   arch/x86/x86/cpu_ucode_amd.c    dom0ops | cpu_ucode
 
 file   arch/xen/xen/xen_machdep.c
 file   arch/xen/xen/xen_debug.c
Index: ./sys/arch/xen/xen/xen_ucode.c
===================================================================
RCS file: /cvsroot/src/sys/arch/xen/xen/xen_ucode.c,v
retrieving revision 1.1
diff -u -p -r1.1 xen_ucode.c
--- ./sys/arch/xen/xen/xen_ucode.c      13 Jan 2012 16:05:15 -0000      1.1
+++ ./sys/arch/xen/xen/xen_ucode.c      14 Jan 2012 04:10:14 -0000
@@ -31,8 +31,6 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: xen_ucode.c,v 1.1 2012/01/13 16:05:15 cegger Exp 
$");
 
-#include "opt_cpu_ucode.h"
-
 #include <sys/param.h>
 #include <sys/cpuio.h>
 #include <sys/cpu.h>
Index: ./sys/conf/files
===================================================================
RCS file: /cvsroot/src/sys/conf/files,v
retrieving revision 1.1035
diff -u -p -r1.1035 files
--- ./sys/conf/files    13 Jan 2012 21:46:00 -0000      1.1035
+++ ./sys/conf/files    14 Jan 2012 04:10:14 -0000
@@ -1471,6 +1475,7 @@ file      kern/kern_clock.c
 file   kern/kern_condvar.c
 file   kern/kern_core.c                coredump
 file   kern/kern_cpu.c
+file   kern/kern_cpu_ucode.c           cpu_ucode
 file   kern/kern_ctf.c                 kdtrace_hooks
 file   kern/kern_descrip.c
 file   kern/kern_event.c
Index: ./sys/kern/kern_cpu.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_cpu.c,v
retrieving revision 1.53
diff -u -p -r1.53 kern_cpu.c
--- ./sys/kern/kern_cpu.c       13 Jan 2012 16:05:15 -0000      1.53
+++ ./sys/kern/kern_cpu.c       14 Jan 2012 04:10:14 -0000
@@ -58,8 +58,6 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.53 2012/01/13 16:05:15 cegger Exp 
$");
 
-#include "opt_cpu_ucode.h"
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/idle.h>
@@ -247,28 +245,8 @@ cpuctl_ioctl(dev_t dev, u_long cmd, void
                *(int *)data = ncpu;
                break;
 
-#ifdef CPU_UCODE
-       case IOC_CPU_UCODE_GET_VERSION:
-               error = cpu_ucode_get_version(data);
-               break;
-
-       case IOC_CPU_UCODE_APPLY:
-               error = kauth_authorize_machdep(l->l_cred,
-                   KAUTH_MACHDEP_CPU_UCODE_APPLY,
-                   NULL, NULL, NULL, NULL);
-               if (error != 0)
-                       break;
-               error = kauth_authorize_system(l->l_cred,
-                   KAUTH_SYSTEM_CPU, KAUTH_REQ_SYSTEM_CPU_UCODE_APPLY,
-                   data, NULL, NULL);
-               if (error != 0)
-                       break;
-               error = cpu_ucode_apply(data);
-               break;
-#endif
-
        default:
-               error = ENOTTY;
+               error = cpuctl_ucode_ioctl(dev, cmd, data, flag, l);
                break;
        }
        mutex_exit(&cpu_lock);
@@ -529,46 +507,3 @@ cpu_softintr_p(void)
 
        return (curlwp->l_pflag & LP_INTR) != 0;
 }
-
-#ifdef CPU_UCODE
-int
-cpu_ucode_load(struct cpu_ucode_softc *sc, const char *fwname)
-{
-       firmware_handle_t fwh;
-       int error;
-
-       if (sc->sc_blob != NULL) {
-               firmware_free(sc->sc_blob, 0);
-               sc->sc_blob = NULL;
-               sc->sc_blobsize = 0;
-       }
-
-       error = cpu_ucode_md_open(&fwh, fwname);
-       if (error != 0) {
-               aprint_error("ucode: firmware_open failed: %i\n", error);
-               goto err0;
-       }
-
-       sc->sc_blobsize = firmware_get_size(fwh);
-       sc->sc_blob = firmware_malloc(sc->sc_blobsize);
-       if (sc->sc_blob == NULL) {
-               error = ENOMEM;
-               firmware_close(fwh);
-               goto err0;
-       }
-
-       error = firmware_read(fwh, 0, sc->sc_blob, sc->sc_blobsize);
-       firmware_close(fwh);
-       if (error != 0)
-               goto err1;
-
-       return 0;
-
-err1:
-       firmware_free(sc->sc_blob, 0);
-       sc->sc_blob = NULL;
-       sc->sc_blobsize = 0;
-err0:
-       return error;
-}
-#endif
Index: ./sys/kern/kern_stub.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_stub.c,v
retrieving revision 1.36
diff -u -p -r1.36 kern_stub.c
--- ./sys/kern/kern_stub.c      31 Aug 2011 20:09:57 -0000      1.36
+++ ./sys/kern/kern_stub.c      14 Jan 2012 04:10:14 -0000
@@ -124,31 +124,39 @@ __weak_alias(ktruser,enosys);
 __weak_alias(ktr_point,nullop);
 #endif /* KTRACE */
 
-__weak_alias(device_register, voidop);
-__weak_alias(device_register_post_config, voidop);
-__weak_alias(spldebug_start, voidop);
-__weak_alias(spldebug_stop, voidop);
-__weak_alias(machdep_init,nullop);
-__weak_alias(pci_chipset_tag_create, eopnotsupp);
-__weak_alias(pci_chipset_tag_destroy, voidop);
+__weak_alias(bus_dma_tag_create, eopnotsupp);
+__weak_alias(bus_dma_tag_destroy, voidop);
+
 __weak_alias(bus_space_reserve, eopnotsupp);
 __weak_alias(bus_space_reserve_subregion, eopnotsupp);
 __weak_alias(bus_space_release, voidop);
 __weak_alias(bus_space_reservation_map, eopnotsupp);
 __weak_alias(bus_space_reservation_unmap, voidop);
-__weak_alias(bus_dma_tag_create, eopnotsupp);
-__weak_alias(bus_dma_tag_destroy, voidop);
 __weak_alias(bus_space_tag_create, eopnotsupp);
 __weak_alias(bus_space_tag_destroy, voidop);
 __strict_weak_alias(bus_space_is_equal, default_bus_space_is_equal);
 __strict_weak_alias(bus_space_handle_is_equal,
     default_bus_space_handle_is_equal);
+
+__weak_alias(cpuctl_ucode_ioctl, enoioctl);
+
+__weak_alias(device_register, voidop);
+__weak_alias(device_register_post_config, voidop);
+
+__weak_alias(kobj_renamespace, nullop);
+
+__weak_alias(machdep_init,nullop);
+
+__weak_alias(pci_chipset_tag_create, eopnotsupp);
+__weak_alias(pci_chipset_tag_destroy, voidop);
+
+__weak_alias(spldebug_start, voidop);
+__weak_alias(spldebug_stop, voidop);
+
 __weak_alias(userconf_bootinfo, voidop);
 __weak_alias(userconf_init, voidop);
 __weak_alias(userconf_prompt, voidop);
 
-__weak_alias(kobj_renamespace, nullop);
-
 #if !defined(KERN_SA)
 /*
  * Scheduler activations system calls.  These need to remain, even when
Index: ./sys/kern/kern_cpu_ucode.c
===================================================================
RCS file: ./sys/kern/kern_cpu_ucode.c
diff -N ./sys/kern/kern_cpu_ucode.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ ./sys/kern/kern_cpu_ucode.c 14 Jan 2012 04:10:14 -0000
@@ -0,0 +1,125 @@
+/*     $NetBSD$        */
+
+/*-
+ * Copyright (c) 2007, 2008, 2009, 2010, 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christoph Egger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/idle.h>
+#include <sys/sched.h>
+#include <sys/intr.h>
+#include <sys/conf.h>
+#include <sys/cpu.h>
+#include <sys/cpuio.h>
+#include <sys/proc.h>
+#include <sys/percpu.h>
+#include <sys/kernel.h>
+#include <sys/kauth.h>
+#include <sys/xcall.h>
+#include <sys/pool.h>
+#include <sys/kmem.h>
+#include <sys/select.h>
+#include <sys/namei.h>
+#include <sys/callout.h>
+
+#include <uvm/uvm_extern.h>
+
+int
+cpuctl_ucode_ioctl(dev_t dev __unused, u_long cmd, void *data,
+    int flag __unused, lwp_t *l)
+{
+       int error;
+
+       switch (cmd) {
+       case IOC_CPU_UCODE_GET_VERSION:
+               error = cpu_ucode_get_version(data);
+               break;
+
+       case IOC_CPU_UCODE_APPLY:
+               error = kauth_authorize_machdep(l->l_cred,
+                   KAUTH_MACHDEP_CPU_UCODE_APPLY,
+                   NULL, NULL, NULL, NULL);
+               if (error != 0)
+                       break;
+               error = kauth_authorize_system(l->l_cred,
+                   KAUTH_SYSTEM_CPU, KAUTH_REQ_SYSTEM_CPU_UCODE_APPLY,
+                   data, NULL, NULL);
+               if (error != 0)
+                       break;
+               error = cpu_ucode_apply(data);
+               break;
+       default:
+               error = ENOTTY;
+               break;
+       }
+       return error;
+}
+
+int
+cpu_ucode_load(struct cpu_ucode_softc *sc, const char *fwname)
+{
+       firmware_handle_t fwh;
+       int error;
+
+       if (sc->sc_blob != NULL) {
+               firmware_free(sc->sc_blob, 0);
+               sc->sc_blob = NULL;
+               sc->sc_blobsize = 0;
+       }
+
+       error = cpu_ucode_md_open(&fwh, fwname);
+       if (error != 0) {
+               aprint_error("ucode: firmware_open failed: %i\n", error);
+               goto err0;
+       }
+
+       sc->sc_blobsize = firmware_get_size(fwh);
+       sc->sc_blob = firmware_malloc(sc->sc_blobsize);
+       if (sc->sc_blob == NULL) {
+               error = ENOMEM;
+               firmware_close(fwh);
+               goto err0;
+       }
+
+       error = firmware_read(fwh, 0, sc->sc_blob, sc->sc_blobsize);
+       firmware_close(fwh);
+       if (error != 0)
+               goto err1;
+
+       return 0;
+
+err1:
+       firmware_free(sc->sc_blob, 0);
+       sc->sc_blob = NULL;
+       sc->sc_blobsize = 0;
+err0:
+       return error;
+}
Index: ./sys/sys/cpu.h
===================================================================
RCS file: /cvsroot/src/sys/sys/cpu.h,v
retrieving revision 1.34
diff -u -p -r1.34 cpu.h
--- ./sys/sys/cpu.h     13 Jan 2012 16:05:16 -0000      1.34
+++ ./sys/sys/cpu.h     14 Jan 2012 04:10:14 -0000
@@ -42,9 +42,7 @@ struct cpu_info;
 void cpu_idle(void);
 #endif
 
-#ifdef CPU_UCODE
 #include <dev/firmload.h>
-#endif
 
 /*
  * cpu_need_resched() must always be called with the target CPU
@@ -107,7 +105,6 @@ cpu_name(struct cpu_info *ci)
        return ci->ci_data.cpu_name;
 }
 
-#ifdef CPU_UCODE
 struct cpu_ucode_softc {
        char *sc_blob;
        off_t sc_blobsize;
@@ -115,9 +112,9 @@ struct cpu_ucode_softc {
 
 int cpu_ucode_get_version(void *);
 int cpu_ucode_apply(void *);
+int cpuctl_ucode_ioctl(dev_t, u_long, void *, int, lwp_t *);
 int cpu_ucode_load(struct cpu_ucode_softc *, const char *);
 int cpu_ucode_md_open(firmware_handle_t *, const char *);
-#endif
 
 #endif
 #endif /* !_LOCORE */


Home | Main Index | Thread Index | Old Index