From owner-svn-src-head@freebsd.org Tue Jul 24 16:52:53 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7EF7E1050A4E; Tue, 24 Jul 2018 16:52:53 +0000 (UTC) (envelope-from leitao@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2EF4776FF1; Tue, 24 Jul 2018 16:52:53 +0000 (UTC) (envelope-from leitao@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA13D6551; Tue, 24 Jul 2018 16:52:52 +0000 (UTC) (envelope-from leitao@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6OGqq6d044519; Tue, 24 Jul 2018 16:52:52 GMT (envelope-from leitao@FreeBSD.org) Received: (from leitao@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6OGqqxo044518; Tue, 24 Jul 2018 16:52:52 GMT (envelope-from leitao@FreeBSD.org) Message-Id: <201807241652.w6OGqqxo044518@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: leitao set sender to leitao@FreeBSD.org using -f From: Breno Leitao Date: Tue, 24 Jul 2018 16:52:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336678 - in head/sys: conf powerpc/ofw X-SVN-Group: head X-SVN-Commit-Author: leitao X-SVN-Commit-Paths: in head/sys: conf powerpc/ofw X-SVN-Commit-Revision: 336678 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jul 2018 16:52:53 -0000 Author: leitao Date: Tue Jul 24 16:52:52 2018 New Revision: 336678 URL: https://svnweb.freebsd.org/changeset/base/336678 Log: ofw: Load initrd file This is an OFW initrd module that would load the initrd from device tree parameters and give the to the md driver. With this patch, it is possible to pass a rootfs image through kexec in PowerNV mode (powerpc64). In order to user it, you should set the MD_ROOT_MEM option in your kernel configuration. Reviewed by: jhibbits Approved by: jhibbits (mentor) Differential Revision: https://reviews.freebsd.org/D15705 Added: head/sys/powerpc/ofw/ofw_initrd.c (contents, props changed) Modified: head/sys/conf/files.powerpc Modified: head/sys/conf/files.powerpc ============================================================================== --- head/sys/conf/files.powerpc Tue Jul 24 16:45:01 2018 (r336677) +++ head/sys/conf/files.powerpc Tue Jul 24 16:52:52 2018 (r336678) @@ -163,6 +163,7 @@ powerpc/ofw/ofwcall32.S optional aim powerpc powerpc/ofw/ofwcall64.S optional aim powerpc64 powerpc/ofw/openpic_ofw.c standard powerpc/ofw/rtas.c optional aim +powerpc/ofw/ofw_initrd.c optional md_root_mem powerpc64 powerpc/powermac/ata_kauai.c optional powermac ata | powermac atamacio powerpc/powermac/ata_macio.c optional powermac ata | powermac atamacio powerpc/powermac/ata_dbdma.c optional powermac ata | powermac atamacio Added: head/sys/powerpc/ofw/ofw_initrd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/powerpc/ofw/ofw_initrd.c Tue Jul 24 16:52:52 2018 (r336678) @@ -0,0 +1,159 @@ +/*- + * Copyright (C) 2018 Breno Leitao + * + * 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 AUTHOR ``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 TOOLS GMBH 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include "opt_md.h" + +#ifdef MD_ROOT_MEM +extern u_char *mfs_root; +extern uint32_t mfs_root_size; +#else +#warning "MD_ROOT_MEM should be set to use ofw initrd as a md device" +#endif + +/* bus entry points */ +static int ofw_initrd_probe(device_t dev); +static int ofw_initrd_attach(device_t dev); +static void ofw_initrd_identify(driver_t *driver, device_t parent); + +struct ofw_initrd_softc { + device_t sc_dev; + vm_paddr_t start; + vm_paddr_t end; +}; + +static int +ofw_initrd_probe(device_t dev) +{ + phandle_t chosen; + + /* limit this device to one unit */ + if (device_get_unit(dev) != 0) + return (ENXIO); + + chosen = OF_finddevice("/chosen"); + if (chosen <= 0) { + return (ENXIO); + } + + if (!OF_hasprop(chosen, "linux,initrd-start") || + !OF_hasprop(chosen, "linux,initrd-end")) + return (ENXIO); + + device_set_desc(dev, "OFW initrd memregion loader"); + return (BUS_PROBE_DEFAULT); +} + +static int +ofw_initrd_attach(device_t dev) +{ + struct ofw_initrd_softc *sc; + vm_paddr_t start, end; + phandle_t chosen; + pcell_t cell[2]; + ssize_t size; + + sc = device_get_softc(dev); + + chosen = OF_finddevice("/chosen"); + if (chosen <= 0) { + device_printf(dev, "/chosen not found\n"); + return (ENXIO); + } + + size = OF_getencprop(chosen, "linux,initrd-start", cell, sizeof(cell)); + if (size == 4) + start = cell[0]; + else if (size == 8) + start = (uint64_t)cell[0] << 32 | cell[1]; + else { + device_printf(dev, "Wrong linux,initrd-start size\n"); + return (ENXIO); + } + + size = OF_getencprop(chosen, "linux,initrd-end", cell, sizeof(cell)); + if (size == 4) + end = cell[0]; + else if (size == 8) + end = (uint64_t)cell[0] << 32 | cell[1]; + else{ + device_printf(dev, "Wrong linux,initrd-end size\n"); + return (ENXIO); + } + + if (end - start > 0) { + mfs_root = (u_char *) PHYS_TO_DMAP(start); + mfs_root_size = end - start; + + return (0); + } + + return (ENXIO); +} + +static void +ofw_initrd_identify(driver_t *driver, device_t parent) +{ + if (device_find_child(parent, "initrd", -1) != NULL) + return; + + if (BUS_ADD_CHILD(parent, 10, "initrd", -1) == NULL) + device_printf(parent, "add ofw_initrd child failed\n"); +} + +static device_method_t ofw_initrd_methods[] = { + DEVMETHOD(device_identify, ofw_initrd_identify), + DEVMETHOD(device_probe, ofw_initrd_probe), + DEVMETHOD(device_attach, ofw_initrd_attach), + DEVMETHOD_END +}; + +static driver_t ofw_initrd_driver = { + "ofw_initrd", + ofw_initrd_methods, + sizeof(struct ofw_initrd_softc) +}; + +static devclass_t ofw_initrd_devclass; + +DRIVER_MODULE(ofw_initrd, ofwbus, ofw_initrd_driver, ofw_initrd_devclass, + NULL, NULL);