librtas-devel Mailing List for librtas (Page 2)
Brought to you by:
nfont
You can subscribe to this list here.
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
2014 |
Jan
|
Feb
(2) |
Mar
(10) |
Apr
|
May
(10) |
Jun
(9) |
Jul
(14) |
Aug
(15) |
Sep
|
Oct
(12) |
Nov
(1) |
Dec
|
2015 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
(13) |
Jun
|
Jul
(4) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
(3) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Vasant H. <heg...@li...> - 2015-01-08 05:40:58
|
On 01/08/2015 12:58 AM, Nathan Fontenot wrote: > On 10/22/2014 03:45 AM, Vasant Hegde wrote: >> On 10/21/2014 10:10 PM, Nathan Fontenot wrote: >>> In anticipation of pushing out a new release of librtas that will >>> be released under the GPL license I am putting out a set of patches >> >> I assume you will release this under LGPL. >> > > Yes, I plan to pull all of these patches into the first GPL release. Cool.. Once u release GPL version I will change ppc64-diag license as well. -Vasant |
From: Nathan F. <nf...@li...> - 2015-01-07 19:35:35
|
Added to -next tree. Thanks, -Nathan On 11/11/2014 01:25 PM, Tyrel Datwyler wrote: > PAPR requires that the status word is the first parameter in the return > buffer for rtas calls. Due to this requirement the librtas sc_rtas_call > function always performs a be32toh operation on the first parameter in the > return buffer. However, the ibm,open-errinjct rtas is special in that its > return buffer is switched. The "Open Token" is the first return parameter > while the "Status" word is second. > > This patch fixes this special case in the sc_errinjct_open function such > that the byteswapping of "status" and "otoken" are handled correctly. > > Signed-off-by: Tyrel Datwyler <ty...@li...> > --- > librtas_src/syscall_calls.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c > index dc52370..a81c25c 100644 > --- a/librtas_src/syscall_calls.c > +++ b/librtas_src/syscall_calls.c > @@ -493,20 +493,20 @@ int sc_errinjct_close(int token, int otoken) > int sc_errinjct_open(int token, int *otoken) > { > uint64_t elapsed = 0; > - __be32 be_otoken; > + __be32 be_status; > int status; > int rc; > > do { > - rc = sc_rtas_call(token, 0, 2, &be_otoken, &status); > + rc = sc_rtas_call(token, 0, 2, otoken, &be_status); > if (rc) > return rc; > > + status = be32toh(be_status); > + > rc = handle_delay(status, &elapsed); > } while (rc == CALL_AGAIN); > > - *otoken = be32toh(be_otoken); > - > dbg1("(%p) = %d, %d\n", otoken, rc ? rc : status, *otoken); > return rc ? rc : status; > } > |
From: Nathan F. <nf...@li...> - 2015-01-07 19:28:50
|
On 10/22/2014 03:45 AM, Vasant Hegde wrote: > On 10/21/2014 10:10 PM, Nathan Fontenot wrote: >> In anticipation of pushing out a new release of librtas that will >> be released under the GPL license I am putting out a set of patches > > I assume you will release this under LGPL. > Yes, I plan to pull all of these patches into the first GPL release. -Nathan > -Vasant > >> that do some cleanup for the release. >> >> This set of patches is not really connected in any way other than >> putting a new release (likely v2.0) is a good chance to make some >> of these changes. These patches do a lot of cleanup to the code >> and remove the libofdt library from the package. >> >> This set of patches is done on top of Thomas Falcon's patches >> for removing the proc interface for librtas. >> >> -Nathan >> >> >> ------------------------------------------------------------------------------ >> Comprehensive Server Monitoring with Site24x7. >> Monitor 10 servers for $9/Month. >> Get alerted through email, SMS, voice calls or mobile push notifications. >> Take corrective actions from your mobile device. >> http://p.sf.net/sfu/Zoho >> _______________________________________________ >> Librtas-devel mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/librtas-devel >> > |
From: Tyrel D. <ty...@li...> - 2014-11-11 19:25:42
|
PAPR requires that the status word is the first parameter in the return buffer for rtas calls. Due to this requirement the librtas sc_rtas_call function always performs a be32toh operation on the first parameter in the return buffer. However, the ibm,open-errinjct rtas is special in that its return buffer is switched. The "Open Token" is the first return parameter while the "Status" word is second. This patch fixes this special case in the sc_errinjct_open function such that the byteswapping of "status" and "otoken" are handled correctly. Signed-off-by: Tyrel Datwyler <ty...@li...> --- librtas_src/syscall_calls.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index dc52370..a81c25c 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -493,20 +493,20 @@ int sc_errinjct_close(int token, int otoken) int sc_errinjct_open(int token, int *otoken) { uint64_t elapsed = 0; - __be32 be_otoken; + __be32 be_status; int status; int rc; do { - rc = sc_rtas_call(token, 0, 2, &be_otoken, &status); + rc = sc_rtas_call(token, 0, 2, otoken, &be_status); if (rc) return rc; + status = be32toh(be_status); + rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - *otoken = be32toh(be_otoken); - dbg1("(%p) = %d, %d\n", otoken, rc ? rc : status, *otoken); return rc ? rc : status; } -- 1.9.3 |
From: Vasant H. <heg...@li...> - 2014-10-22 08:45:45
|
On 10/21/2014 10:10 PM, Nathan Fontenot wrote: > In anticipation of pushing out a new release of librtas that will > be released under the GPL license I am putting out a set of patches I assume you will release this under LGPL. -Vasant > that do some cleanup for the release. > > This set of patches is not really connected in any way other than > putting a new release (likely v2.0) is a good chance to make some > of these changes. These patches do a lot of cleanup to the code > and remove the libofdt library from the package. > > This set of patches is done on top of Thomas Falcon's patches > for removing the proc interface for librtas. > > -Nathan > > > ------------------------------------------------------------------------------ > Comprehensive Server Monitoring with Site24x7. > Monitor 10 servers for $9/Month. > Get alerted through email, SMS, voice calls or mobile push notifications. > Take corrective actions from your mobile device. > http://p.sf.net/sfu/Zoho > _______________________________________________ > Librtas-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/librtas-devel > |
From: Nathan F. <nf...@li...> - 2014-10-21 17:00:34
|
Correct the warnings produced during the build of librtas. Signed-off-by: Nathan Fontenot <nf...@li...> NOTE: This should have been the real patch 2/10. I'll send another set of patches out (if needed) with the patch numbering correct. --- librtas_src/syscall_calls.c | 18 +++++++++--------- librtas_src/syscall_rmo.c | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index a107cf5..0ef3b2c 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -30,7 +30,7 @@ _syscall1(int, rtas, void *, args); #define CALL_AGAIN 1 -struct librtas_config config = { NULL, 0 }; +struct librtas_config config = { 0, 0 }; /** * handle_delay @@ -445,7 +445,7 @@ int rtas_get_config_addr_info2(uint32_t config_addr, uint64_t phb_id, *info = be32toh(be_info); - dbg1("(0x%x, 0x%llx, %d) = %d, 0x%x\n", config_addr, phb_id, func, + dbg1("(0x%x, 0x%lx, %d) = %d, 0x%x\n", config_addr, phb_id, func, rc ? rc : status, *info); return rc ? rc : status; } @@ -528,7 +528,7 @@ rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, *next = be32toh(be_next); - dbg1("(%d, %d, %p, %d, %d, %p) = %d, %d\n", is_sensor, type, workarea, + dbg1("(%d, %d, %p, %zd, %d, %p) = %d, %d\n", is_sensor, type, workarea, size, start, next, rc ? rc : status, *next); return rc ? rc : status; } @@ -721,7 +721,7 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, *seq_next = be32toh(*seq_next); *bytes_ret = be32toh(*bytes_ret); - dbg1("(%s, 0x%p, %d, %d) = %d, %d, %d", loc_code ? loc_code : "NULL", + dbg1("(%s, 0x%p, %zd, %d) = %d, %d, %d", loc_code ? loc_code : "NULL", workarea, size, sequence, status, *seq_next, *bytes_ret); return rc ? rc : status; } @@ -828,7 +828,7 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, break; sequence = BITS64(be32toh(next_hi), be32toh(next_lo)); - dbg1("%s: seq_next = 0x%llx\n", __FUNCTION__, sequence); + dbg1("%s: seq_next = 0x%lx\n", __FUNCTION__, sequence); rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); @@ -844,7 +844,7 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, bytes_lo = be32toh(bytes_lo); *bytes_ret = BITS64(bytes_hi, bytes_lo); - dbg1("(0x%llx, 0x%llx, %p, %d, %p, %p) = %d, 0x%llx, 0x%llx\n", + dbg1("(0x%lx, 0x%lx, %p, %zd, %p, %p) = %d, 0x%lx, 0x%lx\n", dump_tag, sequence, buffer, length, seq_next, bytes_ret, rc ? rc : status, *seq_next, *bytes_ret); return rc ? rc : status; @@ -874,7 +874,7 @@ rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, *state = be32toh(*state); *eeh = be32toh(*eeh); - dbg1("(0x%x, 0x%llx, %p, %p) = %d, %d, %d\n", cfg_addr, phbid, state, + dbg1("(0x%x, 0x%lx, %p, %p) = %d, %d, %d\n", cfg_addr, phbid, state, eeh, rc ? rc : status, *state, *eeh); return rc ? rc : status; } @@ -907,7 +907,7 @@ int rtas_scan_log_dump(void *buffer, size_t length) (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); - dbg1("(%p, %d) = %d\n", buffer, length, rc ? rc : status); + dbg1("(%p, %zd) = %d\n", buffer, length, rc ? rc : status); return rc ? rc : status; } @@ -978,7 +978,7 @@ rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) htobe32(BITS32_HI(phbid)), htobe32(BITS32_LO(phbid)), htobe32(function), &status); - dbg1("(0x%x, 0x%llx, %d) = %d\n", cfg_addr, phbid, function, + dbg1("(0x%x, 0x%lx, %d) = %d\n", cfg_addr, phbid, function, rc ? rc : status); return rc ? rc : status; } diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index cc364f4..a483f42 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -91,7 +91,7 @@ static int read_kregion_bounds(struct region *kregion) return rc; } - sscanf(buf, "%llx %x", &kregion->addr, &kregion->size); + sscanf(buf, "%lx %x", &kregion->addr, &kregion->size); free(buf); if (!(kregion->size && kregion->addr) || @@ -169,7 +169,7 @@ static int acquire_file_lock(off_t start, size_t size) rc = fcntl(wa_config.lockfile_fd, F_SETLKW, &flock); if (rc < 0) { /* Expected to fail for regions used by other processes */ - dbg1("fcntl failed for [0x%lx, 0x%x]\n", start, size); + dbg1("fcntl failed for [0x%lx, 0x%zx]\n", start, size); return RTAS_IO_ASSERT; } @@ -196,7 +196,7 @@ static int release_file_lock(off_t start, size_t size) rc = fcntl(wa_config.lockfile_fd, F_SETLK, &flock); if (rc < 0) { - dbg1("fcntl failed for [0x%lx, 0x%x]\n", start, size); + dbg1("fcntl failed for [0x%lx, 0x%zx]\n", start, size); return RTAS_IO_ASSERT; } @@ -219,7 +219,7 @@ static int get_phys_region(size_t size, uint32_t * phys_addr) int i; if (size > kregion->size) { - dbg1("Invalid buffer size 0x%x requested\n", size); + dbg1("Invalid buffer size 0x%zx requested\n", size); return RTAS_IO_ASSERT; } @@ -266,7 +266,7 @@ static int release_phys_region(uint32_t phys_addr, size_t size) int rc; if (size > kregion->size) { - dbg1("Invalid buffer size 0x%x requested\n", size); + dbg1("Invalid buffer size 0x%zx requested\n", size); return RTAS_IO_ASSERT; } @@ -276,7 +276,7 @@ static int release_phys_region(uint32_t phys_addr, size_t size) bits = get_bits(first_page, first_page + n_pages - 1, wa_config.pages_map); if (bits != ((1 << n_pages) - 1)) { - dbg1("Invalid region [0x%x, 0x%x]\n", phys_addr, size); + dbg1("Invalid region [0x%x, 0x%zx]\n", phys_addr, size); return RTAS_IO_ASSERT; } @@ -447,7 +447,7 @@ int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) int n_pages; int rc; - dbg1("RMO buffer request, size: %d\n", size); + dbg1("RMO buffer request, size: %zd\n", size); n_pages = size / PAGE_SIZE; |
From: Nathan F. <nf...@li...> - 2014-10-21 16:58:32
|
The libofdt library is a project that was started a long time ago in the hopes of providing a common infrastructure for accessing the device tree. The code is mostly complete andd I really don't think there are any users of it so I am proposing to deprecate the library. Signed-off-by: Nathan Fontenot <nf...@li...> --- 0 files changed diff --git a/Makefile b/Makefile index dcec853..98077a2 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ include rules.mk .SILENT: FILES = README COPYRIGHT -SUBDIRS = librtas_src librtasevent_src libofdt_src +SUBDIRS = librtas_src librtasevent_src TARBALL_FILES += $(FILES) doc/doxygen.rtas doc/doxygen.rtasevent Changelog @@ -29,7 +29,6 @@ rpm: all @export DESTDIR=$(SHIPDIR); $(MAKE) install @rm $(SHIPDIR)$(LIB_DIR)$(call is_lib64,librtas_src/librtas.so.$(VERSION))/librtas.so @rm $(SHIPDIR)$(LIB_DIR)$(call is_lib64,librtasevent_src/librtasevent.so.$(VERSION))/librtasevent.so - @rm $(SHIPDIR)$(LIB_DIR)$(call is_lib64,libofdt_src/libofdt.so.$(VERSION))/libofdt.so @$(RPM) -bb $(SPECFILE) @rm -rf $(SHIPDIR) diff --git a/libofdt_src/Makefile b/libofdt_src/Makefile deleted file mode 100644 index 02fba0c..0000000 --- a/libofdt_src/Makefile +++ /dev/null @@ -1,38 +0,0 @@ - -# -# Makefile for libofdt -# -# Copyright (C) 2005 IBM Corporation -# Common Public License Version 1.0 (see COPYRIGHT) -# - -include ../rules.mk - -LIBOFDT_SONAME = libofdt.so -LIBOFDT = $(LIBOFDT_SONAME).$(VERSION) - -LIBOFDT_OBJS = dtree.o drc.o - -LIBOFDT_HDRS = libofdt.h common.h -LIBOFDT_SHIP_HDR = libofdt.h - -CFLAGS += -fPIC -DPIC -LDFLAGS += -shared -Wl,-soname -Wl,$(LIBOFDT_SONAME).$(MAJOR_NO) - -all: $(LIBOFDT_OBJS) $(LIBOFDT_HDRS) - @echo "LD $(WORK_DIR)/$(LIBOFDT)..." - @$(CC) $(LIBOFDT_OBJS) $(LDFLAGS) -o $(LIBOFDT) - -install: - @$(call install_lib,$(LIBOFDT),$(DESTDIR)) - @$(call install_inc,$(LIBOFDT_SHIP_HDR),$(DESTDIR)) - @ln -sf $(LIBOFDT) $(DESTDIR)/$(LIB_DIR)$(call is_lib64,$(LIBOFDT))/$(LIBOFDT_SONAME) - -uninstall: - @$(call uninstall_lib,$(LIBOFDT),$(DESTDIR)) - @$(call uninstall_inc,$(LIBOFDT_SHIP_HDR),$(DESTDIR)) - @rm -f $(DESTDIR)/$(LIB_DIR)$(call is_lib64,$(LIBOFDT))/$(LIBOFDT_SONAME) - -clean: - @echo "Cleaning up $(WORK_DIR) files..." - @rm -f $(LIBOFDT_OBJS) $(LIBOFDT) diff --git a/libofdt_src/README b/libofdt_src/README deleted file mode 100644 index 6561ab5..0000000 --- a/libofdt_src/README +++ /dev/null @@ -1,57 +0,0 @@ - -In most linux systems, most of the hardware bindings and values are exported -through /proc/devic-tree. This needs to be accessed frequently to query values -to enable or disable many functions on the system. Here, We attempt to provide -an API to read values and parse data that maybe required for many utilities -to do commonly required operations. Please note that this API only reads -and parses values. It does not modify anything. - -The API is as follows: - -1: -void ofdt_get(const char *path) -This function accepts a relative path to the deivce-tree. It can also be -NULL. If the value is null, the base path to the device-tree -/proc/device-tree is assumed. If the value is non null, a relative path -is assumed and /proc/device-tree is added to the path to fully qualify it. - -This function builds a complete tree from the given path. It processes -sub-directories and will also parse ibm,indexes file and find appropriate -values for "ibm,drc-name", "ibm,drc-type" & "ibm,drc-powerdomain" for the -approprate "ibm,my-drc-index" files. It fills these out and sends back -a pointer to the the head of the tree. - -It is always nice to call ofdt_put after this function has been called -with the right head pointer. - - -2: -void ofdt_put(struct node *delete) - -This function takes a node pointer type, normally this is the head of -a tree structure that needs to be freed. It is normally a good idea -to free the stuff allocated. But just incase you forget, there is a -fini_routine that takes care of it. - -3: -struct property *ofdt_get_property(struct node *prop_node, - const char * name); - -This function takes a path to the property and a node pointer. The node -pointer is normally the head of a fully populated tree structure formed -by ofdt_get() with appropriate values. The function returns the requested -property from the given tree. - -4: -struct property * ofdt_get_property_by_name(const char * path); - -This function returns a structure of type property. It builds and -returns the property from the given path. It does not build a tree. -It will also not return any property that does not exist like -for eg: when a ibm,my-drc-index exists and other properties do not, it -will return a NULL pointer. - -5: -void ofdt_property_put(struct property * to_delete); - -This function frees all properties that are passed in to this function. diff --git a/libofdt_src/common.h b/libofdt_src/common.h deleted file mode 100644 index 5a6b605..0000000 --- a/libofdt_src/common.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file common.h - * - * Copyright (C) 2008/2009 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author Manish Ahuja ma...@us... - */ -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include "libofdt.h" - -#define DRC_STR_MAX 48 -#define OFDT_BASE "/proc/device-tree" - -struct delete_struct { - struct delete_struct *next; - struct node *dnode; - struct property *dprop; -}; - -struct dr_connector { - char name[DRC_STR_MAX]; - char type[DRC_STR_MAX]; - unsigned int index; - unsigned int powerdomain; - struct dr_connector *next; -}; - -struct of_list_prop { - char *_data; - char *val; - int n_entries; -}; - -struct drc_prop_grp { - struct of_list_prop drc_names; - struct of_list_prop drc_types; - struct of_list_prop drc_indexes; - struct of_list_prop drc_domains; -}; - -struct dr_connector *get_drc_info(const char *); -void free_drc_info(struct dr_connector *); -char *of_to_full_path(const char *); -struct dr_connector *find_drc_info(const char *); -int file_exists(const char *, const char *); -void create_drc_properties(struct node *, struct dr_connector *); -void add_property(struct node *, const char *, char *); - -static inline void *zalloc(int sz) { - void *tmp = malloc(sz); - if (tmp) - memset(tmp, 0, sz); - - return tmp; -} - -#endif /* COMMON_H_ */ diff --git a/libofdt_src/drc.c b/libofdt_src/drc.c deleted file mode 100644 index 1421ec8..0000000 --- a/libofdt_src/drc.c +++ /dev/null @@ -1,339 +0,0 @@ -/** - * @file drc.c - * @brief Common routines for building DRC Info. - * @author Borrowed/Adapted code from drmgr authored by "Nathan Fontenont". - * @author Manish Ahuja ma...@us... - * - * Copyright (C) IBM Corporation 2009 - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <stdint.h> -#include <endian.h> -#include <byteswap.h> -#include "common.h" - -static inline unsigned int ofdt_swap_int(unsigned int data) -{ -#if __BYTE_ORDER == __LITTLE_ENDIAN - return bswap_32(data); -#else - return data; -#endif -} - -/** - * get_property - * @brief retrieve a device-tree property from /proc - * - * @param path path to the property to retrieve - * @param name name of the property to retrieve - * @param prop of_list_prop to retrieve property for - * @returns 0 on success, !0 otherwise - */ -static int get_property(const char *path, const char *property, - void *buf, int buf_sz) -{ - FILE *fp; - int rc; - char dir[OFDT_MAX_PATH]; - - if ((path == NULL) || (property == NULL)) - return -1; - - sprintf(dir, "%s/%s", path, property); - fp = fopen(dir, "r"); - if (fp == NULL) - return -1; - - rc = fread(buf, buf_sz, 1, fp); - - fclose(fp); - return 0; -} - -/** - * get_proprety_size - * @brief Retrieve the size of a device tree property - * - * @param path full path to property - * @param name property name - * @returns size of property - */ -static int get_property_size(const char *path, const char *name) -{ - char file_path[OFDT_MAX_PATH]; - struct stat sb; - int rc; - - sprintf(file_path, "%s/%s", path, name); - rc = stat(file_path, &sb); - - return sb.st_size; -} - -/** - * get_of_list_prop - * @breif retrieve the specified open firmware property list - * - * @param full_path - * @param prop_name - * @param prop - * @returns 0 on success, !0 otherwise - */ -static int get_of_list_prop(const char *full_path, char *prop_name, - struct of_list_prop *prop) -{ - int rc, size; - - size = get_property_size(full_path, prop_name); - prop->_data = zalloc(size); - if (prop->_data == NULL) - return -1; - - rc = get_property(full_path, prop_name, prop->_data, size); - if (rc) { - free(prop->_data); - return -1; - } - - prop->n_entries = ofdt_swap_int(*(uint *)prop->_data); - prop->val = prop->_data + sizeof(uint); - - return 0; -} - -/** - * get_drc_prop_grp - * - * @param full_path - * @param group - * @returns 0 on success, !0 otherwise - */ -static int get_drc_prop_grp(const char *full_path, struct drc_prop_grp *group) -{ - int rc; - - memset(group, 0, sizeof(*group)); - - rc = get_of_list_prop(full_path, "ibm,drc-names", &group->drc_names); - if (rc) - return rc; - - rc = get_of_list_prop(full_path, "ibm,drc-types", &group->drc_types); - if (rc) - return rc; - - rc = get_of_list_prop(full_path, "ibm,drc-indexes", - &group->drc_indexes); - if (rc) - return rc; - - rc = get_of_list_prop(full_path, "ibm,drc-power-domains", - &group->drc_domains); - if (rc) - return rc; - - return 0; -} - -/** - * free_drc_props - * @brief free the properties associated with a drc group - * - * @param group - */ -static void free_drc_props(struct drc_prop_grp *group) -{ - if (group->drc_names.val) - free(group->drc_names._data); - if (group->drc_types.val) - free(group->drc_types._data); - if (group->drc_indexes.val) - free(group->drc_indexes._data); - if (group->drc_domains.val) - free(group->drc_domains._data); -} - -/** - * build_connectors_group - * - * @param group - * @param n_entries - * @param list - * @returns 0 on success, !0 otherwise - */ -static int build_connectors_list(struct drc_prop_grp *group, int n_entries, - struct dr_connector *list) -{ - struct dr_connector *entry; - unsigned int *index_ptr; - unsigned int *domain_ptr; - char *name_ptr; - char *type_ptr; - int i; - - index_ptr = (unsigned int *)group->drc_indexes.val; - domain_ptr = (unsigned int *)group->drc_domains.val; - name_ptr = group->drc_names.val; - type_ptr = group->drc_types.val; - - for (i = 0; i < n_entries; i++) { - entry = &list[i]; - - entry->index = *(index_ptr++); - entry->powerdomain = *(domain_ptr++); - - strncpy(entry->name, name_ptr, DRC_STR_MAX); - name_ptr += strlen(name_ptr) + 1; - - strncpy(entry->type, type_ptr, DRC_STR_MAX); - type_ptr += strlen(type_ptr) + 1; - - if (i == (n_entries - 1)) - entry->next = NULL; - else - entry->next = &list[i+1]; - } - - return 0; -} - -/** - * get_dr_connectors - * - * NOTE:Callers of this function are expected to free drc_list themselves - * - * @param of_path - * @param drc_list - * @param n_drcs - * @returns 0 on success, !0 otherwise - */ -struct dr_connector *get_drc_info(const char *of_path) -{ - struct dr_connector *list = NULL; - struct of_list_prop *drc_names; - struct drc_prop_grp prop_grp; - int n_drcs; - int rc; - - rc = get_drc_prop_grp(of_path, &prop_grp); - if (rc) - return NULL; - - drc_names = &prop_grp.drc_names; - n_drcs = drc_names->n_entries; - - list = zalloc(n_drcs * sizeof(struct dr_connector)); - if (list) - rc = build_connectors_list(&prop_grp, n_drcs, list); - - free_drc_props(&prop_grp); - return list; -} - -/** - * free_drc_info - * - * @param drc_list - */ -void free_drc_info(struct dr_connector *drc_list) -{ - free(drc_list); -} - -/** - * file_exists - * - * @brief Function that checks whether ibm,my-drc-index exists. - * - * @param path - * @returns 0 on success, !0 otherwise - */ -int file_exists(const char *path, const char *fname) -{ - int rc; - struct stat sb; - char file_path[OFDT_MAX_PATH]; - - sprintf(file_path, "%s/%s", path, fname); - rc = stat(file_path, &sb); - - return !rc; -} - -/** - * create_drc_props - * - * @brief Function that creates drc,type/name/powerdomain. - * - * @param dr_connector - * @param parent node - * @param path - */ -void create_drc_properties(struct node *node, struct dr_connector *drc_list) -{ - char powerdomain[OFDT_MAX_NAME]; - struct dr_connector *drc; - int rc; - uint32_t drc_index; - - if (drc_list == NULL) - return; - - rc = get_property(node->path, "ibm,my-drc-index", &drc_index, - sizeof(drc_index)); - if (rc) - return; - drc_index = ofdt_swap_int(drc_index); - - for (drc = drc_list; drc; drc = drc->next) { - if (drc_index == drc->index) - break; - } - - if (!drc) - return - - add_property(node, "ibm,drc-name", drc->name); - add_property(node, "ibm,drc-type", drc->type); - - sprintf(powerdomain, "%u", drc->powerdomain); - add_property(node, "ibm,drc-powerdomain", powerdomain); -} - -/** - * find_drc_info - * - * @brief Function that parses prev sub-directories until it finds - * ibm,drc-index file - * - * @param path - * @returns dr_connector type. - */ -struct dr_connector *find_drc_info(const char *path) -{ - struct stat sb; - int rc; - char tmp_path[OFDT_MAX_PATH]; - char buf[OFDT_MAX_PATH]; - char *slash; - - sprintf(buf, "%s", path); - - do { - sprintf(tmp_path, "%s/%s", buf, "ibm,drc-indexes"); - rc = stat(buf, &sb); - if (rc == 0) - return get_drc_info(buf); - - slash = strrchr(buf, '/'); - if (slash) - *slash = '\0'; - } while (slash); - - return NULL; -} diff --git a/libofdt_src/dtree.c b/libofdt_src/dtree.c deleted file mode 100644 index c611099..0000000 --- a/libofdt_src/dtree.c +++ /dev/null @@ -1,530 +0,0 @@ -/** - * @file dtree.c - * - * Copyright (C) 2008/2009 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author Manish Ahuja ma...@us... - */ - -#include "common.h" - -struct node *treehead = NULL; -struct delete_struct *delete_list = NULL; - -void __libofdt_fini() __attribute__((destructor)); - -/** - * allocate_property - * @brief allocates property - * - * @param name - * @param path - * @param value - * @param size - * @return property - */ -static struct property *allocate_property(const char *name, const char *path, - char *value) -{ - struct property *prop; - int rc; - - prop = zalloc(sizeof(*prop)); - if (!prop) - return NULL; - - if (!value) { - FILE *fp; - struct stat sb; - - rc = stat(path, &sb); - if (rc) - return NULL; - - prop->value = zalloc(sb.st_size + 1); - if (prop->value) { - free(prop); - return NULL; - } - - fp = fopen(path, "r"); - if (fp == NULL) { - free(prop); - return NULL; - } - - rc = fread(prop->value, 1, sb.st_size, fp); - fclose(fp); - } else { - int length = strlen(value); - - prop->value = zalloc(length + 1); - if (!prop->value) { - free(prop); - return NULL; - } - - strncpy(prop->value, value, length); - } - - /* struct alredy nulled out, not copying last null */ - strncpy(prop->path, path, strlen(path)); - strncpy(prop->name, name, strlen(name)); - - return prop; -} - -/** - * add_property - * @brief adds property to head of queue and then calls allocate_property - * - * @param name - * @param path - * @param value - * @param size - */ -void add_property(struct node *node, const char *name, char *value) -{ - struct property *prop; - - prop = allocate_property(name, node->path, value); - - prop->next = node->properties; - node->properties = prop; -} - -/** - * allocate_node - * @brief allocates the actual node. - * - * @param parent - * @param path - * @returns node - */ -static struct node *allocate_node(struct node *parent, const char* path) -{ - struct node *node; - - node = zalloc(sizeof(*node)); - if (node == NULL) - return NULL; - - strncpy(node->path, path, strlen(path)); - node->parent = parent; - - return node; -} - -/** - * build_node - * @brief the heart of this library, that builds and creates the whole tree. - * - * @param dirname - * @param parent_node - * @param parent_list - * @returns node - */ -static struct node *build_node(const char *path, - struct dr_connector *my_drc_info) -{ - int rc; - DIR *d; - struct dirent *de; - struct node *node; - char buf[OFDT_MAX_PATH]; - struct dr_connector *child_drc_info; - - /* Check to see if we need to create drc info for any child nodes */ - if (file_exists(path, "ibm,drc-indexes")) - child_drc_info = get_drc_info(path); - else - child_drc_info = my_drc_info; - - node = allocate_node(NULL, path); - if (!node) { - if (child_drc_info != my_drc_info) - free_drc_info(child_drc_info); - - return NULL; - } - - if (file_exists(path, "ibm,my-drc-index")) - create_drc_properties(node, my_drc_info); - - d = opendir(path); - if (!d) { - if (child_drc_info != my_drc_info) - free_drc_info(child_drc_info); - - return NULL; - } - - while((de = readdir(d)) != NULL ) { - struct stat sb; - - sprintf(buf, "%s/%s", path, de->d_name); - rc = stat(buf, &sb); - if (rc) - break; - - if (S_ISDIR(sb.st_mode)) { - struct node *child; - - child = build_node(buf, child_drc_info); - - child->sibling = node->child; - node->child = child; - } else if (S_ISREG(sb.st_mode)) { - add_property(node, de->d_name, NULL); - } - } - - closedir(d); - - if (child_drc_info != my_drc_info) - free_drc_info(child_drc_info); - - return node; -} - -/** - * add_node_to_dl - * @brief Adds nodes to delete list. - * - * @param node to add - */ -static void add_node_to_dl(struct node *to_add) -{ - struct delete_struct *new; - - new = zalloc(sizeof(*new)); - if (!new) - return; - - new->dnode = to_add; - new->next = delete_list; - delete_list = new; -} - -/** - * add_prop_to_dl - * @brief Adds property to delete list. - * - * @param prop to add - */ -static void add_prop_to_dl(struct property *to_add) -{ - struct delete_struct *new; - - new = zalloc(sizeof(*new)); - if (!new) - return; - - new->dprop = to_add; - new->next = delete_list; - delete_list = new; -} - -/** - * delete_properties - * @brief deletes chained properties. - * - * @param prop to add - */ -static void delete_properties(struct node *to_delete) -{ - struct property *tmp, *prop; - prop = to_delete->properties; - - while (prop != NULL) { - tmp = prop; - prop = prop->next; - free(tmp); - } -} - -/** - * remove_node - * @brief removes sub-nodes and nodes recursively. - * - * @param node head. - */ -static void remove_node(struct node *head) -{ - struct node *tmp; - - while ((head->child) || (head->sibling)) { - if (head->child) { - remove_node(head->child); - if (head->sibling == NULL && (head->properties)) { - delete_properties(head); - free(head); - break; - } - } - if (head->sibling) { - if (head->properties) - delete_properties(head); - tmp = head; - head = head->sibling; - free(tmp); - } - } -} - -/** - * delete_node_from_dl - * @brief removes-any nodes being asked to delete. - * - * @param delete_node - */ -static void delete_node_from_dl(struct node *to_delete) -{ - struct delete_struct *tmp, *prev; - - tmp = delete_list; - while (tmp) { - if (tmp->dnode == to_delete) { - remove_node(tmp->dnode); - - if (tmp == delete_list) - delete_list = tmp->next; - else - prev->next = tmp->next; - - free(tmp); - break; - } - - prev = tmp; - tmp = tmp->next; - } -} - -/** - * delete_prop_from_dl - * @brief removes-any properties being asked to delete. - * - * @param delete_prop - */ -static void delete_prop_from_dl(struct property *to_delete) -{ - struct delete_struct *tmp, *prev; - - tmp = delete_list; - while (tmp) { - if (tmp->dprop == to_delete) { - free(tmp->dprop); - - if (tmp == delete_list) - delete_list = tmp->next; - else - prev->next = tmp->next; - - free(tmp); - return; - } - - prev = tmp; - tmp = tmp->next; - } -} - -/** - * base_path - * @brief builds appropriate path and returns it. - * - * The path specified can be either a full path to a device tree, or - * a relative path to the real device tree at /proc/device-tree. NOTE - * that the relative path of NULL implies the base device tree at - * /proc/device-tree - * - * @param dir - */ -static int path_to_full_dtpath(const char *user_path, char *full_path) -{ - struct stat sb; - int rc; - - memset(full_path, 0, OFDT_MAX_PATH); - - if (!user_path) { - /* NULL implies /proc/device-tree */ - sprintf(full_path, "%s", OFDT_BASE); - return 0; - } - - rc = stat(user_path, &sb); - if (rc == 0) { - /* Valid path specified, copy to full path */ - snprintf(full_path, OFDT_MAX_PATH, "%s", user_path); - return 0; - } - - /* build OFDT_BASE/user_path and validate */ - snprintf(full_path, OFDT_MAX_PATH, "%s/%s", OFDT_BASE, user_path); - rc = stat(full_path, &sb); - - return rc; -} - -/** - * ofdt_get - * @brief builds the device tree from the given path. - * - * @param path - * @returns node - */ -struct node *ofdt_get(const char * path) -{ - char full_path[OFDT_MAX_PATH]; - struct dr_connector *drc_info; - struct node *head; - int rc; - - rc = path_to_full_dtpath(path, full_path); - if (rc) - return NULL; - - drc_info = find_drc_info(full_path); - head = build_node(full_path, drc_info); - if (head) - add_node_to_dl(head); - - free_drc_info(drc_info); - return head; -} - -/** - * ofdt_put - * @brief releases the device tree from the given node pointer. - * - * @param path - * @returns node - */ -void ofdt_put(struct node *delete) -{ - delete_node_from_dl(delete); -} - -/** - * ofdt_get_property - * @brief returns the appropriate property pointer from given tree. It takes - * path. - * - * @param node - * @param path - * @returns property - */ -struct property *ofdt_get_property(struct node *node, const char *name) -{ - struct property *prop; - int len = strlen(name); - - for (prop = node->properties; prop; prop = prop->next) { - if (strncmp(prop->name, name, len) == 0) - return prop; - } - - return NULL; -} - -/** - * ofdt_get_property_by_name - * @brief builds and returns the appropriate property pointer from given path. - * - * @param path - * @returns property - */ -struct property * ofdt_get_property_by_name(const char * dir) -{ - struct property *prop; - char *name; - char path[OFDT_MAX_PATH]; - int rc; - - rc = path_to_full_dtpath(dir, path); - if (rc) - return NULL; - - name = strrchr(path, '/'); - if (!name) - return NULL; - - /* move past the '/' character */ - name++; - - prop = allocate_property(name, path, NULL); - add_prop_to_dl(prop); - return prop; -} - -/** - * ofdt_property_put - * @brief Deletes properties from delete list. - * - * @param property - */ -void ofdt_property_put(struct property *to_delete) -{ - delete_prop_from_dl(to_delete); -} - -#ifdef DEBUG -/** - * traverse_devicetree - * @brief Debug function, that prints nodes and properties. - * - * @param node_head - */ -void traverse_devicetree(struct node *head) -{ - struct property *prop; - - while ((head->child) || (head->sibling)) { - if (head->child) { - traverse_devicetree(head->child); - if (head->sibling == NULL) { - printf("NODE name is %s\n", head->path); - for (prop = head->properties; prop != NULL; - prop = prop->next) { - printf("\tProp name is %s path is %s\n", - prop->name, prop->path); - } - break; - } - } - if (head->sibling) { - printf("NODE name is %s\n", head->path); - for (prop = head->properties; prop != NULL; - prop = prop->next) { - printf("\tProp name is %s path is %s\n", - prop->name, prop->path); - } - head = head->sibling; - } - } -} -#endif - -/** - * __libofdt_fini() - * @brief fini routine that cleans everything when library exits. - * - */ -void __libofdt_fini() -{ - struct delete_struct *tmp, *prev; - - tmp = delete_list; - while (tmp) { - prev = tmp; - if (tmp->dnode) - remove_node(tmp->dnode); - if (tmp->dprop) - free(tmp->dprop); - tmp = tmp->next; - free(prev); - } -} diff --git a/libofdt_src/libofdt.h b/libofdt_src/libofdt.h deleted file mode 100644 index b4d2bd1..0000000 --- a/libofdt_src/libofdt.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file libofdt.h - * - * Copyright (C) 2008/2009 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author Manish Ahuja ma...@us... - */ - -#ifndef _LIBOFDT_H_ -#define _LIBOFDT_H_ - -#include <stdio.h> -#include <dirent.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <sys/stat.h> - -#define OFDT_MAX_NAME 128 /* Max name length */ -#define OFDT_MAX_PATH 1024 /* Max Path length */ - -struct property { - char name[OFDT_MAX_NAME]; - char path[OFDT_MAX_PATH]; - char *value; - struct property *next; - struct node * parent; -}; - -struct node { - char name[OFDT_MAX_NAME]; - char path[OFDT_MAX_PATH]; - struct property *properties; - struct node *child; - struct node *parent; - struct node *sibling; -}; - -extern struct node *ofdt_get(const char *); -extern void ofdt_put(struct node *); - -extern struct property *ofdt_get_property(struct node *, const char *); -extern struct property *ofdt_get_property_by_name(const char *); -extern void ofdt_property_put(struct property *); - -#endif /* _LIBOFDT_H_ */ diff --git a/librtas.spec.in b/librtas.spec.in index d35925c..cb9e2e7 100644 --- a/librtas.spec.in +++ b/librtas.spec.in @@ -36,10 +36,8 @@ the contents of RTAS events. %defattr(-, root, root) %{_docdir}/%{name}/COPYRIGHT %{_docdir}/%{name}/README -%{_includedir}/common.h %{_includedir}/librtas.h %{_libdir}/librtas.so.%{version} -%{_libdir}/libofdt.so %{_libdir}/librtas.so %{_libdir}/librtasevent.so %{_libdir}/librtasevent.so.1 @@ -48,15 +46,11 @@ the contents of RTAS events. %{_includedir}/librtasevent_v4.h %{_includedir}/librtasevent_v6.h -%{_libdir}/libofdt.so.%{version} -%{_includedir}/libofdt.h - %post # Post-install script ------------------------------------------------- ln -sf %{_libdir}/librtas.so.%{version} %{_libdir}/librtas.so ln -sf %{_libdir}/librtas.so.%{version} %{_libdir}/librtas.so.1 ln -sf %{_libdir}/librtasevent.so.%{version} %{_libdir}/librtasevent.so -ln -sf %{_libdir}/libofdt.so.%{version} %{_libdir}/libofdt.so ldconfig %postun @@ -64,6 +58,5 @@ ldconfig if [ "$1" = "0" ] ; then # last uninstall rm -f %{_libdir}/librtas.so rm -f %{_libdir}/librtasevent.so - rm -f %{_libdir}/libofdt.so fi ldconfig |
From: Nathan F. <nf...@li...> - 2014-10-21 16:57:28
|
Correct a few style issues to give the code a more consistent look. No functional changes. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/librtas.h | 2 + librtas_src/ofdt.c | 9 +++--- librtas_src/syscall_calls.c | 62 ++++++++++++++++++++----------------------- librtas_src/syscall_rmo.c | 6 ++-- 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index c0f7e4f..00b6adb 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -34,7 +34,7 @@ /* Adding a new RTAS call requires the following: * 1) A function prototype in librtas.h (this file) that roughly matches * the RTAS call name. - * 2) An implementation of the RTAS function, in librtas_calls.c. + * 2) An implementation of the RTAS function, in syscall_calls.c. */ #ifdef __cplusplus diff --git a/librtas_src/ofdt.c b/librtas_src/ofdt.c index ba5a7a2..3140621 100644 --- a/librtas_src/ofdt.c +++ b/librtas_src/ofdt.c @@ -62,12 +62,10 @@ static int open_prop_file(const char *prop_path, const char *prop_name, int *fd) * @param prop_len * @return 0 on success, !0 otherwise */ -static int -get_property(const char *prop_path, const char *prop_name, char **prop_val, - size_t * prop_len) +static int get_property(const char *prop_path, const char *prop_name, + char **prop_val, size_t *prop_len) { - int fd; - int rc; + int rc, fd; rc = open_prop_file(prop_path, prop_name, &fd); if (rc) @@ -142,6 +140,7 @@ int read_entire_file(int fd, char **buf, size_t * len) errno = EIO; return -1; } + off += rc; } while (rc == BLOCK_SIZE); diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 56b4e1a..88abe18 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -109,7 +109,7 @@ static void display_rtas_buf(struct rtas_args *args, int after) return; ninputs = be32toh(args->ninputs); - nret = be32toh(args->nret); + nret = be32toh(args->nret); /* It doesn't make sense to byte swap the input and return arguments * as we don't know here what they really mean (it could be a 64 bit @@ -178,6 +178,7 @@ static int _rtas_call(int delay_handling, int token, int ninputs, dbg("RTAS syscall failure, errno=%d\n", errno); return RTAS_IO_ASSERT; } + display_rtas_buf(&args, 1); /* Assign rets */ @@ -281,9 +282,11 @@ int rtas_cfg_connector(char *workarea) break; if ((rc == 0) && (status == CFG_RC_MEM)) { - rc = rtas_get_rmo_buffer(PAGE_SIZE, &extent, &extent_pa); + rc = rtas_get_rmo_buffer(PAGE_SIZE, &extent, + &extent_pa); if (rc < 0) break; + continue; } @@ -553,9 +556,8 @@ int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) * @param next * @return 0 on success, !0 otherwise */ -int -rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, - int start, int *next) +int rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, + int start, int *next) { uint32_t kernbuf_pa; __be32 be_next; @@ -565,6 +567,7 @@ rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, rc = sanity_check(); if (rc) return rc; + rc = rtas_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -658,9 +661,7 @@ int rtas_get_sensor(int sensor, int index, int *state) * @param data reference to buffer to return parameter in * @return 0 on success, !0 otherwise */ -int -rtas_get_sysparm(unsigned int parameter, unsigned int length, - char *data) +int rtas_get_sysparm(unsigned int parameter, unsigned int length, char *data) { uint32_t kernbuf_pa; void *kernbuf; @@ -703,7 +704,7 @@ rtas_get_sysparm(unsigned int parameter, unsigned int length, * @return 0 on success, !0 otherwise */ int rtas_get_time(uint32_t *year, uint32_t *month, uint32_t *day, - uint32_t *hour, uint32_t *min, uint32_t *sec, uint32_t *nsec) + uint32_t *hour, uint32_t *min, uint32_t *sec, uint32_t *nsec) { int rc, status; @@ -740,8 +741,8 @@ int rtas_get_time(uint32_t *year, uint32_t *month, uint32_t *day, * @return 0 on success, !0 otherwise */ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, - unsigned int sequence, unsigned int *seq_next, - unsigned int *bytes_ret) + unsigned int sequence, unsigned int *seq_next, + unsigned int *bytes_ret) { uint32_t kernbuf_pa; uint32_t loc_pa = 0; @@ -759,6 +760,7 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, rc = rtas_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); if (rc) return rc; + kernbuf = rmobuf + PAGE_SIZE; kernbuf_pa = rmo_pa + PAGE_SIZE; locbuf = rmobuf; @@ -804,9 +806,8 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, * @param seq_next * @return 0 on success, !0 otherwise */ -int rtas_lpar_perftools(int subfunc, char *workarea, - unsigned int length, unsigned int sequence, - unsigned int *seq_next) +int rtas_lpar_perftools(int subfunc, char *workarea, unsigned int length, + unsigned int sequence, unsigned int *seq_next) { uint64_t elapsed = 0; uint32_t kernbuf_pa; @@ -859,9 +860,8 @@ int rtas_lpar_perftools(int subfunc, char *workarea, * @param bytes_ret * @return 0 on success, !0 othwerwise */ -int -rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, - size_t length, uint64_t * seq_next, uint64_t * bytes_ret) +int rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, + size_t length, uint64_t *seq_next, uint64_t *bytes_ret) { uint64_t elapsed = 0; uint32_t kernbuf_pa = 0; @@ -880,8 +880,8 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, if (rc) return rc; } - /* - * Converting a 64bit host value to 32bit BE, _hi and _lo + + /* Converting a 64bit host value to 32bit BE, _hi and _lo * pair is tricky: we should convert the _hi and _lo 32bits * of the 64bit host value. */ @@ -933,9 +933,8 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, * @param eeh * @return 0 on success, !0 otherwise */ -int -rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, - int *eeh) +int rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, + int *eeh) { int rc, status; @@ -1011,8 +1010,7 @@ int rtas_set_debug(int level) * @param loc_code * @return 0 on success, !0 otherwise */ -int rtas_set_dynamic_indicator(int indicator, int new_value, - void *loc_code) +int rtas_set_dynamic_indicator(int indicator, int new_value, void *loc_code) { uint32_t loc_pa = 0; void *locbuf; @@ -1042,7 +1040,7 @@ int rtas_set_dynamic_indicator(int indicator, int new_value, } /** - * rtas__set_eeh_option + * rtas_set_eeh_option * @brief Inerface to the ibm,set-eeh-option rtas call * * @param cfg_addr configuration address for slot to set eeh option on @@ -1050,8 +1048,7 @@ int rtas_set_dynamic_indicator(int indicator, int new_value, * @param function * @return 0 on success, !0 otherwise */ -int -rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) +int rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) { int rc, status; @@ -1134,9 +1131,9 @@ int rtas_set_power_level(int powerdomain, int level, int *setlevel) * @param nsec nano-second top power on * @return 0 on success, !0 otherwise */ -int -rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, uint32_t nsec) +int rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, + uint32_t hour, uint32_t min, uint32_t sec, + uint32_t nsec) { int rc, status; @@ -1201,8 +1198,8 @@ int rtas_set_sysparm(unsigned int parameter, char *data) * @param nsec nan-second to set time to * @return 0 on success, !0 otherwise */ -int rtas_set_time(uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, uint32_t nsec) +int rtas_set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, + uint32_t min, uint32_t sec, uint32_t nsec) { int rc, status; @@ -1313,4 +1310,3 @@ int rtas_update_properties(char *workarea, unsigned int scope) dbg("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; } -/* ========================= END OF FILE ================== */ diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index 59d5e0f..b238937 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -129,7 +129,7 @@ static inline uint64_t get_bits(short lobit, short hibit, uint64_t mask) * @return 0 on success, !0 otherwise */ static inline void set_bits(short lobit, short hibit, uint64_t value, - uint64_t * mask) + uint64_t *mask) { short num_bits = hibit - lobit + 1; uint64_t ones_mask = (1ll << (num_bits)) - 1; @@ -273,8 +273,8 @@ static int release_phys_region(uint32_t phys_addr, size_t size) first_page = (phys_addr - kregion->addr) / PAGE_SIZE; n_pages = size / PAGE_SIZE; - bits = - get_bits(first_page, first_page + n_pages - 1, wa_config.pages_map); + bits = get_bits(first_page, first_page + n_pages - 1, + wa_config.pages_map); if (bits != ((1 << n_pages) - 1)) { dbg("Invalid region [0x%x, 0x%zx]\n", phys_addr, size); return RTAS_IO_ASSERT; |
From: Nathan F. <nf...@li...> - 2014-10-21 16:56:25
|
Make the SANITY_CHECKS() macro a regular function. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/librtas.h | 9 -- librtas_src/syscall.h | 1 librtas_src/syscall_calls.c | 163 +++++++++++++++++++++++++++++++++++-------- librtas_src/syscall_rmo.c | 10 ++- 4 files changed, 143 insertions(+), 40 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index d7fd849..c0f7e4f 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -97,13 +97,4 @@ extern int rtas_update_properties(char *workarea, unsigned int scope); } #endif -#define SANITY_CHECKS() \ - /* Check credentials */ \ - if (geteuid() != (uid_t) 0) \ - return RTAS_PERM; \ - \ - /* Check for any kernel RTAS interface */ \ - if (!interface_exists()) \ - return RTAS_KERNEL_INT; - #endif /* _LIBRTAS_H_ */ diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index c4a8baa..90e5e4e 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -41,6 +41,7 @@ extern int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size); extern int interface_exists(); extern int read_entire_file(int fd, char **buf, size_t *len); extern int rtas_token(const char *call_name); +extern int sanity_check(void); #define BITS32_LO(_num) (uint32_t) (_num & 0xffffffffll) #define BITS32_HI(_num) (uint32_t) (_num >> 32) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 96fe72f..56b4e1a 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -34,6 +34,23 @@ int dbg_lvl = 0; static uint64_t rtas_timeout_ms; /** + * sanity_check + * @brief validate the caller credentials and rtas interface + * + * @return 0 for success, !o on failure + */ +int sanity_check(void) +{ + if (geteuid() != (uid_t)0) + return RTAS_PERM; + + if (!interface_exists()) + return RTAS_KERNEL_INT; + + return 0; +} + +/** * handle_delay * @brief sleep for the specified delay time * @@ -215,9 +232,12 @@ static int rtas_call(const char *name, int ninputs, int nrets, ...) */ int rtas_activate_firmware() { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("ibm,activate-firmware", 0, 1, &status); dbg("() = %d\n", rc ? rc : status); @@ -236,7 +256,6 @@ int rtas_activate_firmware() */ int rtas_cfg_connector(char *workarea) { - SANITY_CHECKS(); uint32_t workarea_pa; uint32_t extent_pa = 0; uint64_t elapsed = 0; @@ -244,6 +263,10 @@ int rtas_cfg_connector(char *workarea) void *extent; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(PAGE_SIZE, &kernbuf, &workarea_pa); if (rc) return rc; @@ -288,7 +311,12 @@ int rtas_cfg_connector(char *workarea) */ int rtas_delay_timeout(uint64_t timeout_ms) { - SANITY_CHECKS(); + int rc; + + rc = sanity_check(); + if (rc) + return rc; + rtas_timeout_ms = timeout_ms; return 0; @@ -303,9 +331,12 @@ int rtas_delay_timeout(uint64_t timeout_ms) */ int rtas_display_char(char c) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("display-character", 1, 1, c, &status); dbg("(%d) = %d\n", c, rc ? rc : status); @@ -321,12 +352,15 @@ int rtas_display_char(char c) */ int rtas_display_msg(char *buf) { - SANITY_CHECKS(); uint32_t kernbuf_pa; void *kernbuf; int str_len; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + str_len = strlen(buf); rc = rtas_get_rmo_buffer(str_len, &kernbuf, &kernbuf_pa); @@ -356,11 +390,14 @@ int rtas_display_msg(char *buf) */ int rtas_errinjct(int etoken, int otoken, char *workarea) { - SANITY_CHECKS(); uint32_t kernbuf_pa; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(ERRINJCT_BUF_SIZE, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -388,9 +425,12 @@ int rtas_errinjct(int etoken, int otoken, char *workarea) */ int rtas_errinjct_close(int otoken) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("ibm,close-errinjct", 1, 1, htobe32(otoken), &status); dbg("(%d) = %d\n", otoken, rc ? rc : status); @@ -409,10 +449,13 @@ int rtas_errinjct_close(int otoken) */ int rtas_errinjct_open(int *otoken) { - SANITY_CHECKS(); __be32 be_otoken; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("ibm,open-errinjct", 0, 2, &be_otoken, &status); *otoken = be32toh(be_otoken); @@ -436,10 +479,13 @@ int rtas_errinjct_open(int *otoken) int rtas_get_config_addr_info2(uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info) { - SANITY_CHECKS(); __be32 be_info; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("ibm,get-config-addr-info2", 4, 2, htobe32(config_addr), htobe32(BITS32_HI(phb_id)), htobe32(BITS32_LO(phb_id)), htobe32(func), &status, &be_info); @@ -465,13 +511,16 @@ int rtas_get_config_addr_info2(uint32_t config_addr, uint64_t phb_id, */ int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) { - SANITY_CHECKS(); uint32_t loc_pa = 0; void *locbuf; uint32_t size; __be32 be_state; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); rc = rtas_get_rmo_buffer(size, &locbuf, &loc_pa); @@ -508,12 +557,14 @@ int rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, int start, int *next) { - SANITY_CHECKS(); uint32_t kernbuf_pa; __be32 be_next; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; rc = rtas_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -547,10 +598,13 @@ rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, */ int rtas_get_power_level(int powerdomain, int *level) { - SANITY_CHECKS(); __be32 be_level; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("get-power-level", 1, 2, htobe32(powerdomain), &status, &be_level); @@ -575,10 +629,13 @@ int rtas_get_power_level(int powerdomain, int *level) */ int rtas_get_sensor(int sensor, int index, int *state) { - SANITY_CHECKS(); __be32 be_state; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("get-sensor-state", 2, 2, htobe32(sensor), htobe32(index), &status, &be_state); @@ -605,11 +662,14 @@ int rtas_get_sysparm(unsigned int parameter, unsigned int length, char *data) { - SANITY_CHECKS(); uint32_t kernbuf_pa; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -645,9 +705,12 @@ rtas_get_sysparm(unsigned int parameter, unsigned int length, int rtas_get_time(uint32_t *year, uint32_t *month, uint32_t *day, uint32_t *hour, uint32_t *min, uint32_t *sec, uint32_t *nsec) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("get-time-of-day", 0, 8, &status, year, month, day, hour, min, sec, nsec); @@ -680,7 +743,6 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, unsigned int sequence, unsigned int *seq_next, unsigned int *bytes_ret) { - SANITY_CHECKS(); uint32_t kernbuf_pa; uint32_t loc_pa = 0; uint32_t rmo_pa = 0; @@ -690,6 +752,10 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, void *locbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); if (rc) return rc; @@ -742,12 +808,15 @@ int rtas_lpar_perftools(int subfunc, char *workarea, unsigned int length, unsigned int sequence, unsigned int *seq_next) { - SANITY_CHECKS(); uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -794,7 +863,6 @@ int rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, size_t length, uint64_t * seq_next, uint64_t * bytes_ret) { - SANITY_CHECKS(); uint64_t elapsed = 0; uint32_t kernbuf_pa = 0; uint32_t next_hi, next_lo; @@ -803,6 +871,10 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + if (buffer) { rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) @@ -865,9 +937,12 @@ int rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, int *eeh) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("ibm,read-slot-reset-state", 3, 3, htobe32(cfg_addr), htobe32(BITS32_HI(phbid)), htobe32(BITS32_LO(phbid)), &status, state, eeh); @@ -890,11 +965,14 @@ rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, */ int rtas_scan_log_dump(void *buffer, size_t length) { - SANITY_CHECKS(); uint32_t kernbuf_pa; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -936,12 +1014,15 @@ int rtas_set_debug(int level) int rtas_set_dynamic_indicator(int indicator, int new_value, void *loc_code) { - SANITY_CHECKS(); uint32_t loc_pa = 0; void *locbuf; uint32_t size; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); rc = rtas_get_rmo_buffer(size, &locbuf, &loc_pa); @@ -972,9 +1053,12 @@ int rtas_set_dynamic_indicator(int indicator, int new_value, int rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("ibm,set-eeh-option", 4, 1, htobe32(cfg_addr), htobe32(BITS32_HI(phbid)), htobe32(BITS32_LO(phbid)), htobe32(function), &status); @@ -995,9 +1079,12 @@ rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) */ int rtas_set_indicator(int indicator, int index, int new_value) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("set-indicator", 3, 1, htobe32(indicator), htobe32(index), htobe32(new_value), &status); @@ -1017,10 +1104,13 @@ int rtas_set_indicator(int indicator, int index, int new_value) */ int rtas_set_power_level(int powerdomain, int level, int *setlevel) { - SANITY_CHECKS(); __be32 be_setlevel; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("set-power-level", 2, 2, htobe32(powerdomain), htobe32(level), &status, &be_setlevel); @@ -1048,9 +1138,12 @@ int rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t min, uint32_t sec, uint32_t nsec) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("set-time-for-power-on", 7, 1, htobe32(year), htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); @@ -1070,12 +1163,15 @@ rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, */ int rtas_set_sysparm(unsigned int parameter, char *data) { - SANITY_CHECKS(); uint32_t kernbuf_pa; void *kernbuf; int rc, status; short size; + rc = sanity_check(); + if (rc) + return rc; + size = *(short *)data; rc = rtas_get_rmo_buffer(size + sizeof(short), &kernbuf, &kernbuf_pa); if (rc) @@ -1108,9 +1204,12 @@ int rtas_set_sysparm(unsigned int parameter, char *data) int rtas_set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t min, uint32_t sec, uint32_t nsec) { - SANITY_CHECKS(); int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_call("set-time-of-day", 7, 1, htobe32(year), htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); @@ -1150,11 +1249,14 @@ int rtas_suspend_me(uint64_t streamid) */ int rtas_update_nodes(char *workarea, unsigned int scope) { - SANITY_CHECKS(); uint32_t workarea_pa; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) return rc; @@ -1186,11 +1288,14 @@ int rtas_update_nodes(char *workarea, unsigned int scope) */ int rtas_update_properties(char *workarea, unsigned int scope) { - SANITY_CHECKS(); uint32_t workarea_pa; void *kernbuf; int rc, status; + rc = sanity_check(); + if (rc) + return rc; + rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) return rc; diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index 0ed3272..59d5e0f 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -397,10 +397,13 @@ int interface_exists() */ int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) { - SANITY_CHECKS(); int n_pages; int rc; + rc = sanity_check(); + if (rc) + return rc; + n_pages = size / PAGE_SIZE; /* Check for multiple of page size */ @@ -442,11 +445,14 @@ int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) */ int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) { - SANITY_CHECKS(); uint32_t addr; int n_pages; int rc; + rc = sanity_check(); + if (rc) + return rc; + dbg("RMO buffer request, size: %zd\n", size); n_pages = size / PAGE_SIZE; |
From: Nathan F. <nf...@li...> - 2014-10-21 16:55:21
|
Move rtas_token decalration to internal header file. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/librtas.h | 2 -- librtas_src/syscall.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index d2504b5..d7fd849 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -97,8 +97,6 @@ extern int rtas_update_properties(char *workarea, unsigned int scope); } #endif -extern int rtas_token(const char *call_name); - #define SANITY_CHECKS() \ /* Check credentials */ \ if (geteuid() != (uid_t) 0) \ diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index 6c9ddd2..c4a8baa 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -40,6 +40,7 @@ extern int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t *phys_addr); extern int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size); extern int interface_exists(); extern int read_entire_file(int fd, char **buf, size_t *len); +extern int rtas_token(const char *call_name); #define BITS32_LO(_num) (uint32_t) (_num & 0xffffffffll) #define BITS32_HI(_num) (uint32_t) (_num >> 32) |
From: Nathan F. <nf...@li...> - 2014-10-21 16:53:40
|
Make the open_proc_rtas_file() routine static and remove its declaration from librtas.h. Signed-off-by: Nathan Fotnenot <nf...@li...> --- librtas_src/librtas.h | 1 - librtas_src/syscall_rmo.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index e645655..d2504b5 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -97,7 +97,6 @@ extern int rtas_update_properties(char *workarea, unsigned int scope); } #endif -extern int open_proc_rtas_file(const char *name, int mode); extern int rtas_token(const char *call_name); #define SANITY_CHECKS() \ diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index caaff91..0ed3272 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -43,7 +43,7 @@ static struct workarea_config wa_config = { * @param mode mode to open file in * @return results of open() call */ -int open_proc_rtas_file(const char *name, int mode) +static int open_proc_rtas_file(const char *name, int mode) { const char *proc_rtas_paths[] = { "/proc/ppc64/rtas", "/proc/rtas" }; char full_name[MAX_PATH_LEN]; |
From: Nathan F. <nf...@li...> - 2014-10-21 16:50:58
|
Move declaration of read_entire_file() to an internal header. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/librtas.h | 1 - librtas_src/syscall.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index dcead18..e645655 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -99,7 +99,6 @@ extern int rtas_update_properties(char *workarea, unsigned int scope); extern int open_proc_rtas_file(const char *name, int mode); extern int rtas_token(const char *call_name); -extern int read_entire_file(int fd, char **buf, size_t *len); #define SANITY_CHECKS() \ /* Check credentials */ \ diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index b939af8..6c9ddd2 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -39,6 +39,7 @@ struct region { extern int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t *phys_addr); extern int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size); extern int interface_exists(); +extern int read_entire_file(int fd, char **buf, size_t *len); #define BITS32_LO(_num) (uint32_t) (_num & 0xffffffffll) #define BITS32_HI(_num) (uint32_t) (_num >> 32) |
From: Nathan F. <nf...@li...> - 2014-10-21 16:49:45
|
Break up the librtas_config struct into its two pieces and remove the definitions from the public header. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/librtas.h | 7 ------- librtas_src/syscall.h | 4 +++- librtas_src/syscall_calls.c | 15 ++++++++------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index 316bcce..dcead18 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -97,17 +97,10 @@ extern int rtas_update_properties(char *workarea, unsigned int scope); } #endif -struct librtas_config { - uint64_t rtas_timeout_ms; - int debug; -}; - extern int open_proc_rtas_file(const char *name, int mode); extern int rtas_token(const char *call_name); extern int read_entire_file(int fd, char **buf, size_t *len); -extern struct librtas_config config; - #define SANITY_CHECKS() \ /* Check credentials */ \ if (geteuid() != (uid_t) 0) \ diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index a32b73b..b939af8 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -44,9 +44,11 @@ extern int interface_exists(); #define BITS32_HI(_num) (uint32_t) (_num >> 32) #define BITS64(_high, _low) (uint64_t) (((uint64_t) _high << 32) | _low) +extern int dbg_lvl; + #define dbg(_fmt, _args...) \ do { \ - if (config.debug >= 0) \ + if (dbg_lvl >= 0) \ printf("librtas %s(): " _fmt, __func__, ##_args); \ } while (0) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 445694d..96fe72f 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -30,7 +30,8 @@ _syscall1(int, rtas, void *, args); #define CALL_AGAIN 1 -struct librtas_config config = { 0, 0 }; +int dbg_lvl = 0; +static uint64_t rtas_timeout_ms; /** * handle_delay @@ -61,11 +62,11 @@ static unsigned int handle_delay(int status, uint64_t * elapsed) return 0; } - if (config.rtas_timeout_ms) { - if (*elapsed >= config.rtas_timeout_ms) + if (rtas_timeout_ms) { + if (*elapsed >= rtas_timeout_ms) return RTAS_TIMEOUT; - remaining = config.rtas_timeout_ms - *elapsed; + remaining = rtas_timeout_ms - *elapsed; if (ms > remaining) ms = remaining; } @@ -87,7 +88,7 @@ static void display_rtas_buf(struct rtas_args *args, int after) { int i, ninputs, nret; - if (config.debug < 2) + if (dbg_lvl < 2) return; ninputs = be32toh(args->ninputs); @@ -288,7 +289,7 @@ int rtas_cfg_connector(char *workarea) int rtas_delay_timeout(uint64_t timeout_ms) { SANITY_CHECKS(); - config.rtas_timeout_ms = timeout_ms; + rtas_timeout_ms = timeout_ms; return 0; } @@ -920,7 +921,7 @@ int rtas_scan_log_dump(void *buffer, size_t length) */ int rtas_set_debug(int level) { - config.debug = level; + dbg_lvl = level; return 0; } |
From: Nathan F. <nf...@li...> - 2014-10-21 16:47:59
|
Remove the useless indirect of dbg1() macro and move the definition to an internal .h file. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/librtas.h | 11 ----- librtas_src/ofdt.c | 3 + librtas_src/syscall.h | 6 +++ librtas_src/syscall_calls.c | 98 ++++++++++++++++++++++--------------------- librtas_src/syscall_rmo.c | 32 +++++++------- 5 files changed, 73 insertions(+), 77 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index eaeda0a..316bcce 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -108,17 +108,6 @@ extern int read_entire_file(int fd, char **buf, size_t *len); extern struct librtas_config config; -#define dbg(_lvl, _fmt, _args...) \ - do { \ - if (config.debug >= _lvl) \ - printf("librtas %s(): " _fmt, __FUNCTION__, ##_args); \ - } while (0) - -#define dbg1(_fmt, _args...) \ - do { \ - dbg(1, _fmt, ##_args); \ - } while (0) \ - #define SANITY_CHECKS() \ /* Check credentials */ \ if (geteuid() != (uid_t) 0) \ diff --git a/librtas_src/ofdt.c b/librtas_src/ofdt.c index 226735a..ba5a7a2 100644 --- a/librtas_src/ofdt.c +++ b/librtas_src/ofdt.c @@ -14,6 +14,7 @@ #include <endian.h> #include <byteswap.h> #include "librtas.h" +#include "syscall.h" static const char *ofdt_rtas_path = "/proc/device-tree/rtas"; @@ -137,7 +138,7 @@ int read_entire_file(int fd, char **buf, size_t * len) rc = read(fd, *buf + off, BLOCK_SIZE); if (rc < 0) { - dbg1("read failed\n"); + dbg("read failed\n"); errno = EIO; return -1; } diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index d5da539..a32b73b 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -44,4 +44,10 @@ extern int interface_exists(); #define BITS32_HI(_num) (uint32_t) (_num >> 32) #define BITS64(_high, _low) (uint64_t) (((uint64_t) _high << 32) | _low) +#define dbg(_fmt, _args...) \ + do { \ + if (config.debug >= 0) \ + printf("librtas %s(): " _fmt, __func__, ##_args); \ + } while (0) + #endif diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 0ef3b2c..445694d 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -71,7 +71,7 @@ static unsigned int handle_delay(int status, uint64_t * elapsed) } *elapsed += ms; - dbg1("Return status %d, delaying for %ld ms\n", status, ms); + dbg("Return status %d, delaying for %ld ms\n", status, ms); usleep(ms * 1000); return 1; } @@ -157,7 +157,7 @@ static int _rtas_call(int delay_handling, int token, int ninputs, } while (rc == CALL_AGAIN); if (rc != 0) { - dbg1("RTAS syscall failure, errno=%d\n", errno); + dbg("RTAS syscall failure, errno=%d\n", errno); return RTAS_IO_ASSERT; } display_rtas_buf(&args, 1); @@ -219,7 +219,7 @@ int rtas_activate_firmware() rc = rtas_call("ibm,activate-firmware", 0, 1, &status); - dbg1("() = %d\n", rc ? rc : status); + dbg("() = %d\n", rc ? rc : status); return rc ? rc : status; } @@ -274,7 +274,7 @@ int rtas_cfg_connector(char *workarea) if (extent_pa) (void)rtas_free_rmo_buffer(extent, extent_pa, PAGE_SIZE); - dbg1("(%p) = %d\n", workarea, rc ? rc : status); + dbg("(%p) = %d\n", workarea, rc ? rc : status); return rc ? rc : status; } @@ -307,7 +307,7 @@ int rtas_display_char(char c) rc = rtas_call("display-character", 1, 1, c, &status); - dbg1("(%d) = %d\n", c, rc ? rc : status); + dbg("(%d) = %d\n", c, rc ? rc : status); return rc ? rc : status; } @@ -338,7 +338,7 @@ int rtas_display_msg(char *buf) &status); (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, str_len); - dbg1("(%p) = %d\n", buf, rc ? rc : status); + dbg("(%p) = %d\n", buf, rc ? rc : status); return rc ? rc : status; } @@ -374,7 +374,7 @@ int rtas_errinjct(int etoken, int otoken, char *workarea) (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, ERRINJCT_BUF_SIZE); - dbg1("(%d, %d, %p) = %d\n", etoken, otoken, workarea, rc ? rc : status); + dbg("(%d, %d, %p) = %d\n", etoken, otoken, workarea, rc ? rc : status); return rc ? rc : status; } @@ -392,7 +392,7 @@ int rtas_errinjct_close(int otoken) rc = rtas_call("ibm,close-errinjct", 1, 1, htobe32(otoken), &status); - dbg1("(%d) = %d\n", otoken, rc ? rc : status); + dbg("(%d) = %d\n", otoken, rc ? rc : status); return rc ? rc : status; } @@ -416,7 +416,7 @@ int rtas_errinjct_open(int *otoken) *otoken = be32toh(be_otoken); - dbg1("(%p) = %d, %d\n", otoken, rc ? rc : status, *otoken); + dbg("(%p) = %d, %d\n", otoken, rc ? rc : status, *otoken); return rc ? rc : status; } @@ -445,8 +445,8 @@ int rtas_get_config_addr_info2(uint32_t config_addr, uint64_t phb_id, *info = be32toh(be_info); - dbg1("(0x%x, 0x%lx, %d) = %d, 0x%x\n", config_addr, phb_id, func, - rc ? rc : status, *info); + dbg("(0x%x, 0x%lx, %d) = %d, 0x%x\n", config_addr, phb_id, func, + rc ? rc : status, *info); return rc ? rc : status; } @@ -486,8 +486,8 @@ int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) *state = be32toh(be_state); - dbg1("(%d, %s, %p) = %d, %d\n", sensor, (char *)loc_code, state, - rc ? rc : status, *state); + dbg("(%d, %s, %p) = %d, %d\n", sensor, (char *)loc_code, state, + rc ? rc : status, *state); return rc ? rc : status; } @@ -528,8 +528,8 @@ rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, *next = be32toh(be_next); - dbg1("(%d, %d, %p, %zd, %d, %p) = %d, %d\n", is_sensor, type, workarea, - size, start, next, rc ? rc : status, *next); + dbg("(%d, %d, %p, %zd, %d, %p) = %d, %d\n", is_sensor, type, workarea, + size, start, next, rc ? rc : status, *next); return rc ? rc : status; } @@ -555,8 +555,8 @@ int rtas_get_power_level(int powerdomain, int *level) *level = be32toh(be_level); - dbg1("(%d, %p) = %d, %d\n", powerdomain, level, rc ? rc : status, - *level); + dbg("(%d, %p) = %d, %d\n", powerdomain, level, rc ? rc : status, + *level); return rc ? rc : status; } @@ -583,8 +583,8 @@ int rtas_get_sensor(int sensor, int index, int *state) *state = be32toh(be_state); - dbg1("(%d, %d, %p) = %d, %d\n", sensor, index, state, rc ? rc : status, - *state); + dbg("(%d, %d, %p) = %d, %d\n", sensor, index, state, rc ? rc : status, + *state); return rc ? rc : status; } @@ -621,7 +621,7 @@ rtas_get_sysparm(unsigned int parameter, unsigned int length, (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); - dbg1("(%d, %d, %p) = %d\n", parameter, length, data, rc ? rc : status); + dbg("(%d, %d, %p) = %d\n", parameter, length, data, rc ? rc : status); return rc ? rc : status; } @@ -658,8 +658,8 @@ int rtas_get_time(uint32_t *year, uint32_t *month, uint32_t *day, *sec = be32toh(*sec); *nsec = be32toh(*nsec); - dbg1("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year, - *month, *day, *hour, *min, *sec, *nsec); + dbg("() = %d, %d, %d, %d, %d, %d, %d, %d\n", rc ? rc : status, *year, + *month, *day, *hour, *min, *sec, *nsec); return rc ? rc : status; } @@ -721,8 +721,8 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, *seq_next = be32toh(*seq_next); *bytes_ret = be32toh(*bytes_ret); - dbg1("(%s, 0x%p, %zd, %d) = %d, %d, %d", loc_code ? loc_code : "NULL", - workarea, size, sequence, status, *seq_next, *bytes_ret); + dbg("(%s, 0x%p, %zd, %d) = %d, %d, %d", loc_code ? loc_code : "NULL", + workarea, size, sequence, status, *seq_next, *bytes_ret); return rc ? rc : status; } @@ -773,8 +773,8 @@ int rtas_lpar_perftools(int subfunc, char *workarea, *seq_next = be32toh(*seq_next); - dbg1("(%d, %p, %d, %d, %p) = %d, %d\n", subfunc, workarea, - length, sequence, seq_next, rc ? rc : status, *seq_next); + dbg("(%d, %p, %d, %d, %p) = %d, %d\n", subfunc, workarea, + length, sequence, seq_next, rc ? rc : status, *seq_next); return rc ? rc : status; } /** @@ -828,7 +828,7 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, break; sequence = BITS64(be32toh(next_hi), be32toh(next_lo)); - dbg1("%s: seq_next = 0x%lx\n", __FUNCTION__, sequence); + dbg("seq_next = 0x%lx\n", sequence); rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); @@ -844,9 +844,9 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, bytes_lo = be32toh(bytes_lo); *bytes_ret = BITS64(bytes_hi, bytes_lo); - dbg1("(0x%lx, 0x%lx, %p, %zd, %p, %p) = %d, 0x%lx, 0x%lx\n", - dump_tag, sequence, buffer, length, seq_next, bytes_ret, - rc ? rc : status, *seq_next, *bytes_ret); + dbg("(0x%lx, 0x%lx, %p, %zd, %p, %p) = %d, 0x%lx, 0x%lx\n", + dump_tag, sequence, buffer, length, seq_next, bytes_ret, + rc ? rc : status, *seq_next, *bytes_ret); return rc ? rc : status; } @@ -874,8 +874,8 @@ rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, *state = be32toh(*state); *eeh = be32toh(*eeh); - dbg1("(0x%x, 0x%lx, %p, %p) = %d, %d, %d\n", cfg_addr, phbid, state, - eeh, rc ? rc : status, *state, *eeh); + dbg("(0x%x, 0x%lx, %p, %p) = %d, %d, %d\n", cfg_addr, phbid, state, + eeh, rc ? rc : status, *state, *eeh); return rc ? rc : status; } @@ -907,7 +907,7 @@ int rtas_scan_log_dump(void *buffer, size_t length) (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); - dbg1("(%p, %zd) = %d\n", buffer, length, rc ? rc : status); + dbg("(%p, %zd) = %d\n", buffer, length, rc ? rc : status); return rc ? rc : status; } @@ -954,8 +954,8 @@ int rtas_set_dynamic_indicator(int indicator, int new_value, (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); - dbg1("(%d, %d, %s) = %d\n", indicator, new_value, (char *)loc_code, - rc ? rc : status); + dbg("(%d, %d, %s) = %d\n", indicator, new_value, (char *)loc_code, + rc ? rc : status); return rc ? rc : status; } @@ -978,8 +978,8 @@ rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) htobe32(BITS32_HI(phbid)), htobe32(BITS32_LO(phbid)), htobe32(function), &status); - dbg1("(0x%x, 0x%lx, %d) = %d\n", cfg_addr, phbid, function, - rc ? rc : status); + dbg("(0x%x, 0x%lx, %d) = %d\n", cfg_addr, phbid, function, + rc ? rc : status); return rc ? rc : status; } @@ -1000,8 +1000,8 @@ int rtas_set_indicator(int indicator, int index, int new_value) rc = rtas_call("set-indicator", 3, 1, htobe32(indicator), htobe32(index), htobe32(new_value), &status); - dbg1("(%d, %d, %d) = %d\n", indicator, index, new_value, - rc ? rc : status); + dbg("(%d, %d, %d) = %d\n", indicator, index, new_value, + rc ? rc : status); return rc ? rc : status; } @@ -1025,8 +1025,8 @@ int rtas_set_power_level(int powerdomain, int level, int *setlevel) *setlevel = be32toh(be_setlevel); - dbg1("(%d, %d, %p) = %d, %d\n", powerdomain, level, setlevel, - rc ? rc : status, *setlevel); + dbg("(%d, %d, %p) = %d, %d\n", powerdomain, level, setlevel, + rc ? rc : status, *setlevel); return rc ? rc : status; } @@ -1054,8 +1054,8 @@ rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); - dbg1("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour, - min, sec, nsec, rc ? rc : status); + dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour, + min, sec, nsec, rc ? rc : status); return rc ? rc : status; } @@ -1087,7 +1087,7 @@ int rtas_set_sysparm(unsigned int parameter, char *data) (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, size + sizeof(short)); - dbg1("(%d, %p) = %d\n", parameter, data, rc ? rc : status); + dbg("(%d, %p) = %d\n", parameter, data, rc ? rc : status); return rc ? rc : status; } @@ -1114,8 +1114,8 @@ int rtas_set_time(uint32_t year, uint32_t month, uint32_t day, htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); - dbg1("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour, - min, sec, nsec, rc ? rc : status); + dbg("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour, + min, sec, nsec, rc ? rc : status); return rc ? rc : status; } @@ -1132,7 +1132,7 @@ int rtas_suspend_me(uint64_t streamid) rc = rtas_call("ibm,suspend-me", 2, 1, htobe32(BITS32_HI(streamid)), htobe32(BITS32_LO(streamid)), &status); - dbg1("() = %d\n", rc ? rc : status); + dbg("() = %d\n", rc ? rc : status); return rc ? rc : status; } @@ -1168,7 +1168,7 @@ int rtas_update_nodes(char *workarea, unsigned int scope) (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); - dbg1("(%p) %d = %d\n", workarea, scope, rc ? rc : status); + dbg("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; } @@ -1204,7 +1204,7 @@ int rtas_update_properties(char *workarea, unsigned int scope) (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); - dbg1("(%p) %d = %d\n", workarea, scope, rc ? rc : status); + dbg("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; } /* ========================= END OF FILE ================== */ diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index a483f42..caaff91 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -60,7 +60,7 @@ int open_proc_rtas_file(const char *name, int mode) } if (fd < 0) - dbg1("Failed to open %s\n", full_name); + dbg("Failed to open %s\n", full_name); return fd; } @@ -80,7 +80,7 @@ static int read_kregion_bounds(struct region *kregion) fd = open_proc_rtas_file(rmo_filename, O_RDONLY); if (fd < 0) { - dbg1("Could not open workarea file\n"); + dbg("Could not open workarea file\n"); return RTAS_IO_ASSERT; } @@ -96,7 +96,7 @@ static int read_kregion_bounds(struct region *kregion) if (!(kregion->size && kregion->addr) || (kregion->size > (PAGE_SIZE * MAX_PAGES))) { - dbg1("Unexpected kregion bounds\n"); + dbg("Unexpected kregion bounds\n"); return RTAS_IO_ASSERT; } @@ -155,7 +155,7 @@ static int acquire_file_lock(off_t start, size_t size) wa_config.lockfile_fd = open(lockfile_path, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (wa_config.lockfile_fd < 0) { - dbg1("could not open lockfile %s\n", lockfile_path); + dbg("could not open lockfile %s\n", lockfile_path); return RTAS_IO_ASSERT; } } @@ -169,7 +169,7 @@ static int acquire_file_lock(off_t start, size_t size) rc = fcntl(wa_config.lockfile_fd, F_SETLKW, &flock); if (rc < 0) { /* Expected to fail for regions used by other processes */ - dbg1("fcntl failed for [0x%lx, 0x%zx]\n", start, size); + dbg("fcntl failed for [0x%lx, 0x%zx]\n", start, size); return RTAS_IO_ASSERT; } @@ -196,7 +196,7 @@ static int release_file_lock(off_t start, size_t size) rc = fcntl(wa_config.lockfile_fd, F_SETLK, &flock); if (rc < 0) { - dbg1("fcntl failed for [0x%lx, 0x%zx]\n", start, size); + dbg("fcntl failed for [0x%lx, 0x%zx]\n", start, size); return RTAS_IO_ASSERT; } @@ -219,7 +219,7 @@ static int get_phys_region(size_t size, uint32_t * phys_addr) int i; if (size > kregion->size) { - dbg1("Invalid buffer size 0x%zx requested\n", size); + dbg("Invalid buffer size 0x%zx requested\n", size); return RTAS_IO_ASSERT; } @@ -242,7 +242,7 @@ static int get_phys_region(size_t size, uint32_t * phys_addr) } if (!addr) { - dbg1("Could not find available workarea space\n"); + dbg("Could not find available workarea space\n"); return RTAS_IO_ASSERT; } @@ -266,7 +266,7 @@ static int release_phys_region(uint32_t phys_addr, size_t size) int rc; if (size > kregion->size) { - dbg1("Invalid buffer size 0x%zx requested\n", size); + dbg("Invalid buffer size 0x%zx requested\n", size); return RTAS_IO_ASSERT; } @@ -276,7 +276,7 @@ static int release_phys_region(uint32_t phys_addr, size_t size) bits = get_bits(first_page, first_page + n_pages - 1, wa_config.pages_map); if (bits != ((1 << n_pages) - 1)) { - dbg1("Invalid region [0x%x, 0x%zx]\n", phys_addr, size); + dbg("Invalid region [0x%x, 0x%zx]\n", phys_addr, size); return RTAS_IO_ASSERT; } @@ -321,7 +321,7 @@ static int mmap_dev_mem(uint32_t phys_addr, size_t size, void **buf) fd = open(devmem_path, O_RDWR); if (fd < 0) { - dbg1("Failed to open %s\n", devmem_path); + dbg("Failed to open %s\n", devmem_path); return RTAS_IO_ASSERT; } @@ -330,7 +330,7 @@ static int mmap_dev_mem(uint32_t phys_addr, size_t size, void **buf) close(fd); if (newbuf == MAP_FAILED) { - dbg1("mmap failed\n"); + dbg("mmap failed\n"); return RTAS_IO_ASSERT; } @@ -352,14 +352,14 @@ static int munmap_dev_mem(void *buf, size_t size) fd = open(devmem_path, O_RDWR); if (fd < 0) { - dbg1("Failed to open %s\n", devmem_path); + dbg("Failed to open %s\n", devmem_path); return RTAS_IO_ASSERT; } rc = munmap(buf, size); close(fd); if (rc < 0) { - dbg1("munmap failed\n"); + dbg("munmap failed\n"); return RTAS_IO_ASSERT; } @@ -411,7 +411,7 @@ int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) } if (!wa_config.init_done) { - dbg1("Attempting to free before calling get()\n"); + dbg("Attempting to free before calling get()\n"); return RTAS_FREE_ERR; } @@ -447,7 +447,7 @@ int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) int n_pages; int rc; - dbg1("RMO buffer request, size: %zd\n", size); + dbg("RMO buffer request, size: %zd\n", size); n_pages = size / PAGE_SIZE; |
From: Nathan F. <nf...@li...> - 2014-10-21 16:46:48
|
Consolidate common actions, such as getting the rtas token and handling extended delays, when making a rtas call into a routine. This change presents to new ways to make a rtas call; rtas_call() - Which handles any delays rtas_call_no_delay() - Which does not handle any delays The no delay variant was needed for the few instances where some work needs to be done in between rtas calls when a delay occurs. Signed-off-by: Nathan Fontenot <nf...@li...> --- librtas_src/syscall_calls.c | 575 +++++++++++-------------------------------- 1 file changed, 144 insertions(+), 431 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 9b555a3..a107cf5 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -124,33 +124,37 @@ static void display_rtas_buf(struct rtas_args *args, int after) * @param nret number of return variables * @return 0 on success, !0 otherwise */ -static int rtas_call(int token, int ninputs, int nret, ...) +static int _rtas_call(int delay_handling, int token, int ninputs, + int nrets, va_list *ap) { struct rtas_args args; rtas_arg_t *rets[MAX_ARGS]; - va_list ap; - int rc; - int i; + uint64_t elapsed = 0; + int i, rc; args.token = htobe32(token); args.ninputs = htobe32(ninputs); - args.nret = htobe32(nret); + args.nret = htobe32(nrets); - va_start(ap, nret); for (i = 0; i < ninputs; i++) - args.args[i] = (rtas_arg_t) va_arg(ap, unsigned long); + args.args[i] = (rtas_arg_t) va_arg(*ap, unsigned long); - for (i = 0; i < nret; i++) - rets[i] = (rtas_arg_t *) va_arg(ap, unsigned long); - va_end(ap); + for (i = 0; i < nrets; i++) + rets[i] = (rtas_arg_t *) va_arg(*ap, unsigned long); display_rtas_buf(&args, 0); + do { #ifdef _syscall1 - rc = rtas(&args); + rc = rtas(&args); #else - rc = syscall(__NR_rtas, &args); + rc = syscall(__NR_rtas, &args); #endif + if (!delay_handling || (rc < 0)) + break; + + rc = handle_delay(be32toh(args.args[ninputs]), &elapsed); + } while (rc == CALL_AGAIN); if (rc != 0) { dbg1("RTAS syscall failure, errno=%d\n", errno); @@ -159,17 +163,49 @@ static int rtas_call(int token, int ninputs, int nret, ...) display_rtas_buf(&args, 1); /* Assign rets */ - if (nret) { + if (nrets) { /* All RTAS calls return a status in rets[0] */ *(rets[0]) = be32toh(args.args[ninputs]); - for (i = 1; i < nret; i++) + for (i = 1; i < nrets; i++) *(rets[i]) = args.args[ninputs + i]; } return 0; } +static int rtas_call_no_delay(const char *name, int ninputs, int nrets, ...) +{ + va_list ap; + int rc, token; + + token = rtas_token(name); + if (token < 0) + return token; + + va_start(ap, nrets); + rc = _rtas_call(0, token, ninputs, nrets, &ap); + va_end(ap); + + return rc; +} + +static int rtas_call(const char *name, int ninputs, int nrets, ...) +{ + va_list ap; + int rc, token; + + token = rtas_token(name); + if (token < 0) + return token; + + va_start(ap, nrets); + rc = _rtas_call(1, token, ninputs, nrets, &ap); + va_end(ap); + + return rc; +} + /** * rtas_activate_firmware * @brief Interface for ibm,activate-firmware rtas call @@ -179,21 +215,9 @@ static int rtas_call(int token, int ninputs, int nret, ...) int rtas_activate_firmware() { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("ibm,activate-firmware"); + int rc, status; - if (token < 0) - return token; - - do { - rc = rtas_call(token, 0, 1, &status); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,activate-firmware", 0, 1, &status); dbg1("() = %d\n", rc ? rc : status); return rc ? rc : status; @@ -217,12 +241,7 @@ int rtas_cfg_connector(char *workarea) uint64_t elapsed = 0; void *kernbuf; void *extent; - int status; - int rc; - int token = rtas_token("ibm,configure-connector"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(PAGE_SIZE, &kernbuf, &workarea_pa); if (rc) @@ -231,8 +250,9 @@ int rtas_cfg_connector(char *workarea) memcpy(kernbuf, workarea, PAGE_SIZE); do { - rc = rtas_call(token, 2, 1, htobe32(workarea_pa), - htobe32(extent_pa), &status); + rc = rtas_call_no_delay("ibm,configure-connector", 2, 1, + htobe32(workarea_pa), + htobe32(extent_pa), &status); if (rc < 0) break; @@ -283,21 +303,9 @@ int rtas_delay_timeout(uint64_t timeout_ms) int rtas_display_char(char c) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("display-character"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 1, 1, c, &status); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("display-character", 1, 1, c, &status); dbg1("(%d) = %d\n", c, rc ? rc : status); return rc ? rc : status; @@ -313,16 +321,10 @@ int rtas_display_char(char c) int rtas_display_msg(char *buf) { SANITY_CHECKS(); - uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; int str_len; - int status; - int rc; - int token = rtas_token("ibm,display-message"); - - if (token < 0) - return token; + int rc, status; str_len = strlen(buf); @@ -332,14 +334,8 @@ int rtas_display_msg(char *buf) strcpy(kernbuf, buf); - do { - rc = rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while ((rc == CALL_AGAIN)); - + rc = rtas_call("ibm,display-message", 1, 1, htobe32(kernbuf_pa), + &status); (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, str_len); dbg1("(%p) = %d\n", buf, rc ? rc : status); @@ -360,15 +356,9 @@ int rtas_display_msg(char *buf) int rtas_errinjct(int etoken, int otoken, char *workarea) { SANITY_CHECKS(); - uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; - int status=0; - int rc; - int token = rtas_token("ibm,errinjct"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(ERRINJCT_BUF_SIZE, &kernbuf, &kernbuf_pa); if (rc) @@ -376,14 +366,8 @@ int rtas_errinjct(int etoken, int otoken, char *workarea) memcpy(kernbuf, workarea, ERRINJCT_BUF_SIZE); - do { - rc = rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), - htobe32(kernbuf_pa), &status); - if (rc < 0 ) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,errinjct", 3, 1, htobe32(etoken), htobe32(otoken), + htobe32(kernbuf_pa), &status); if (rc == 0) memcpy(workarea, kernbuf, ERRINJCT_BUF_SIZE); @@ -404,21 +388,9 @@ int rtas_errinjct(int etoken, int otoken, char *workarea) int rtas_errinjct_close(int otoken) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("ibm,close-errinjct"); + int rc, status; - if (token < 0) - return token; - - do { - rc = rtas_call(token, 1, 1, htobe32(otoken), &status); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,close-errinjct", 1, 1, htobe32(otoken), &status); dbg1("(%d) = %d\n", otoken, rc ? rc : status); return rc ? rc : status; @@ -437,22 +409,10 @@ int rtas_errinjct_close(int otoken) int rtas_errinjct_open(int *otoken) { SANITY_CHECKS(); - uint64_t elapsed = 0; __be32 be_otoken; - int status; - int rc; - int token = rtas_token("ibm,open-errinjct"); - - if (token < 0) - return token; + int rc, status; - do { - rc = rtas_call(token, 0, 2, &be_otoken, &status); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,open-errinjct", 0, 2, &be_otoken, &status); *otoken = be32toh(be_otoken); @@ -476,25 +436,12 @@ int rtas_get_config_addr_info2(uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info) { SANITY_CHECKS(); - uint64_t elapsed = 0; __be32 be_info; - int status; - int rc; - int token = rtas_token("ibm,get-config-addr-info2"); - - if (token < 0) - return token; + int rc, status; - do { - rc = rtas_call(token, 4, 2, htobe32(config_addr), - htobe32(BITS32_HI(phb_id)), - htobe32(BITS32_LO(phb_id)), - htobe32(func), &status, &be_info); - if (rc) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,get-config-addr-info2", 4, 2, htobe32(config_addr), + htobe32(BITS32_HI(phb_id)), htobe32(BITS32_LO(phb_id)), + htobe32(func), &status, &be_info); *info = be32toh(be_info); @@ -519,16 +466,10 @@ int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) { SANITY_CHECKS(); uint32_t loc_pa = 0; - uint64_t elapsed = 0; void *locbuf; uint32_t size; __be32 be_state; - int status; - int rc; - int token = rtas_token("ibm,get-dynamic-sensor-state"); - - if (token < 0) - return token; + int rc, status; size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); @@ -538,14 +479,8 @@ int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) memcpy(locbuf, loc_code, size); - do { - rc = rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), - &status, &be_state); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,get-dynamic-sensor-state", 2, 2, + htobe32(sensor), htobe32(loc_pa), &status, &be_state); (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); @@ -573,31 +508,18 @@ rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, int start, int *next) { SANITY_CHECKS(); - uint64_t elapsed = 0; uint32_t kernbuf_pa; __be32 be_next; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,get-indices"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); if (rc) return rc; - do { - rc = rtas_call(token, 5, 2, htobe32(is_sensor), - htobe32(type), htobe32(kernbuf_pa), - htobe32(size), htobe32(start), - &status, &be_next); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,get-indices", 5, 2, htobe32(is_sensor), + htobe32(type), htobe32(kernbuf_pa), htobe32(size), + htobe32(start), &status, &be_next); if (rc == 0) memcpy(workarea, kernbuf, size); @@ -625,23 +547,11 @@ rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, int rtas_get_power_level(int powerdomain, int *level) { SANITY_CHECKS(); - uint64_t elapsed = 0; __be32 be_level; - int status; - int rc; - int token = rtas_token("get-power-level"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 1, 2, htobe32(powerdomain), - &status, &be_level); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("get-power-level", 1, 2, htobe32(powerdomain), + &status, &be_level); *level = be32toh(be_level); @@ -665,23 +575,11 @@ int rtas_get_power_level(int powerdomain, int *level) int rtas_get_sensor(int sensor, int index, int *state) { SANITY_CHECKS(); - uint64_t elapsed = 0; __be32 be_state; - int status; - int rc; - int token = rtas_token("get-sensor-state"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 2, 2, htobe32(sensor), - htobe32(index), &status, &be_state); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("get-sensor-state", 2, 2, htobe32(sensor), + htobe32(index), &status, &be_state); *state = be32toh(be_state); @@ -707,29 +605,16 @@ rtas_get_sysparm(unsigned int parameter, unsigned int length, char *data) { SANITY_CHECKS(); - uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,get-system-parameter"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; - do { - rc = rtas_call(token, 3, 1, htobe32(parameter), - htobe32(kernbuf_pa), htobe32(length), - &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,get-system-parameter", 3, 1, htobe32(parameter), + htobe32(kernbuf_pa), htobe32(length), &status); if (rc == 0) memcpy(data, kernbuf, length); @@ -760,22 +645,10 @@ int rtas_get_time(uint32_t *year, uint32_t *month, uint32_t *day, uint32_t *hour, uint32_t *min, uint32_t *sec, uint32_t *nsec) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("get-time-of-day"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 0, 8, &status, year, month, day, hour, - min, sec, nsec); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("get-time-of-day", 0, 8, &status, year, month, day, + hour, min, sec, nsec); *year = be32toh(*year); *month = be32toh(*month); @@ -814,12 +687,7 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, void *kernbuf; void *rmobuf; void *locbuf; - int status; - int rc; - int token = rtas_token("ibm,get-vpd"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); if (rc) @@ -835,7 +703,7 @@ int rtas_get_vpd(char *loc_code, char *workarea, size_t size, *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = rtas_call(token, 4, 3, htobe32(loc_pa), + rc = rtas_call_no_delay("ibm,get-vpd", 4, 3, htobe32(loc_pa), htobe32(kernbuf_pa), htobe32(size), sequence, &status, seq_next, bytes_ret); @@ -877,12 +745,7 @@ int rtas_lpar_perftools(int subfunc, char *workarea, uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,lpar-perftools"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) @@ -893,9 +756,10 @@ int rtas_lpar_perftools(int subfunc, char *workarea, *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = rtas_call(token, 5, 2, htobe32(subfunc), 0, - htobe32(kernbuf_pa), htobe32(length), - sequence, &status, seq_next); + rc = rtas_call_no_delay("ibm,lpar-perftools", 5, 2, + htobe32(subfunc), 0, + htobe32(kernbuf_pa), htobe32(length), + sequence, &status, seq_next); if (rc < 0) break; @@ -936,12 +800,7 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, uint32_t bytes_hi, bytes_lo; uint32_t dump_tag_hi, dump_tag_lo; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,platform-dump"); - - if (token < 0) - return token; + int rc, status; if (buffer) { rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); @@ -960,10 +819,11 @@ rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, next_lo = htobe32(BITS32_LO(sequence)); do { - rc = rtas_call(token, 6, 5, dump_tag_hi, dump_tag_lo, - next_hi, next_lo, htobe32(kernbuf_pa), - htobe32(length), &status, &next_hi, &next_lo, - &bytes_hi, &bytes_lo); + rc = rtas_call_no_delay("ibm,platform-dump", 6, 5, dump_tag_hi, + dump_tag_lo, next_hi, next_lo, + htobe32(kernbuf_pa), htobe32(length), + &status, &next_hi, &next_lo, + &bytes_hi, &bytes_lo); if (rc < 0) break; @@ -1005,24 +865,11 @@ rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, int *eeh) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("ibm,read-slot-reset-state"); - - if (token < 0) - return token; + int rc, status; - do { - rc = rtas_call(token, 3, 3, htobe32(cfg_addr), - htobe32(BITS32_HI(phbid)), - htobe32(BITS32_LO(phbid)), &status, - state, eeh); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,read-slot-reset-state", 3, 3, htobe32(cfg_addr), + htobe32(BITS32_HI(phbid)), htobe32(BITS32_LO(phbid)), + &status, state, eeh); *state = be32toh(*state); *eeh = be32toh(*eeh); @@ -1043,29 +890,17 @@ rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, int rtas_scan_log_dump(void *buffer, size_t length) { SANITY_CHECKS(); - uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,scan-log-dump"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, buffer, length); - do { - rc = rtas_call(token, 2, 1, htobe32(kernbuf_pa), - htobe32(length), &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,scan-log-dump", 2, 1, htobe32(kernbuf_pa), + htobe32(length), &status); if (rc == 0) memcpy(buffer, kernbuf, length); @@ -1102,15 +937,9 @@ int rtas_set_dynamic_indicator(int indicator, int new_value, { SANITY_CHECKS(); uint32_t loc_pa = 0; - uint64_t elapsed = 0; void *locbuf; uint32_t size; - int status; - int rc; - int token = rtas_token("ibm,set-dynamic-indicator"); - - if (token < 0) - return token; + int rc, status; size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); @@ -1120,15 +949,8 @@ int rtas_set_dynamic_indicator(int indicator, int new_value, memcpy(locbuf, loc_code, size); - do { - rc = rtas_call(token, 3, 1, htobe32(indicator), - htobe32(new_value), htobe32(loc_pa), &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); - + rc = rtas_call("ibm,set-dynamic-indicator", 3, 1, htobe32(indicator), + htobe32(new_value), htobe32(loc_pa), &status); (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); @@ -1150,24 +972,11 @@ int rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("ibm,set-eeh-option"); + int rc, status; - if (token < 0) - return token; - - do { - rc = rtas_call(token, 4, 1, htobe32(cfg_addr), - htobe32(BITS32_HI(phbid)), - htobe32(BITS32_LO(phbid)), - htobe32(function), &status); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,set-eeh-option", 4, 1, htobe32(cfg_addr), + htobe32(BITS32_HI(phbid)), htobe32(BITS32_LO(phbid)), + htobe32(function), &status); dbg1("(0x%x, 0x%llx, %d) = %d\n", cfg_addr, phbid, function, rc ? rc : status); @@ -1186,22 +995,10 @@ rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) int rtas_set_indicator(int indicator, int index, int new_value) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("set-indicator"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 3, 1, htobe32(indicator), - htobe32(index), htobe32(new_value), &status); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("set-indicator", 3, 1, htobe32(indicator), + htobe32(index), htobe32(new_value), &status); dbg1("(%d, %d, %d) = %d\n", indicator, index, new_value, rc ? rc : status); @@ -1220,23 +1017,11 @@ int rtas_set_indicator(int indicator, int index, int new_value) int rtas_set_power_level(int powerdomain, int level, int *setlevel) { SANITY_CHECKS(); - uint64_t elapsed = 0; __be32 be_setlevel; - int status; - int rc; - int token = rtas_token("set-power-level"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 2, 2, htobe32(powerdomain), - htobe32(level), &status, &be_setlevel); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("set-power-level", 2, 2, htobe32(powerdomain), + htobe32(level), &status, &be_setlevel); *setlevel = be32toh(be_setlevel); @@ -1263,23 +1048,11 @@ rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t min, uint32_t sec, uint32_t nsec) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("set-time-for-power-on"); - - if (token < 0) - return token; - - do { - rc = rtas_call(token, 7, 1, htobe32(year), htobe32(month), - htobe32(day), htobe32(hour), htobe32(min), - htobe32(sec), htobe32(nsec), &status); - if (rc) - return rc; + int rc, status; - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("set-time-for-power-on", 7, 1, htobe32(year), + htobe32(month), htobe32(day), htobe32(hour), + htobe32(min), htobe32(sec), htobe32(nsec), &status); dbg1("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour, min, sec, nsec, rc ? rc : status); @@ -1297,16 +1070,10 @@ rtas_set_poweron_time(uint32_t year, uint32_t month, uint32_t day, int rtas_set_sysparm(unsigned int parameter, char *data) { SANITY_CHECKS(); - uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; - int status; + int rc, status; short size; - int rc; - int token = rtas_token("ibm,set-system-parameter"); - - if (token < 0) - return token; size = *(short *)data; rc = rtas_get_rmo_buffer(size + sizeof(short), &kernbuf, &kernbuf_pa); @@ -1315,14 +1082,8 @@ int rtas_set_sysparm(unsigned int parameter, char *data) memcpy(kernbuf, data, size + sizeof(short)); - do { - rc = rtas_call(token, 2, 1, htobe32(parameter), - htobe32(kernbuf_pa), &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,set-system-parameter", 2, 1, htobe32(parameter), + htobe32(kernbuf_pa), &status); (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, size + sizeof(short)); @@ -1347,23 +1108,11 @@ int rtas_set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t min, uint32_t sec, uint32_t nsec) { SANITY_CHECKS(); - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("set-time-of-day"); - - if (token < 0) - return token; + int rc, status; - do { - rc = rtas_call(token, 7, 1, htobe32(year), htobe32(month), - htobe32(day), htobe32(hour), htobe32(min), - htobe32(sec), htobe32(nsec), &status); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("set-time-of-day", 7, 1, htobe32(year), htobe32(month), + htobe32(day), htobe32(hour), htobe32(min), + htobe32(sec), htobe32(nsec), &status); dbg1("(%d, %d, %d, %d, %d, %d, %d) = %d\n", year, month, day, hour, min, sec, nsec, rc ? rc : status); @@ -1378,22 +1127,10 @@ int rtas_set_time(uint32_t year, uint32_t month, uint32_t day, */ int rtas_suspend_me(uint64_t streamid) { - uint64_t elapsed = 0; - int status; - int rc; - int token = rtas_token("ibm,suspend-me"); - - if (token < 0) - return token; + int rc, status; - do { - rc = rtas_call(token, 2, 1, htobe32(BITS32_HI(streamid)), - htobe32(BITS32_LO(streamid)), &status); - if (rc) - return rc; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,suspend-me", 2, 1, htobe32(BITS32_HI(streamid)), + htobe32(BITS32_LO(streamid)), &status); dbg1("() = %d\n", rc ? rc : status); return rc ? rc : status; @@ -1414,14 +1151,8 @@ int rtas_update_nodes(char *workarea, unsigned int scope) { SANITY_CHECKS(); uint32_t workarea_pa; - uint64_t elapsed = 0; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,update-nodes"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) @@ -1429,14 +1160,8 @@ int rtas_update_nodes(char *workarea, unsigned int scope) memcpy(kernbuf, workarea, 4096); - do { - rc = rtas_call(token, 2, 1, htobe32(workarea_pa), - htobe32(scope), &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,update-nodes", 2, 1, htobe32(workarea_pa), + htobe32(scope), &status); if (rc == 0) memcpy(workarea, kernbuf, 4096); @@ -1462,14 +1187,8 @@ int rtas_update_properties(char *workarea, unsigned int scope) { SANITY_CHECKS(); uint32_t workarea_pa; - uint64_t elapsed = 0; void *kernbuf; - int status; - int rc; - int token = rtas_token("ibm,update-properties"); - - if (token < 0) - return token; + int rc, status; rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) @@ -1477,14 +1196,8 @@ int rtas_update_properties(char *workarea, unsigned int scope) memcpy(kernbuf, workarea, 4096); - do { - rc = rtas_call(token, 2, 1, htobe32(workarea_pa), - htobe32(scope), &status); - if (rc < 0) - break; - - rc = handle_delay(status, &elapsed); - } while (rc == CALL_AGAIN); + rc = rtas_call("ibm,update-properties", 2, 1, htobe32(workarea_pa), + htobe32(scope), &status); if (rc == 0) memcpy(workarea, kernbuf, 4096); |
From: Nathan F. <nf...@li...> - 2014-10-21 16:40:11
|
In anticipation of pushing out a new release of librtas that will be released under the GPL license I am putting out a set of patches that do some cleanup for the release. This set of patches is not really connected in any way other than putting a new release (likely v2.0) is a good chance to make some of these changes. These patches do a lot of cleanup to the code and remove the libofdt library from the package. This set of patches is done on top of Thomas Falcon's patches for removing the proc interface for librtas. -Nathan |
From: Thomas F. <tlf...@li...> - 2014-08-21 18:25:30
|
On 08/21/2014 07:30 AM, Suzuki K. Poulose wrote: > From: "Suzuki K. Poulose" <su...@in...> > > When we pass _hi and _lo 32bits of a 64bit value, we > should convert the host endian value carefully. > > i.e, > X_hi = htobe32(BITS32_HI(X)) > X_lo = htobe32(BITS32_LO(X)) > > and not : > X_hi = BITS32_HI(htobe64(X)) Maybe I am mistaken, but you take the high and low 32 bits of a 64-bit LE integer, then convert each to 32-bit BE integer. Each half would be the correct endianness, but would not be the correct orientation? Wouldn't the hi bits then actually be the lo bits? Ex. LE: AB BC CD DE BE: DE CD BC AB In the current implementation, hi is DECD. In this implementation, BCAB. tom > NOTE: This patch is untested, but I believe this patch > is good to have than the current faulty conversion. > > This patch fixes all such occurrences in librtas. > > Signed-off-by: Suzuki K. Poulose <su...@in...> > --- > librtas_src/syscall_calls.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c > index 29ab613..dc52370 100644 > --- a/librtas_src/syscall_calls.c > +++ b/librtas_src/syscall_calls.c > @@ -532,8 +532,8 @@ int sc_get_config_addr_info2(int token, uint32_t config_addr, > > do { > rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), > - BITS32_HI(htobe64(phb_id)), > - BITS32_LO(htobe64(phb_id)), > + htobe32(BITS32_HI(phb_id)), > + htobe32(BITS32_LO(phb_id)), > htobe32(func), &status, &be_info); > if (rc) > break; > @@ -1005,8 +1005,8 @@ sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, > > do { > rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), > - BITS32_HI(htobe64(phbid)), > - BITS32_LO(htobe64(phbid)), &status, > + htobe32(BITS32_HI(phbid)), > + htobe32(BITS32_LO(phbid)), &status, > state, eeh); > if (rc) > return rc; > @@ -1123,8 +1123,8 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) > > do { > rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), > - BITS32_HI(htobe64(phbid)), > - BITS32_LO(htobe64(phbid)), > + htobe32(BITS32_HI(phbid)), > + htobe32(BITS32_LO(phbid)), > htobe32(function), &status); > if (rc) > return rc; > @@ -1321,8 +1321,8 @@ int sc_suspend_me(int token, uint64_t streamid) > int rc; > > do { > - rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), > - BITS32_LO(htobe64(streamid)), &status); > + rc = sc_rtas_call(token, 2, 1, htobe32(BITS32_HI(streamid)), > + htobe32(BITS32_LO(streamid)), &status); > if (rc) > return rc; > -- |
From: Thomas F. <tlf...@li...> - 2014-08-21 16:29:21
|
On 08/21/2014 11:08 AM, Thomas Falcon wrote: > > On 08/21/2014 07:30 AM, Suzuki K. Poulose wrote: >> From: "Suzuki K. Poulose" <su...@in...> >> >> When we pass _hi and _lo 32bits of a 64bit value, we >> should convert the host endian value carefully. >> >> i.e, >> X_hi = htobe32(BITS32_HI(X)) >> X_lo = htobe32(BITS32_LO(X)) >> >> and not : >> X_hi = BITS32_HI(htobe64(X)) > > Maybe I am mistaken, but you take the high and low 32 bits of a 64-bit > LE integer, then convert each to 32-bit BE integer. Each half would > be the correct endianness, but would not be the correct orientation? > Wouldn't the hi bits then actually be the lo bits? > > Ex. > > LE: AB BC CD DE > > BE: DE CD BC AB > > In the current implementation, hi is DECD. In this implementation, BCAB. > > tom Nevermind this message, I was confused as to how the BITS32_HI and BITS32_LO macros work. I understand now. This is the right way to convert the values. tom >> NOTE: This patch is untested, but I believe this patch >> is good to have than the current faulty conversion. >> >> This patch fixes all such occurrences in librtas. >> >> Signed-off-by: Suzuki K. Poulose <su...@in...> >> --- >> librtas_src/syscall_calls.c | 16 ++++++++-------- >> 1 file changed, 8 insertions(+), 8 deletions(-) >> >> diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c >> index 29ab613..dc52370 100644 >> --- a/librtas_src/syscall_calls.c >> +++ b/librtas_src/syscall_calls.c >> @@ -532,8 +532,8 @@ int sc_get_config_addr_info2(int token, uint32_t >> config_addr, >> >> do { >> rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), >> - BITS32_HI(htobe64(phb_id)), >> - BITS32_LO(htobe64(phb_id)), >> + htobe32(BITS32_HI(phb_id)), >> + htobe32(BITS32_LO(phb_id)), >> htobe32(func), &status, &be_info); >> if (rc) >> break; >> @@ -1005,8 +1005,8 @@ sc_read_slot_reset(int token, uint32_t >> cfg_addr, uint64_t phbid, int *state, >> >> do { >> rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), >> - BITS32_HI(htobe64(phbid)), >> - BITS32_LO(htobe64(phbid)), &status, >> + htobe32(BITS32_HI(phbid)), >> + htobe32(BITS32_LO(phbid)), &status, >> state, eeh); >> if (rc) >> return rc; >> @@ -1123,8 +1123,8 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, >> uint64_t phbid, int function) >> >> do { >> rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), >> - BITS32_HI(htobe64(phbid)), >> - BITS32_LO(htobe64(phbid)), >> + htobe32(BITS32_HI(phbid)), >> + htobe32(BITS32_LO(phbid)), >> htobe32(function), &status); >> if (rc) >> return rc; >> @@ -1321,8 +1321,8 @@ int sc_suspend_me(int token, uint64_t streamid) >> int rc; >> >> do { >> - rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), >> - BITS32_LO(htobe64(streamid)), &status); >> + rc = sc_rtas_call(token, 2, 1, htobe32(BITS32_HI(streamid)), >> + htobe32(BITS32_LO(streamid)), &status); >> if (rc) >> return rc; >> > -- |
From: Suzuki K. P. <su...@in...> - 2014-08-21 12:31:20
|
From: "Suzuki K. Poulose" <su...@in...> This patch fixes the conversion of args for paltform-dump call. platform dump passes 64bit values as, a pair of 32bit values. val_hi and val_lo. So when we convert a value 'X' to 32bit hi and lo values in BE, we should follow the below approach : X_hi = htobe32(BITS32_HI(X)) X_lo = htobe32(BITS32_LO(X)) and NOT X_tmp = htobe64(X); X_hi = BITS32_HI(X_tmp), X_lo = BITS32_LO(X_tmp) This patch has been tested with rtas_errd/extract_platdump to retrieve a dump from FSP. Signed-off-by: Suzuki K. Poulose <su...@in...> --- librtas_src/syscall_calls.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 5bd6486..29ab613 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -930,6 +930,7 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, uint32_t kernbuf_pa = 0; uint32_t next_hi, next_lo; uint32_t bytes_hi, bytes_lo; + uint32_t dump_tag_hi, dump_tag_lo; void *kernbuf; int status; int rc; @@ -939,22 +940,29 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, if (rc) return rc; } + /* + * Converting a 64bit host value to 32bit BE, _hi and _lo + * pair is tricky: we should convert the _hi and _lo 32bits + * of the 64bit host value. + */ + dump_tag_hi = htobe32(BITS32_HI(dump_tag)); + dump_tag_lo = htobe32(BITS32_LO(dump_tag)); + + next_hi = htobe32(BITS32_HI(sequence)); + next_lo = htobe32(BITS32_LO(sequence)); - *seq_next = htobe64(sequence); do { - sequence = *seq_next; - rc = sc_rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), - BITS32_LO(htobe64(dump_tag)), - BITS32_HI(sequence), - BITS32_LO(sequence), + rc = sc_rtas_call(token, 6, 5, dump_tag_hi, + dump_tag_lo, + next_hi, + next_lo, htobe32(kernbuf_pa), htobe32(length), &status, &next_hi, &next_lo, &bytes_hi, &bytes_lo); if (rc < 0) break; - - *seq_next = BITS64(next_hi, next_lo); - dbg1("%s: seq_next = 0x%llx\n", __FUNCTION__, *seq_next); + sequence = BITS64(be32toh(next_hi), be32toh(next_lo)); + dbg1("%s: seq_next = 0x%llx\n", __FUNCTION__, sequence); rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); @@ -965,9 +973,10 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, if (kernbuf) (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + *seq_next = sequence; + bytes_hi = be32toh(bytes_hi); + bytes_lo = be32toh(bytes_lo); *bytes_ret = BITS64(bytes_hi, bytes_lo); - *seq_next = be64toh(*seq_next); - *bytes_ret = be64toh(*bytes_ret); dbg1("(0x%llx, 0x%llx, %p, %d, %p, %p) = %d, 0x%llx, 0x%llx\n", dump_tag, sequence, buffer, length, seq_next, bytes_ret, -- 1.8.5.2 |
From: Suzuki K. P. <su...@in...> - 2014-08-21 12:31:17
|
From: "Suzuki K. Poulose" <su...@in...> When we pass _hi and _lo 32bits of a 64bit value, we should convert the host endian value carefully. i.e, X_hi = htobe32(BITS32_HI(X)) X_lo = htobe32(BITS32_LO(X)) and not : X_hi = BITS32_HI(htobe64(X)) NOTE: This patch is untested, but I believe this patch is good to have than the current faulty conversion. This patch fixes all such occurrences in librtas. Signed-off-by: Suzuki K. Poulose <su...@in...> --- librtas_src/syscall_calls.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 29ab613..dc52370 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -532,8 +532,8 @@ int sc_get_config_addr_info2(int token, uint32_t config_addr, do { rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), - BITS32_HI(htobe64(phb_id)), - BITS32_LO(htobe64(phb_id)), + htobe32(BITS32_HI(phb_id)), + htobe32(BITS32_LO(phb_id)), htobe32(func), &status, &be_info); if (rc) break; @@ -1005,8 +1005,8 @@ sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, do { rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), - BITS32_HI(htobe64(phbid)), - BITS32_LO(htobe64(phbid)), &status, + htobe32(BITS32_HI(phbid)), + htobe32(BITS32_LO(phbid)), &status, state, eeh); if (rc) return rc; @@ -1123,8 +1123,8 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) do { rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), - BITS32_HI(htobe64(phbid)), - BITS32_LO(htobe64(phbid)), + htobe32(BITS32_HI(phbid)), + htobe32(BITS32_LO(phbid)), htobe32(function), &status); if (rc) return rc; @@ -1321,8 +1321,8 @@ int sc_suspend_me(int token, uint64_t streamid) int rc; do { - rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), - BITS32_LO(htobe64(streamid)), &status); + rc = sc_rtas_call(token, 2, 1, htobe32(BITS32_HI(streamid)), + htobe32(BITS32_LO(streamid)), &status); if (rc) return rc; -- 1.8.5.2 |
From: Suzuki K. P. <su...@in...> - 2014-08-21 12:31:16
|
From: "Suzuki K. Poulose" <su...@in...> Use rpm macros for standard paths Signed-off-by: Suzuki K. Poulose <su...@in...> --- librtas.spec.in | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/librtas.spec.in b/librtas.spec.in index 54fef89..d35925c 100644 --- a/librtas.spec.in +++ b/librtas.spec.in @@ -34,36 +34,36 @@ the contents of RTAS events. %files %defattr(-, root, root) -/usr/share/doc/packages/%{name}/COPYRIGHT -/usr/share/doc/packages/%{name}/README -/usr/include/common.h -/usr/include/librtas.h -@LIB_DIR@/librtas.so.%{version} -@LIB_DIR@/libofdt.so -@LIB_DIR@/librtas.so -@LIB_DIR@/librtasevent.so -@LIB_DIR@/librtasevent.so.1 -@LIB_DIR@/librtasevent.so.%{version} -/usr/include/librtasevent.h -/usr/include/librtasevent_v4.h -/usr/include/librtasevent_v6.h +%{_docdir}/%{name}/COPYRIGHT +%{_docdir}/%{name}/README +%{_includedir}/common.h +%{_includedir}/librtas.h +%{_libdir}/librtas.so.%{version} +%{_libdir}/libofdt.so +%{_libdir}/librtas.so +%{_libdir}/librtasevent.so +%{_libdir}/librtasevent.so.1 +%{_libdir}/librtasevent.so.%{version} +%{_includedir}/librtasevent.h +%{_includedir}/librtasevent_v4.h +%{_includedir}/librtasevent_v6.h -@LIB_DIR@/libofdt.so.%{version} -/usr/include/libofdt.h +%{_libdir}/libofdt.so.%{version} +%{_includedir}/libofdt.h %post # Post-install script ------------------------------------------------- -ln -sf @LIB_DIR@/librtas.so.%{version} @LIB_DIR@/librtas.so -ln -sf @LIB_DIR@/librtas.so.%{version} @LIB_DIR@/librtas.so.1 -ln -sf @LIB_DIR@/librtasevent.so.%{version} @LIB_DIR@/librtasevent.so -ln -sf @LIB_DIR@/libofdt.so.%{version} @LIB_DIR@/libofdt.so +ln -sf %{_libdir}/librtas.so.%{version} %{_libdir}/librtas.so +ln -sf %{_libdir}/librtas.so.%{version} %{_libdir}/librtas.so.1 +ln -sf %{_libdir}/librtasevent.so.%{version} %{_libdir}/librtasevent.so +ln -sf %{_libdir}/libofdt.so.%{version} %{_libdir}/libofdt.so ldconfig %postun # Post-uninstall script ----------------------------------------------- if [ "$1" = "0" ] ; then # last uninstall - rm -f @LIB_DIR@/librtas.so - rm -f @LIB_DIR@/librtasevent.so - rm -f @LIB_DIR@/libofdt.so + rm -f %{_libdir}/librtas.so + rm -f %{_libdir}/librtasevent.so + rm -f %{_libdir}/libofdt.so fi ldconfig -- 1.8.5.2 |
From: Suzuki K. P. <su...@in...> - 2014-08-21 12:31:15
|
From: Thomas L Falcon <tlf...@li...> Fix LE parsing of SRC/FRU events Changes since V1: * Fix typo in code which causes a crash - Suzuki Signed-off-by: Thomas L Falcon <tlf...@li...> Signed-off-by: Suzuki K. Poulose <su...@in...> --- librtasevent_src/get_rtas_event.c | 5 ----- librtasevent_src/rtas_srcfru.c | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/librtasevent_src/get_rtas_event.c b/librtasevent_src/get_rtas_event.c index efd412f..3a5e034 100644 --- a/librtasevent_src/get_rtas_event.c +++ b/librtasevent_src/get_rtas_event.c @@ -336,12 +336,7 @@ parse_v6_rtas_event(struct rtas_event *re) case RTAS_PSRC_SCN: case RTAS_SSRC_SCN: -#if __BYTE_ORDER == __LITTLE_ENDIAN - fprintf(stderr, "Parsing RTAS SRC Sections on little endian not supported\n"); - rc = -1; -#else rc = parse_src_scn(re); -#endif break; case RTAS_HP_SCN: diff --git a/librtasevent_src/rtas_srcfru.c b/librtasevent_src/rtas_srcfru.c index 1fb1840..6ce9e76 100644 --- a/librtasevent_src/rtas_srcfru.c +++ b/librtasevent_src/rtas_srcfru.c @@ -56,7 +56,7 @@ parse_fru_id_scn(struct rtas_event *re) memset(fru_id, 0, sizeof(*fru_id)); - fru_id_raw = (struct rtas_fru_id_scn_raw *)re->buffer + re->offset; + fru_id_raw = (struct rtas_fru_id_scn_raw *)(re->buffer + re->offset); parse_fru_hdr(&fru_id->fruhdr, &fru_id_raw->fruhdr); re->offset += RE_FRU_HDR_SZ; @@ -105,7 +105,7 @@ parse_fru_pe_scn(struct rtas_event *re) } memset(fru_pe, 0, sizeof(*fru_pe)); - fru_pe_raw = (struct rtas_fru_pe_scn_raw *)re->buffer + re->offset; + fru_pe_raw = (struct rtas_fru_pe_scn_raw *)(re->buffer + re->offset); parse_fru_hdr(&fru_pe->fruhdr, &fru_pe_raw->fruhdr); re->offset += RE_FRU_HDR_SZ; @@ -138,7 +138,7 @@ parse_fru_mr_scn(struct rtas_event *re) } memset(fru_mr, 0, sizeof(*fru_mr)); - fru_mr_raw = (struct rtas_fru_mr_scn_raw *)re->buffer + re->offset; + fru_mr_raw = (struct rtas_fru_mr_scn_raw *)(re->buffer + re->offset); parse_fru_hdr(&fru_mr->fruhdr, &fru_mr_raw->fruhdr); re->offset += RE_FRU_HDR_SZ; @@ -186,17 +186,23 @@ parse_src_scn(struct rtas_event *re) struct rtas_src_scn_raw *src_raw; struct rtas_fru_scn *fru, *last_fru; int total_len, srcsub_len; - src = malloc(sizeof(*src)); if (src == NULL) { errno = ENOMEM; return 1; } + + src_raw = malloc(sizeof(*src_raw)); + if (src_raw == NULL) { + errno = ENOMEM; + return 1; + } memset(src, 0, sizeof(*src)); + memset(src_raw, 0, sizeof(*src_raw)); src->shdr.raw_offset = re->offset; - src_raw = (struct rtas_src_scn_raw *)(re->buffer + re->offset); + rtas_copy(src_raw, re, RE_SRC_SCN_SZ); parse_v6_hdr(&src->v6hdr, &src_raw->v6hdr); src->version = src_raw->version; @@ -216,16 +222,16 @@ parse_src_scn(struct rtas_event *re) memcpy(&src->primary_refcode, &src_raw->primary_refcode, sizeof(src->primary_refcode)); - re->offset += RE_SRC_SCN_SZ; add_re_scn(re, src, re_scn_id(&src_raw->v6hdr)); if (!src_subscns_included(src)) return 0; + rtas_copy( (char *) src_raw + RE_SRC_SCN_SZ + 4, re, RE_SRC_SUBSCN_SZ); + src->subscn_id = src_raw->subscn_id; src->subscn_platform_data = src_raw->subscn_platform_data; src->subscn_length = be16toh(src_raw->subscn_length); - re->offset += RE_SRC_SUBSCN_SZ; srcsub_len = src->subscn_length * 4; /*get number of bytes */ total_len = RE_SRC_SUBSCN_SZ; @@ -236,7 +242,6 @@ parse_src_scn(struct rtas_event *re) uint32_t fru_len, fru_end; struct rtas_fru_hdr *last_fruhdr = NULL; struct rtas_fru_scn_raw *rawfru; - fru = malloc(sizeof(*fru)); if (fru == NULL) { cleanup_rtas_event(re); @@ -245,7 +250,7 @@ parse_src_scn(struct rtas_event *re) } memset(fru, 0, sizeof(*fru)); - + rawfru = (struct rtas_fru_scn_raw *)(re->buffer + re->offset); parse_fru_scn(re, fru, rawfru); -- 1.8.5.2 |
From: Suzuki K. P. <su...@in...> - 2014-08-21 12:31:13
|
From: "Suzuki K. Poulose" <su...@in...> This series : - Adds support for parsinc SRC/FRU events on LE - Fixes variouls librtas stubs for handling LE The series has been tested with various different types of events, except for PRRN. The series applies on top of v1.3.12 tag in the upstream librtas repo. Nathan Fontenot (1): librtasevent: LE support for SRC/FRU events Suzuki K. Poulose (3): librtas: Fix platform_dump for LE [librtas] Minor Spec file changes librtas: Fix conversion of 64bit values for LE Thomas L Falcon (1): librtasevent: Fixes for LE parsing SRC/FRU events librtas.spec.in | 44 +++++++------- librtas_src/syscall_calls.c | 47 +++++++++------ librtasevent_src/get_rtas_event.c | 5 -- librtasevent_src/librtasevent_v6.h | 110 +++++++++++++++++++++++++++-------- librtasevent_src/rtas_srcfru.c | 116 ++++++++++++++++++++++++++++++------- 5 files changed, 232 insertions(+), 90 deletions(-) -- 1.8.5.2 |
From: Suzuki K. P. <su...@in...> - 2014-08-21 12:31:12
|
From: Nathan Fontenot <nf...@li...> LE Support for SRC/FRU events Signed-off-by: Nathan Fontenot <nf...@li...> --- librtasevent_src/librtasevent_v6.h | 110 +++++++++++++++++++++++++++++-------- librtasevent_src/rtas_srcfru.c | 105 +++++++++++++++++++++++++++++------ 2 files changed, 174 insertions(+), 41 deletions(-) diff --git a/librtasevent_src/librtasevent_v6.h b/librtasevent_src/librtasevent_v6.h index 7fdcb17..7097bb0 100644 --- a/librtasevent_src/librtasevent_v6.h +++ b/librtasevent_src/librtasevent_v6.h @@ -267,9 +267,15 @@ struct rtas_lri_scn_raw { struct rtas_fru_hdr { struct rtas_fru_hdr *next; char id[2]; + uint32_t length; + uint32_t flags; +}; + +struct rtas_fru_hdr_raw { + char id[2]; uint32_t length:8; uint32_t flags:8; -}; +}__attribute__((__packed__)); #define RE_FRU_HDR_SZ 4 #define RE_FRU_HDR_OFFSET(x) ((char *)(x) + sizeof(struct rtas_fru_hdr *)) @@ -307,6 +313,16 @@ struct rtas_fru_id_scn { char serial_no[13]; }; +struct rtas_fru_id_scn_raw { + struct rtas_fru_hdr_raw fruhdr; + + /* The following fields may not be present */ + char part_no[8]; + char procedure_id[8]; + char ccin[5]; + char serial_no[13]; +}__attribute__((__packed__)); + /** * @struct rtas_fru_pe_scn * @brief contents of the FRU Power Enclosure Substructure @@ -317,11 +333,22 @@ struct rtas_fru_pe_scn { char pce_name[32]; }; +struct rtas_fru_pe_scn_raw { + struct rtas_fru_hdr_raw fruhdr; + struct rtas_mtms pce_mtms; + char pce_name[32]; +}__attribute__((__packed__)); + /** * @struct fru_mru * @brief FRU MR Description structs */ struct fru_mru { + char priority; + uint32_t id; +}; + +struct fru_mru_raw { uint32_t /* reserved */:24; char priority; uint32_t id; @@ -339,18 +366,24 @@ struct rtas_fru_mr_scn { uint32_t /* reserved */:32; struct fru_mru mrus[15]; }; + +struct rtas_fru_mr_scn_raw { + struct rtas_fru_hdr_raw fruhdr; + uint32_t /* reserved */:32; + struct fru_mru_raw mrus[15]; +}; /** * @struct rtas_v6_fru_scn * @brief RTAS version 6 FRU callout section */ struct rtas_fru_scn { - uint32_t length:8; /**< call-out length */ - uint32_t type:4; /**< callout type */ - uint32_t fru_id_included:1; /**< fru id subsection included */ - uint32_t fru_subscn_included:3; + uint32_t length; /**< call-out length */ + uint32_t type; /**< callout type */ + uint32_t fru_id_included; /**< fru id subsection included */ + uint32_t fru_subscn_included; - char priority; /**< fru priority */ + char priority; /**< fru priority */ #define RTAS_FRU_PRIORITY_HIGH 'H' #define RTAS_FRU_PRIORITY_MEDIUM 'M' #define RTAS_FRU_PRIORITY_MEDIUM_A 'A' @@ -358,12 +391,20 @@ struct rtas_fru_scn { #define RTAS_FRU_PRIORITY_MEDIUM_C 'C' #define RTAS_FRU_PRIORITY_LOW 'L' - uint32_t loc_code_length:8; /**< location field length */ - char loc_code[80]; /**< location code */ + uint32_t loc_code_length; /**< location field length */ + char loc_code[80]; /**< location code */ struct rtas_fru_scn *next; struct rtas_fru_hdr *subscns; }; +struct rtas_fru_scn_raw { + uint32_t length:8; + uint32_t data1:8; + char priority; + uint32_t loc_code_length:8; + char loc_code[80]; +}; + #define RE_FRU_SCN_SZ 4 /** @@ -372,31 +413,54 @@ struct rtas_fru_scn { */ struct rtas_src_scn { struct scn_header shdr; - struct rtas_v6_hdr_raw v6hdr; + struct rtas_v6_hdr v6hdr; - uint32_t version:8; /**< SRC version */ - char src_platform_data[7]; /**< platform specific data */ + uint32_t version; /**< SRC version */ + char src_platform_data[7]; /**< platform specific data */ #define src_subscns_included(src) ((src)->src_platform_data[0] & 0x01) - uint32_t ext_refcode2:32; /**< extended reference code word 2 */ - uint32_t ext_refcode3:32; /**< extended reference code word 3 */ - uint32_t ext_refcode4:32; /**< extended reference code word 4 */ - uint32_t ext_refcode5:32; /**< extended reference code word 5 */ + uint32_t ext_refcode2; /**< extended reference code word 2 */ + uint32_t ext_refcode3; /**< extended reference code word 3 */ + uint32_t ext_refcode4; /**< extended reference code word 4 */ + uint32_t ext_refcode5; /**< extended reference code word 5 */ - uint32_t ext_refcode6:32; /**< extended reference code word 6 */ - uint32_t ext_refcode7:32; /**< extended reference code word 7 */ - uint32_t ext_refcode8:32; /**< extended reference code word 8 */ - uint32_t ext_refcode9:32; /**< extended reference code word 9 */ + uint32_t ext_refcode6; /**< extended reference code word 6 */ + uint32_t ext_refcode7; /**< extended reference code word 7 */ + uint32_t ext_refcode8; /**< extended reference code word 8 */ + uint32_t ext_refcode9; /**< extended reference code word 9 */ - char primary_refcode[36];/**< primary reference code */ + char primary_refcode[36]; /**< primary reference code */ - uint32_t subscn_id:8; /**< sub-section id (0xC0) */ - uint32_t subscn_platform_data:8; /**< platform specific data */ - uint32_t subscn_length:16; /**< sub-section length */ + uint32_t subscn_id; /**< sub-section id (0xC0) */ + uint32_t subscn_platform_data; /**< platform specific data */ + uint32_t subscn_length; /**< sub-section length */ struct rtas_fru_scn *fru_scns; }; +struct rtas_src_scn_raw { + struct rtas_v6_hdr_raw v6hdr; + + uint32_t version:8; + char src_platform_data[7]; + + uint32_t ext_refcode2:32; + uint32_t ext_refcode3:32; + uint32_t ext_refcode4:32; + uint32_t ext_refcode5:32; + + uint32_t ext_refcode6:32; + uint32_t ext_refcode7:32; + uint32_t ext_refcode8:32; + uint32_t ext_refcode9:32; + + char primary_refcode[36]; + + uint32_t subscn_id:8; + uint32_t subscn_platform_data:8; + uint32_t subscn_length:16; +}; + #define RE_SRC_SCN_SZ 80 #define RE_SRC_SUBSCN_SZ 4 diff --git a/librtasevent_src/rtas_srcfru.c b/librtasevent_src/rtas_srcfru.c index c757999..1fb1840 100644 --- a/librtasevent_src/rtas_srcfru.c +++ b/librtasevent_src/rtas_srcfru.c @@ -19,6 +19,23 @@ #include "rtas_src_codes.c" /** + * parse_fru_hdr + * @brief Parse the ontents of a FRU header + * + * @param fru_hdr rtas_fru_hdr pointer + * @param fru_hdr_raw rtas_fru_hdr_raw pointer + */ +static void parse_fru_hdr(struct rtas_fru_hdr *fru_hdr, + struct rtas_fru_hdr_raw *fru_hdr_raw) +{ + fru_hdr->id[0] = fru_hdr_raw->id[0]; + fru_hdr->id[1] = fru_hdr_raw->id[1]; + + fru_hdr->length = fru_hdr_raw->length; + fru_hdr->flags = fru_hdr_raw->flags; +} + +/** * parse_fru_id_scn * @brief Parse a FRU Identity Substructure * @@ -29,6 +46,7 @@ static struct rtas_fru_hdr * parse_fru_id_scn(struct rtas_event *re) { struct rtas_fru_id_scn *fru_id; + struct rtas_fru_id_scn_raw *fru_id_raw; fru_id = malloc(sizeof(*fru_id)); if (fru_id == NULL) { @@ -37,7 +55,10 @@ parse_fru_id_scn(struct rtas_event *re) } memset(fru_id, 0, sizeof(*fru_id)); - rtas_copy(RE_FRU_HDR_OFFSET(fru_id), re, RE_FRU_HDR_SZ); + + fru_id_raw = (struct rtas_fru_id_scn_raw *)re->buffer + re->offset; + parse_fru_hdr(&fru_id->fruhdr, &fru_id_raw->fruhdr); + re->offset += RE_FRU_HDR_SZ; if (fruid_has_part_no(fru_id)) { strcpy(fru_id->part_no, RE_EVENT_OFFSET(re)); @@ -73,6 +94,7 @@ static struct rtas_fru_hdr * parse_fru_pe_scn(struct rtas_event *re) { struct rtas_fru_pe_scn *fru_pe; + struct rtas_fru_pe_scn_raw *fru_pe_raw; uint32_t scn_sz; char *data; @@ -83,7 +105,9 @@ parse_fru_pe_scn(struct rtas_event *re) } memset(fru_pe, 0, sizeof(*fru_pe)); - rtas_copy(RE_FRU_HDR_OFFSET(fru_pe), re, RE_FRU_HDR_SZ); + fru_pe_raw = (struct rtas_fru_pe_scn_raw *)re->buffer + re->offset; + parse_fru_hdr(&fru_pe->fruhdr, &fru_pe_raw->fruhdr); + re->offset += RE_FRU_HDR_SZ; scn_sz = fru_pe->fruhdr.length; data = (char *)fru_pe + sizeof(fru_pe->fruhdr); @@ -104,8 +128,8 @@ static struct rtas_fru_hdr * parse_fru_mr_scn(struct rtas_event *re) { struct rtas_fru_mr_scn *fru_mr; - uint32_t scn_sz; - char *data; + struct rtas_fru_mr_scn_raw *fru_mr_raw; + int i, mrus_sz, num_mrus; fru_mr = malloc(sizeof(*fru_mr)); if (fru_mr == NULL) { @@ -114,16 +138,39 @@ parse_fru_mr_scn(struct rtas_event *re) } memset(fru_mr, 0, sizeof(*fru_mr)); - rtas_copy(RE_FRU_HDR_OFFSET(fru_mr), re, RE_FRU_HDR_SZ); + fru_mr_raw = (struct rtas_fru_mr_scn_raw *)re->buffer + re->offset; + parse_fru_hdr(&fru_mr->fruhdr, &fru_mr_raw->fruhdr); + re->offset += RE_FRU_HDR_SZ; - scn_sz = fru_mr->fruhdr.length; - data = (char *)fru_mr + sizeof(fru_mr->fruhdr); - - rtas_copy(data, re, scn_sz - RE_FRU_HDR_SZ); + mrus_sz = fru_mr->fruhdr.length - RE_FRU_HDR_SZ - sizeof(uint32_t); + num_mrus = mrus_sz / sizeof(struct fru_mru_raw); + + for (i = 0; i < num_mrus; i++) { + fru_mr->mrus[i].priority = fru_mr_raw->mrus[i].priority; + fru_mr->mrus[i].id = be32toh(fru_mr_raw->mrus[i].id); + } + re->offset += mrus_sz + sizeof(uint32_t) /* reserved piece */; return (struct rtas_fru_hdr *)fru_mr; } +void parse_fru_scn(struct rtas_event *re, struct rtas_fru_scn *fru, + struct rtas_fru_scn_raw *rawfru) +{ + fru->length = rawfru->length; + + fru->type = (rawfru->data1 & 0xf0) >> 4; + fru->fru_id_included = (rawfru->data1 & 0x08) >> 3; + fru->fru_subscn_included = rawfru->data1 & 0x07; + + fru->priority = rawfru->priority; + fru->loc_code_length = rawfru->loc_code_length; + re->offset += RE_FRU_SCN_SZ; + + memcpy(fru->loc_code, rawfru->loc_code, fru->loc_code_length); + re->offset += fru->loc_code_length; +} + /** * parse_v6_src_scn * @brief parse a version 6 rtas SRC section @@ -136,6 +183,7 @@ int parse_src_scn(struct rtas_event *re) { struct rtas_src_scn *src; + struct rtas_src_scn_raw *src_raw; struct rtas_fru_scn *fru, *last_fru; int total_len, srcsub_len; @@ -148,13 +196,36 @@ parse_src_scn(struct rtas_event *re) memset(src, 0, sizeof(*src)); src->shdr.raw_offset = re->offset; - rtas_copy(RE_SHDR_OFFSET(src), re, RE_SRC_SCN_SZ); - add_re_scn(re, src, re_scn_id(&src->v6hdr)); + src_raw = (struct rtas_src_scn_raw *)(re->buffer + re->offset); + parse_v6_hdr(&src->v6hdr, &src_raw->v6hdr); - if (! src_subscns_included(src)) + src->version = src_raw->version; + memcpy(&src->src_platform_data, &src_raw->src_platform_data, + sizeof(src->src_platform_data)); + + src->ext_refcode2 = be32toh(src_raw->ext_refcode2); + src->ext_refcode3 = be32toh(src_raw->ext_refcode3); + src->ext_refcode4 = be32toh(src_raw->ext_refcode4); + src->ext_refcode5 = be32toh(src_raw->ext_refcode5); + + src->ext_refcode6 = be32toh(src_raw->ext_refcode6); + src->ext_refcode7 = be32toh(src_raw->ext_refcode7); + src->ext_refcode8 = be32toh(src_raw->ext_refcode8); + src->ext_refcode9 = be32toh(src_raw->ext_refcode9); + + memcpy(&src->primary_refcode, &src_raw->primary_refcode, + sizeof(src->primary_refcode)); + + re->offset += RE_SRC_SCN_SZ; + add_re_scn(re, src, re_scn_id(&src_raw->v6hdr)); + + if (!src_subscns_included(src)) return 0; - rtas_copy(RE_SHDR_OFFSET(src) + RE_SRC_SCN_SZ + 4, re, RE_SRC_SUBSCN_SZ); + src->subscn_id = src_raw->subscn_id; + src->subscn_platform_data = src_raw->subscn_platform_data; + src->subscn_length = be16toh(src_raw->subscn_length); + re->offset += RE_SRC_SUBSCN_SZ; srcsub_len = src->subscn_length * 4; /*get number of bytes */ total_len = RE_SRC_SUBSCN_SZ; @@ -164,6 +235,7 @@ parse_src_scn(struct rtas_event *re) do { uint32_t fru_len, fru_end; struct rtas_fru_hdr *last_fruhdr = NULL; + struct rtas_fru_scn_raw *rawfru; fru = malloc(sizeof(*fru)); if (fru == NULL) { @@ -174,11 +246,8 @@ parse_src_scn(struct rtas_event *re) memset(fru, 0, sizeof(*fru)); - /* First the fixed part of the fru */ - rtas_copy(fru, re, RE_FRU_SCN_SZ); - - /* Then the variable length location string */ - rtas_copy(fru->loc_code, re, fru->loc_code_length); + rawfru = (struct rtas_fru_scn_raw *)(re->buffer + re->offset); + parse_fru_scn(re, fru, rawfru); fru_len = RE_FRU_SCN_SZ + fru->loc_code_length; fru_end = re->offset + fru->length - fru_len; -- 1.8.5.2 |
From: Vasant H. <heg...@li...> - 2014-08-01 10:36:33
|
On 07/14/2014 04:26 PM, Anshuman Khandual wrote: > This patch handles big endian location code length data in little endian > platform. This enables the tools to work on little endian platform after > having passed big endian buffer data. > > Signed-off-by: Anshuman Khandual <kha...@li...> Reviewed-by: Vasant Hegde <heg...@li...> -Vasant |