/*-1* Copyright (C) 2015 Nathan Whitehorn2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,17* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,18* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;19* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,20* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR21* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF22* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425#include <dev/ofw/openfirm.h>2627#include "opal.h"2829extern uint64_t opal_entrypoint;30extern uint64_t opal_data;31extern uint64_t opal_msr;3233static int opal_initialized = 0;3435int36opal_check(void)37{38phandle_t opal;39cell_t val[2];4041if (opal_initialized)42return (0);4344opal = OF_finddevice("/ibm,opal");45if (opal == -1)46return (ENOENT);4748if (!OF_hasprop(opal, "opal-base-address") ||49!OF_hasprop(opal, "opal-entry-address"))50return (ENOENT);5152OF_getencprop(opal, "opal-base-address", val, sizeof(val));53opal_data = ((uint64_t)val[0] << 32) | val[1];54OF_getencprop(opal, "opal-entry-address", val, sizeof(val));55opal_entrypoint = ((uint64_t)val[0] << 32) | val[1];5657opal_msr = mfmsr() & ~(PSL_EE | PSL_IR | PSL_DR | PSL_SE | PSL_LE);5859opal_initialized = 1;6061return (0);62}636465