diff options
author | Tian Fang <tfang@fb.com> | 2015-03-09 22:53:57 -0700 |
---|---|---|
committer | Tian Fang <tfang@fb.com> | 2015-03-09 22:53:57 -0700 |
commit | 2a51b7c1c2165ddb188c511e192b75f0aa0fbead (patch) | |
tree | bb42aeac00a8b986c325cd70d5cca6c13bc0c23a /meta-facebook/meta-wedge/recipes-wedge/fblibs | |
download | ast2050-yocto-openbmc-2a51b7c1c2165ddb188c511e192b75f0aa0fbead.zip ast2050-yocto-openbmc-2a51b7c1c2165ddb188c511e192b75f0aa0fbead.tar.gz |
Initial open source release of OpenBMC
Diffstat (limited to 'meta-facebook/meta-wedge/recipes-wedge/fblibs')
8 files changed, 368 insertions, 0 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile new file mode 100644 index 0000000..74ce8f3 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile @@ -0,0 +1,11 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +lib: libalert_control.so + +libalert_control.so: alert_control.c + $(CC) $(CCFLAGS) -fPIC -c -o alert_control.o alert_control.c + $(CC) -shared -o libalert_control.so alert_control.o -lc + +.PHONY: clean + +clean: + rm -rf *.o libalert_control.so diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c new file mode 100644 index 0000000..81b0329 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c @@ -0,0 +1,117 @@ +/* + * + * Copyright 2014-present Facebook. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <syslog.h> +#include "alert_control.h" + +#define PATH_ALERT_STATUS "/sys/bus/i2c/drivers/panther_plus/4-0040/alert_status" +#define PATH_ALERT_CONTROL "/sys/bus/i2c/drivers/panther_plus/4-0040/alert_control" + +#define MASK_ALERT_SMS_KCS 0x01 + +/* + * Function to enable/disable alert signal generation for a given Function Block + */ +int +alert_control(e_fbid_t id, e_flag_t cflag) { + FILE *fp; + unsigned char rbuf[5] = {0}; + unsigned char tbuf[3] = {0}; + int count = 0; + + fp = fopen(PATH_ALERT_CONTROL, "r+"); + if (!fp) { + return -1; + } + + count = fread(rbuf, sizeof(unsigned char), sizeof(rbuf), fp); + if (count == 0x0) { + fclose(fp); + return -1; + } + + // Size of the request + tbuf[0] = 0x02; + + switch(id) { + case FBID_SMS_KCS: + if (cflag == FLAG_ENABLE) + tbuf[1] = rbuf[2] | (0x01 << FBID_SMS_KCS); + else + tbuf[1] = rbuf[2] & (~(0x01 << FBID_SMS_KCS)); + + tbuf[2] = rbuf[3]; + break; + // TODO: Add logic for other Function Blocks here + default: + tbuf[0] = rbuf[2]; + tbuf[1] = rbuf[3]; + break; + } + + count = fwrite(tbuf, sizeof(unsigned char), sizeof(tbuf), fp); + if (count != sizeof(tbuf)) { + fclose(fp); + return (-1); + } + + fclose(fp); + + return 0; +} + +/* + * Function to check if the alert for a given Function Block is asserted or not + */ +bool +is_alert_present(e_fbid_t id) { + FILE *fp; + unsigned char buf[5] = {0}; + int count = 0; + + fp = fopen(PATH_ALERT_STATUS, "r"); + + if (!fp) { + return false; + } + + count = fread(buf, sizeof(unsigned char), sizeof(buf), fp); + if (count == 0x0) { + fclose(fp); + sleep(2); + return false; + } + + fclose(fp); + + switch(id) { + case FBID_SMS_KCS: + if (buf[2] & (0x01 << FBID_SMS_KCS)) + return true; + else + return false; + //TODO: Add logic for other Function Blocks here + default: + return false; + } +} diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h new file mode 100644 index 0000000..ca72591 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h @@ -0,0 +1,64 @@ +/* + * + * Copyright 2014-present Facebook. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __ALERT_CONTROL_H__ +#define __ALERT_CONTROL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdbool.h> + +typedef enum { + FLAG_DISABLE = 0x00, + FLAG_ENABLE, +} e_flag_t; + +typedef enum { + FBID_SMS_KCS = 0x00, + FBID_SMM_KCS, + FBID_COM1_DATA, + FBID_COM2_DATA, + FBID_COM1_STAT_CTRL, + FBID_COM2_STAT_CTRL, + FBID_POST, + FBID_I2C_PROXY1_MASTER, + FBID_I2C_PROXY1_STAT, + FBID_I2C_PROXY2_MASTER, + FBID_I2C_PROXY2_STAT, + FBID_GPIO_CONFIG, + FBID_GPIO_OUTPUT, + FBID_GPIO_INPUT, + FBID_GPIO_INTR, + FBID_GPIO_EVENT, + FBID_REG_READ, + FBID_ALERT_CTRL = 0xFD, + FBID_AERT_STAT = 0xFE, + FBID_DISCOVERY = 0xFF, +} e_fbid_t; + +int alert_control(e_fbid_t id, e_flag_t cflag); +bool is_alert_present(e_fbid_t id); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* __ALERT_CONTROL_H__ */ diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile new file mode 100644 index 0000000..8cb69e7 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile @@ -0,0 +1,11 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +lib: libipmi.so + +libipmi.so: ipmi.c + $(CC) $(CCFLAGS) -fPIC -c -o ipmi.o ipmi.c + $(CC) -shared -o libipmi.so ipmi.o -lc + +.PHONY: clean + +clean: + rm -rf *.o libipmi.so diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c new file mode 100644 index 0000000..b5a3e19 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c @@ -0,0 +1,81 @@ +/* + * + * Copyright 2014-present Facebook. All Rights Reserved. + * + * This file contains code to support IPMI2.0 Specificaton available @ + * http://www.intel.com/content/www/us/en/servers/ipmi/ipmi-specifications.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "ipmi.h" +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <syslog.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> + +#define SOCK_PATH "/tmp/ipmi_socket" +#define MAX_IPMI_RES_LEN 100 + +/* + * Function to handle IPMI messages + */ +void +ipmi_handle(unsigned char *request, unsigned char req_len, + unsigned char *response, unsigned char *res_len) { + + int s, t, len; + struct sockaddr_un remote; + + // TODO: Need to update to reuse the socket instead of creating new + if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + syslog(LOG_ALERT, "ipmi_handle: socket() failed\n"); + return; + } + + remote.sun_family = AF_UNIX; + strcpy(remote.sun_path, SOCK_PATH); + len = strlen(remote.sun_path) + sizeof(remote.sun_family); + + if (connect(s, (struct sockaddr *)&remote, len) == -1) { + syslog(LOG_ALERT, "ipmi_handle: connect() failed\n"); + return; + } + + if (send(s, request, req_len, 0) == -1) { + syslog(LOG_ALERT, "ipmi_handle: send() failed\n"); + return; + } + + if ((t=recv(s, response, MAX_IPMI_RES_LEN, 0)) > 0) { + *res_len = t; + } else { + if (t < 0) { + syslog(LOG_ALERT, "ipmi_handle: recv() failed\n"); + } else { + printf("Server closed connection"); + } + + return; + } + + close(s); + + return; +} diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h new file mode 100644 index 0000000..4c6ed62 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h @@ -0,0 +1,35 @@ +/* + * + * Copyright 2014-present Facebook. All Rights Reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __IPMI_H__ +#define __IPMI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void ipmi_handle(unsigned char *request, unsigned char req_len, + unsigned char *response, unsigned char *res_len); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* __IPMI_H__ */ diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/libalert-control_0.1.bb b/meta-facebook/meta-wedge/recipes-wedge/fblibs/libalert-control_0.1.bb new file mode 100644 index 0000000..2ae4ea7 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/libalert-control_0.1.bb @@ -0,0 +1,24 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +SUMMARY = "Wedge Alert Control Library" +DESCRIPTION = "library for Wedge Alert Control" +SECTION = "base" +PR = "r1" +LICENSE = "GPLv2" +LIC_FILES_CHKSUM = "file://alert_control.c;beginline=5;endline=17;md5=da35978751a9d71b73679307c4d296ec" + +SRC_URI = "file://alert_control \ + " + +S = "${WORKDIR}/alert_control" + +do_install() { + install -d ${D}${libdir} + install -m 0644 libalert_control.so ${D}${libdir}/libalert_control.so + + install -d ${D}${includedir}/facebook + install -m 0644 alert_control.h ${D}${includedir}/facebook/alert_control.h +} + +FILES_${PN} = "${libdir}/libalert_control.so" +FILES_${PN}-dbg = "${libdir}/.debug" +FILES_${PN}-dev = "${includedir}/facebook/alert_control.h" diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/libipmi_0.1.bb b/meta-facebook/meta-wedge/recipes-wedge/fblibs/libipmi_0.1.bb new file mode 100644 index 0000000..0b6f3d3 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/libipmi_0.1.bb @@ -0,0 +1,25 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +SUMMARY = "Wedge IPMI Client Library" +DESCRIPTION = "library for Wedge IPMI Client" +SECTION = "base" +PR = "r1" +LICENSE = "GPLv2" +LIC_FILES_CHKSUM = "file://ipmi.c;beginline=8;endline=20;md5=da35978751a9d71b73679307c4d296ec" + + +SRC_URI = "file://ipmi \ + " + +S = "${WORKDIR}/ipmi" + +do_install() { + install -d ${D}${libdir} + install -m 0644 libipmi.so ${D}${libdir}/libipmi.so + + install -d ${D}${includedir}/facebook + install -m 0644 ipmi.h ${D}${includedir}/facebook/ipmi.h +} + +FILES_${PN} = "${libdir}/libipmi.so" +FILES_${PN}-dbg = "${libdir}/.debug" +FILES_${PN}-dev = "${includedir}/facebook/ipmi.h" |