/* * yosys -- Yosys Open SYnthesis Suite * * Copyright (C) 2012 Clifford Wolf * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ /* No clearbox model */ `ifdef NO_CLEARBOX (* blackbox *) module altpll ( inclk, fbin, pllena, clkswitch, areset, pfdena, clkena, extclkena, scanclk, scanaclr, scanclkena, scanread, scanwrite, scandata, phasecounterselect, phaseupdown, phasestep, configupdate, fbmimicbidir, clk, extclk, clkbad, enable0, enable1, activeclock, clkloss, locked, scandataout, scandone, sclkout0, sclkout1, phasedone, vcooverrange, vcounderrange, fbout, fref, icdrclk, c0, c1, c2, c3, c4); parameter intended_device_family = "MAX 10"; parameter operation_mode = "NORMAL"; parameter pll_type = "AUTO"; parameter qualify_conf_done = "OFF"; parameter compensate_clock = "CLK0"; parameter scan_chain = "LONG"; parameter primary_clock = "inclk0"; parameter inclk0_input_frequency = 1000; parameter inclk1_input_frequency = 0; parameter gate_lock_signal = "NO"; parameter gate_lock_counter = 0; parameter lock_high = 1; parameter lock_low = 0; parameter valid_lock_multiplier = 1; parameter invalid_lock_multiplier = 5; parameter switch_over_type = "AUTO"; parameter switch_over_on_lossclk = "OFF" ; parameter switch_over_on_gated_lock = "OFF" ; parameter enable_switch_over_counter = "OFF"; parameter switch_over_counter = 0; parameter feedback_source = "EXTCLK0" ; parameter bandwidth = 0; parameter bandwidth_type = "UNUSED"; parameter lpm_hint = "UNUSED"; parameter spread_frequency = 0; parameter down_spread = "0.0"; parameter self_reset_on_gated_loss_lock = "OFF"; parameter self_reset_on_loss_lock = "OFF"; parameter lock_window_ui = "0.05"; parameter width_clock = 6; parameter width_phasecounterselect = 4; parameter charge_pump_current_bits = 9999; parameter loop_filter_c_bits = 9999; parameter loop_filter_r_bits = 9999; parameter scan_chain_mif_file = "UNUSED"; parameter clk9_multiply_by = 1; parameter clk8_multiply_by = 1; parameter clk7_multiply_by = 1; parameter clk6_multiply_by = 1; parameter clk5_multiply_by = 1; parameter clk4_multiply_by = 1; parameter clk3_multiply_by = 1; parameter clk2_multiply_by = 1; parameter clk1_multiply_by = 1; parameter clk0_multiply_by = 1; parameter clk9_divide_by = 1; parameter clk8_divide_by = 1; parameter clk7_divide_by = 1; parameter clk6_divide_by = 1; parameter clk5_divide_by = 1; parameter clk4_divide_by = 1; parameter clk3_divide_by = 1; parameter clk2_divide_by = 1; parameter clk1_divide_by = 1; parameter clk0_divide_by = 1; parameter clk9_phase_shift = "0"; parameter clk8_phase_shift = "0"; parameter clk7_phase_shift = "0"; parameter clk6_phase_shift = "0"; parameter clk5_phase_shift = "0"; parameter clk4_phase_shift = "0"; parameter clk3_phase_shift = "0"; parameter clk2_phase_shift = "0"; parameter clk1_phase_shift = "0"; parameter clk0_phase_shift = "0"; parameter clk9_duty_cycle = 50; parameter clk8_duty_cycle = 50; parameter clk7_duty_cycle = 50; parameter clk6_duty_cycle = 50; parameter clk5_duty_cycle = 50; parameter clk4_duty_cycle = 50; parameter clk3_duty_cycle = 50; parameter clk2_duty_cycle = 50; parameter clk1_duty_cycle = 50; parameter clk0_duty_cycle = 50; parameter clk9_use_even_counter_mode = "OFF"; parameter clk8_use_even_counter_mode = "OFF"; parameter clk7_use_even_counter_mode = "OFF"; parameter clk6_use_even_counter_mode = "OFF"; parameter clk5_use_even_counter_mode = "OFF"; parameter clk4_use_even_counter_mode = "OFF"; parameter clk3_use_even_counter_mode = "OFF"; parameter clk2_use_even_counter_mode = "OFF"; parameter clk1_use_even_counter_mode = "OFF"; parameter clk0_use_even_counter_mode = "OFF"; parameter clk9_use_even_counter_value = "OFF"; parameter clk8_use_even_counter_value = "OFF"; parameter clk7_use_even_counter_value = "OFF"; parameter clk6_use_even_counter_value = "OFF"; parameter clk5_use_even_counter_value = "OFF"; parameter clk4_use_even_counter_value = "OFF"; parameter clk3_use_even_counter_value = "OFF"; parameter clk2_use_even_counter_value = "OFF"; parameter clk1_use_even_co
//
// Copyright 2019, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * 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.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
// OWNER 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.
//
// Alternatively, this software may be distributed under the terms of the
// GNU General Public License ("GPL") version 2 as published by the Free
// Software Foundation.
//

use std::ffi::OsStr;
use std::fmt::Debug;
use std::io::Result as IoResult;
use std::process::{Command, Stdio};

use super::utils;

fn dmidecode_dispatch<S: AsRef<OsStr>>(args: &[S]) -> IoResult<String> {
    let output = Command::new("/usr/sbin/dmidecode")
        .args(args)
        .stdin(Stdio::null())
        .output()?;

    if !output.status.success() {
        return Err(utils::translate_command_error(&output));
    }
    Ok(String::from_utf8_lossy(&output.stdout).into_owned())
}

pub fn system_info() -> IoResult<String> {
    dmidecode_dispatch(&["-q", "-t1"])
}

pub fn bios_info() -> IoResult<String> {
    dmidecode_dispatch(&["-q", "-t0"])
}

pub fn eventlog_list() -> Result<String, std::io::Error> {
    elogtool_dispatch(&["list"])
}

fn elogtool_dispatch<S: AsRef<OsStr> + Debug>(args: &[S]) -> IoResult<String> {
    info!("elogtool_dispatch() running: /usr/bin/elogtool {:?}", args);

    let output = Command::new("/usr/bin/elogtool")
        .args(args)
        .stdin(Stdio::null())
        .output()?;
    if !output.status.success() {
        return Err(utils::translate_command_error(&output));
    }

    let stdout = String::from_utf8_lossy(&output.stdout).into_owned();
    Ok(stdout)
}