librtas-devel Mailing List for librtas (Page 3)
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: Nathan F. <nf...@li...> - 2014-07-24 15:40:46
|
Yes, this will be in the next release. -Nathan On 07/24/2014 01:12 AM, Suzuki K. Poulose wrote: > On 07/14/2014 04:20 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...> > > Nathan, > > We need the patch below for the LE support for lpd. Please pick this up. > > Thanks > Suzuki > >> --- >> librtas_src/syscall_calls.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c >> index 01d6ce8..da8f25b 100644 >> --- a/librtas_src/syscall_calls.c >> +++ b/librtas_src/syscall_calls.c >> @@ -568,7 +568,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) >> int status; >> int rc; >> >> - size = *(uint32_t *)loc_code + sizeof(uint32_t); >> + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); >> >> rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); >> if (rc) >> @@ -1074,7 +1074,7 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, >> int status; >> int rc; >> >> - size = *(uint32_t *)loc_code + sizeof(uint32_t); >> + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); >> >> rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); >> if (rc) >> > > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > Librtas-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/librtas-devel > |
From: Suzuki K. P. <su...@in...> - 2014-07-24 06:13:00
|
On 07/14/2014 04:20 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...> Nathan, We need the patch below for the LE support for lpd. Please pick this up. Thanks Suzuki > --- > librtas_src/syscall_calls.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c > index 01d6ce8..da8f25b 100644 > --- a/librtas_src/syscall_calls.c > +++ b/librtas_src/syscall_calls.c > @@ -568,7 +568,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) > int status; > int rc; > > - size = *(uint32_t *)loc_code + sizeof(uint32_t); > + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); > > rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); > if (rc) > @@ -1074,7 +1074,7 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, > int status; > int rc; > > - size = *(uint32_t *)loc_code + sizeof(uint32_t); > + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); > > rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); > if (rc) > |
From: Thomas F. <tlf...@li...> - 2014-07-16 21:34:17
|
Since the procfs and common interfaces are being removed, all rtas calls will be fully implemented in the syscall_calls.c and syscall_rmo.c files. Signed-off-by: Thomas Falcon <tlf...@li...> --- Forgot to make some changes in syscall_calls.c that I made in syscall_rmo.c --- librtas_src/syscall.h | 6 +- librtas_src/syscall_calls.c | 745 ++++++++++++++++++++++++-------------------- librtas_src/syscall_rmo.c | 57 +++- 3 files changed, 462 insertions(+), 346 deletions(-) diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index 32bffbd..d5da539 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -36,9 +36,9 @@ struct region { struct region *next; }; -extern int sc_get_rmo_buffer(size_t size, void **buf, uint32_t *phys_addr); -extern int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size); -extern int sc_interface_exists(); +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(); #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 01d6ce8..a3a5f52 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -13,96 +13,11 @@ #include <string.h> #include <errno.h> #include <sys/syscall.h> -#include <unistd.h> #include <linux/unistd.h> #include <linux/types.h> -#include "common.h" #include "syscall.h" #include "librtas.h" -int sc_activate_firmware(int token); -int sc_cfg_connector(int token, char *workarea); -int sc_delay_timeout(uint64_t timeout_ms); -int sc_display_char(int token, char c); -int sc_display_msg(int token, char *buf); -int sc_errinjct(int token, int etoken, int otoken, char *workarea); -int sc_errinjct_close(int token, int otoken); -int sc_errinjct_open(int token, int *otoken); -int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state); -int sc_get_config_addr_info2(int token, uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info); -int sc_get_indices(int token, int is_sensor, int type, char *workarea, - size_t size, int start, int *next); -int sc_get_power_level(int token, int powerdomain, int *level); -int sc_get_sensor(int token, int sensor, int index, int *state); -int sc_get_sysparm(int token, unsigned int parameter, unsigned int length, - char *data); -int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, - uint32_t *hour, uint32_t *min, uint32_t *sec, uint32_t *nsec); -int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, - unsigned int sequence, unsigned int *seq_next, - unsigned int *bytes_ret); -int sc_lpar_perftools(int token, int subfunc, char *workarea, - unsigned int length, unsigned int sequence, - unsigned int *seq_next); -int sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, - void *buffer, size_t length, uint64_t * next_seq, - uint64_t * bytes_ret); -int sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, - int *state, int *eeh); -int sc_scan_log_dump(int token, void *buffer, size_t length); -int sc_set_dynamic_indicator(int token, int indicator, int new_value, - void *loc_code); -int sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, - int function); -int sc_set_indicator(int token, int indicator, int index, int new_value); -int sc_set_power_level(int token, int powerdomain, int level, int *setlevel); -int sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, - uint32_t nsec); -int sc_set_sysparm(int token, unsigned int parameter, char *data); -int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, - uint32_t nsec); -int sc_suspend_me(int token, uint64_t streamid); -int sc_update_nodes(int token, char *workarea, unsigned int scope); -int sc_update_properties(int token, char *workarea, unsigned int scope); - -struct rtas_operations syscall_rtas_ops = { - .activate_firmware = sc_activate_firmware, - .cfg_connector = sc_cfg_connector, - .delay_timeout = sc_delay_timeout, - .display_char = sc_display_char, - .display_msg = sc_display_msg, - .errinjct = sc_errinjct, - .errinjct_close = sc_errinjct_close, - .errinjct_open = sc_errinjct_open, - .free_rmo_buffer = sc_free_rmo_buffer, - .get_config_addr_info2 = sc_get_config_addr_info2, - .get_dynamic_sensor = sc_get_dynamic_sensor, - .get_indices = sc_get_indices, - .get_sensor = sc_get_sensor, - .get_power_level = sc_get_power_level, - .get_rmo_buffer = sc_get_rmo_buffer, - .get_sysparm = sc_get_sysparm, - .get_time = sc_get_time, - .get_vpd = sc_get_vpd, - .lpar_perftools = sc_lpar_perftools, - .platform_dump = sc_platform_dump, - .read_slot_reset = sc_read_slot_reset, - .scan_log_dump = sc_scan_log_dump, - .set_dynamic_indicator = sc_set_dynamic_indicator, - .set_indicator = sc_set_indicator, - .set_eeh_option = sc_set_eeh_option, - .set_power_level = sc_set_power_level, - .set_poweron_time = sc_set_poweron_time, - .set_sysparm = sc_set_sysparm, - .set_time = sc_set_time, - .suspend_me = sc_suspend_me, - .update_nodes = sc_update_nodes, - .update_properties = sc_update_properties, - .interface_exists = sc_interface_exists, -}; - /* The original librtas used the _syscall1 interface to get to the rtas * system call. On recent versions of Linux though the _syscall1 * interface was removed from unistd.h so we have moved to using the @@ -115,6 +30,8 @@ _syscall1(int, rtas, void *, args); #define CALL_AGAIN 1 +struct librtas_config config = { NULL, 0 }; + /** * handle_delay * @brief sleep for the specified delay time @@ -163,7 +80,7 @@ static unsigned int handle_delay(int status, uint64_t * elapsed) * display_rtas_buf * @brief Dump the contents of the rtas call buffer * - * @param args + * @param args * @param after */ static void display_rtas_buf(struct rtas_args *args, int after) @@ -196,10 +113,10 @@ static void display_rtas_buf(struct rtas_args *args, int after) } /** - * sc_rtas_call + * rtas_call * @brief Perform the actual system call for the rtas call - * - * Variable argument list consists of inputs followed by + * + * Variable argument list consists of inputs followed by * pointers to outputs. * * @param token @@ -207,7 +124,7 @@ 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 sc_rtas_call(int token, int ninputs, int nret, ...) +static int rtas_call(int token, int ninputs, int nret, ...) { struct rtas_args args; rtas_arg_t *rets[MAX_ARGS]; @@ -254,20 +171,24 @@ static int sc_rtas_call(int token, int ninputs, int nret, ...) } /** - * sc_activate_firmware - * @brief Set up the activate-firmware rtas system call + * rtas_activate_firmware + * @brief Interface for ibm,activate-firmware rtas call * - * @param token - * @return 0 on success, !0 otherwise + * @return 0 on success, !0 on failure */ -int sc_activate_firmware(int token) +int rtas_activate_firmware() { + SANITY_CHECKS(); uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,activate-firmware"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 0, 1, &status); + rc = rtas_call(token, 0, 1, &status); if (rc) return rc; @@ -282,15 +203,15 @@ int sc_activate_firmware(int token) #define CFG_RC_MEM 5 /** - * sc_cfg_connector - * @brief Set up the cfg-connector rtas system call + * rtas_cfg_connector + * @brief Interface for ibm,configure-connector rtas call * - * @param token - * @param workarea - * @return 0 on success, !0 otherwise + * @param workarea buffer containg args to ibm,configure-connector + * @return 0 on success, !0 on failure */ -int sc_cfg_connector(int token, char *workarea) +int rtas_cfg_connector(char *workarea) { + SANITY_CHECKS(); uint32_t workarea_pa; uint32_t extent_pa = 0; uint64_t elapsed = 0; @@ -298,21 +219,25 @@ int sc_cfg_connector(int token, char *workarea) void *extent; int status; int rc; + int token = rtas_token("ibm,configure-connector"); + + if (token < 0) + return token; - rc = sc_get_rmo_buffer(PAGE_SIZE, &kernbuf, &workarea_pa); + rc = rtas_get_rmo_buffer(PAGE_SIZE, &kernbuf, &workarea_pa); if (rc) return rc; memcpy(kernbuf, workarea, PAGE_SIZE); do { - rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + rc = rtas_call(token, 2, 1, htobe32(workarea_pa), htobe32(extent_pa), &status); if (rc < 0) break; - + if ((rc == 0) && (status == CFG_RC_MEM)) { - rc = sc_get_rmo_buffer(PAGE_SIZE, &extent, &extent_pa); + rc = rtas_get_rmo_buffer(PAGE_SIZE, &extent, &extent_pa); if (rc < 0) break; continue; @@ -324,45 +249,50 @@ int sc_cfg_connector(int token, char *workarea) if (rc == 0) memcpy(workarea, kernbuf, PAGE_SIZE); - (void)sc_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); if (extent_pa) - (void)sc_free_rmo_buffer(extent, extent_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(extent, extent_pa, PAGE_SIZE); dbg1("(%p) = %d\n", workarea, rc ? rc : status); return rc ? rc : status; } /** - * sc_delay_timeout - * @brief set the configured timeout value + * rtas_delay_timeout + * @brief Interface to retrieve the rtas timeout delay * - * @param timeout_ms new timeout in milliseconds - * @return 0 on success, !0 otherwise + * @param timeout_ms timeout in milli-seconds + * @return delay time */ -int sc_delay_timeout(uint64_t timeout_ms) +int rtas_delay_timeout(uint64_t timeout_ms) { + SANITY_CHECKS(); config.rtas_timeout_ms = timeout_ms; return 0; } /** - * sc_display_char - * @brief Set up display-char rtas system call - * - * @param token + * rtas_display_char + * @brief Interface for display-character rtas call + * * @param c character to display * @return 0 on success, !0 otherwise */ -int sc_display_char(int token, char c) +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 = sc_rtas_call(token, 1, 1, c, &status); + rc = rtas_call(token, 1, 1, c, &status); if (rc) return rc; @@ -374,39 +304,43 @@ int sc_display_char(int token, char c) } /** - * sc_display_msg - * @brief Set up the display-message rtas system call + * rtas_display_msg + * @brief Interface for ibm,display-message rtas call * - * @param token * @param buf message to display * @return 0 on success, !0 otherwise */ -int sc_display_msg(int token, char *buf) +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; str_len = strlen(buf); - rc = sc_get_rmo_buffer(str_len, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(str_len, &kernbuf, &kernbuf_pa); if (rc) return rc; strcpy(kernbuf, buf); do { - rc = sc_rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); + rc = rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); if (rc < 0) break; rc = handle_delay(status, &elapsed); } while ((rc == CALL_AGAIN)); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, str_len); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, str_len); dbg1("(%p) = %d\n", buf, rc ? rc : status); return rc ? rc : status; @@ -415,31 +349,35 @@ int sc_display_msg(int token, char *buf) #define ERRINJCT_BUF_SIZE 1024 /** - * sc_errinjct - * @brief Set up the errinjct rtas system call + * rtas_errinjct + * @brief Interface to the ibm,errinjct rtas call * - * @param token - * @param etoken error injection token - * @param otoken error injection open token - * @param workarea additional args to rtas call + * @param etoken errinjct token + * @param otoken errinjct open token + * @param workarea additional args to ibm,errinjct * @return 0 on success, !0 otherwise */ -int sc_errinjct(int token, int etoken, int otoken, char *workarea) +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"); - rc = sc_get_rmo_buffer(ERRINJCT_BUF_SIZE, &kernbuf, &kernbuf_pa); + if (token < 0) + return token; + + rc = rtas_get_rmo_buffer(ERRINJCT_BUF_SIZE, &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, workarea, ERRINJCT_BUF_SIZE); do { - rc = sc_rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), + rc = rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), htobe32(kernbuf_pa), &status); if (rc < 0 ) break; @@ -450,28 +388,32 @@ int sc_errinjct(int token, int etoken, int otoken, char *workarea) if (rc == 0) memcpy(workarea, kernbuf, ERRINJCT_BUF_SIZE); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, ERRINJCT_BUF_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, ERRINJCT_BUF_SIZE); dbg1("(%d, %d, %p) = %d\n", etoken, otoken, workarea, rc ? rc : status); return rc ? rc : status; } /** - * sc_errinjct_close - * @brief Set up the errinjct close rtas system call + * rtas_errinjct_close + * @brief Inerface to close the ibm,errinjct facility * - * @param token * @param otoken errinjct open token * @return 0 on success, !0 otherwise */ -int sc_errinjct_close(int token, int otoken) +int rtas_errinjct_close(int otoken) { + SANITY_CHECKS(); uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,close-errinjct"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 1, 1, htobe32(otoken), &status); + rc = rtas_call(token, 1, 1, htobe32(otoken), &status); if (rc) return rc; @@ -483,22 +425,29 @@ int sc_errinjct_close(int token, int otoken) } /** - * sc_errinjct_open - * @brief Set up the errinjct open rtas system call + * rtas_errinjct_open + * @brief Interface to open the ibm,errinjct facility * - * @param token - * @param otoken + * This call will set the value refrenced by otoken to the open token + * for the ibm,errinjct facility + * + * @param otoken pointer to open token * @return 0 on success, !0 otherwise */ -int sc_errinjct_open(int token, 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; do { - rc = sc_rtas_call(token, 0, 2, &be_otoken, &status); + rc = rtas_call(token, 0, 2, &be_otoken, &status); if (rc) return rc; @@ -512,26 +461,32 @@ int sc_errinjct_open(int token, int *otoken) } /** - * sc_get_config_addr2 - * @brief get the pci slot config address + * rtas_get_config_addr_info2 + * @brief Interface to ibm,get-config-addr-info2 rtas call + * + * On successful completion the info value is returned. * - * @param token * @param config_addr - * @param phb_unit_id - * @param func + * @param PHB_Unit_ID + * @param function * @param info * @return 0 on success, !0 otherwise */ -int sc_get_config_addr_info2(int token, uint32_t config_addr, +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; do { - rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), + rc = rtas_call(token, 4, 2, htobe32(config_addr), BITS32_HI(htobe64(phb_id)), BITS32_LO(htobe64(phb_id)), htobe32(func), &status, &be_info); @@ -549,17 +504,20 @@ int sc_get_config_addr_info2(int token, uint32_t config_addr, } /** - * sc_get_dynamic_sensor - * @brief Set up the get-dynamic-sensor rtas system call + * rtas_get_dynamic_sensor + * @brief Interface to ibm,get-dynamic-sensor-state rtas call * - * @param token - * @param sensor - * @param loc_code - * @param state + * On success the variable referenced by the state parameter will contain + * the state of the sensor + * + * @param sensor sensor to retrieve + * @param loc_code location code of the sensor + * @param state reference to state variable * @return 0 on success, !0 otherwise */ -int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) +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; @@ -567,17 +525,21 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) __be32 be_state; int status; int rc; + int token = rtas_token("ibm,get-dynamic-sensor-state"); + + if (token < 0) + return token; size = *(uint32_t *)loc_code + sizeof(uint32_t); - rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); + rc = rtas_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) return rc; memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), + rc = rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), &status, &be_state); if (rc < 0) break; @@ -585,7 +547,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - (void) sc_free_rmo_buffer(locbuf, loc_pa, size); + (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); *state = be32toh(be_state); @@ -595,35 +557,39 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) } /** - * sc_get_indices - * @brief Set up the get-indices rtas system call + * rtas_get_indices + * @brief Interface to the ibm,get-indices rtas call * - * @param token - * @param is_sensor + * @param is_sensor is this index a sensor? * @param type - * @param workarea + * @param workarea additional args to the rtas call * @param size * @param start * @param next * @return 0 on success, !0 otherwise */ int -sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, +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"); - rc = sc_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); - if (rc) + if (token < 0) + return token; + + rc = rtas_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); + if (rc) return rc; do { - rc = sc_rtas_call(token, 5, 2, htobe32(is_sensor), + rc = rtas_call(token, 5, 2, htobe32(is_sensor), htobe32(type), htobe32(kernbuf_pa), htobe32(size), htobe32(start), &status, &be_next); @@ -636,7 +602,7 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, if (rc == 0) memcpy(workarea, kernbuf, size); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, size); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, size); *next = be32toh(be_next); @@ -646,23 +612,30 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, } /** - * sc_get_power_level - * @brief Set up the get-power-level rtas system call + * rtas_get_power_level + * @brief Interface to the get-power-level rtas call + * + * On success this routine will set the variable referenced by the level + * parameter to the power level * - * @param token * @param powerdomain - * @param level + * @param level reference to the power level variable * @return 0 on success, !0 otherwise */ -int sc_get_power_level(int token, int powerdomain, int *level) +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 = sc_rtas_call(token, 1, 2, htobe32(powerdomain), + rc = rtas_call(token, 1, 2, htobe32(powerdomain), &status, &be_level); if (rc) return rc; @@ -678,24 +651,31 @@ int sc_get_power_level(int token, int powerdomain, int *level) } /** - * sc_get_sensor - * @brief Set up the get-sensor rtas system call + * rtas_get_sensor + * @brief Interface to the get-sensor-state rtas call + * + * On successful completion the state parameter will reference the current + * state of the sensor * - * @param token * @param sensor - * @param index - * @param state + * @param index sensor index + * @param state reference to state variable * @return 0 on success, !0 otherwise */ -int sc_get_sensor(int token, int sensor, int index, int *state) +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 = sc_rtas_call(token, 2, 2, htobe32(sensor), + rc = rtas_call(token, 2, 2, htobe32(sensor), htobe32(index), &status, &be_state); if (rc) return rc; @@ -711,31 +691,38 @@ int sc_get_sensor(int token, int sensor, int index, int *state) } /** - * sc_get_sysparm - * @brief Setup the get-system-parameter rtas system call + * rtas_get_sysparm + * @brief Interface to the ibm,get-system-parameter rtas call * - * @param token - * @param parameter - * @param length - * @param data + * On successful completion the data parameter will contain the system + * parameter results + * + * @param parameter system parameter to retrieve + * @param length data buffer length + * @param data reference to buffer to return parameter in * @return 0 on success, !0 otherwise */ int -sc_get_sysparm(int token, unsigned int parameter, unsigned int length, +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; - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; do { - rc = sc_rtas_call(token, 3, 1, htobe32(parameter), + rc = rtas_call(token, 3, 1, htobe32(parameter), htobe32(kernbuf_pa), htobe32(length), &status); if (rc < 0) @@ -747,17 +734,19 @@ sc_get_sysparm(int token, unsigned int parameter, unsigned int length, if (rc == 0) memcpy(data, kernbuf, length); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); dbg1("(%d, %d, %p) = %d\n", parameter, length, data, rc ? rc : status); return rc ? rc : status; } /** - * sc_get_time - * @brief Set up the get-time rtas system call + * rtas_get_time + * @brief Interface to get-time-of-day rtas call + * + * On successful completion all of the parameters will be filled with + * their respective values for the current time of day. * - * @param token * @param year * @param month * @param day @@ -767,15 +756,20 @@ sc_get_sysparm(int token, unsigned int parameter, unsigned int length, * @param nsec * @return 0 on success, !0 otherwise */ -int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, +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 = sc_rtas_call(token, 0, 8, &status, year, month, day, hour, + rc = rtas_call(token, 0, 8, &status, year, month, day, hour, min, sec, nsec); if (rc) return rc; @@ -797,21 +791,22 @@ int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, } /** - * sc_get_vpd + * rtas_get_vpd + * @brief Interface to the ibm,get-vpd rtas call * - * @param token - * @param loc_code - * @param workarea + * @param loc_code location code + * @param workarea additional args to rtas call * @param size * @param sequence * @param seq_next * @param bytes_ret * @return 0 on success, !0 otherwise */ -int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, - unsigned int sequence, unsigned int *seq_next, +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; @@ -821,8 +816,12 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, void *locbuf; int status; int rc; - - rc = sc_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); + int token = rtas_token("ibm,get-vpd"); + + if (token < 0) + return token; + + rc = rtas_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); if (rc) return rc; kernbuf = rmobuf + PAGE_SIZE; @@ -832,55 +831,60 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, /* If user didn't set loc_code, copy a NULL string */ strncpy(locbuf, loc_code ? loc_code : "", PAGE_SIZE); - + *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 4, 3, htobe32(loc_pa), + rc = rtas_call(token, 4, 3, htobe32(loc_pa), htobe32(kernbuf_pa), htobe32(size), sequence, &status, seq_next, bytes_ret); if (rc < 0) break; - + rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - + if (rc == 0) memcpy(workarea, kernbuf, size); - (void) sc_free_rmo_buffer(rmobuf, rmo_pa, size + PAGE_SIZE); - + (void) rtas_free_rmo_buffer(rmobuf, rmo_pa, size + PAGE_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", - workarea, size, sequence, status, *seq_next, *bytes_ret); - return rc ? rc : status; + workarea, size, sequence, status, *seq_next, *bytes_ret); + return rc ? rc : status; } /** - * sc_lpar_perftools + * rtas_lpar_perftools + * @brief Interface to the ibm,lpa-perftools rtas call * - * @param token * @param subfunc - * @param workarea + * @param workarea additional args to the rtas call * @param length * @param sequence * @param seq_next * @return 0 on success, !0 otherwise */ -int sc_lpar_perftools(int token, int subfunc, char *workarea, +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 status; int rc; + int token = rtas_token("ibm,lpar-perftools"); + + if (token < 0) + return token; - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -889,7 +893,7 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 5, 2, htobe32(subfunc), 0, + rc = rtas_call(token, 5, 2, htobe32(subfunc), 0, htobe32(kernbuf_pa), htobe32(length), sequence, &status, seq_next); if (rc < 0) @@ -901,7 +905,7 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, if (rc == 0) memcpy(workarea, kernbuf, length); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); *seq_next = be32toh(*seq_next); @@ -909,23 +913,23 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, length, sequence, seq_next, rc ? rc : status, *seq_next); return rc ? rc : status; } - /** - * sc_platform_dump + * rtas_platform_dump + * Interface to the ibm,platform-dump rtas call * - * @param token * @param dump_tag * @param sequence - * @param buffer - * @param length - * @param seq_next + * @param buffer buffer to write dump to + * @param length buffer length + * @param next_seq * @param bytes_ret - * @return 0 on success, !0 otherwise + * @return 0 on success, !0 othwerwise */ int -sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, +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; @@ -933,9 +937,13 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, void *kernbuf; int status; int rc; + int token = rtas_token("ibm,platform-dump"); + + if (token < 0) + return token; if (buffer) { - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; } @@ -943,7 +951,7 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, *seq_next = htobe64(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), + rc = rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), BITS32_LO(htobe64(dump_tag)), BITS32_HI(sequence), BITS32_LO(sequence), @@ -952,7 +960,7 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, &bytes_lo); if (rc < 0) break; - + *seq_next = BITS64(next_hi, next_lo); dbg1("%s: seq_next = 0x%llx\n", __FUNCTION__, *seq_next); @@ -961,9 +969,9 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, if (buffer && (rc == 0)) memcpy(buffer, kernbuf, length); - + if (kernbuf) - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); next_hi = be32toh(next_hi); next_lo = be32toh(next_lo); @@ -979,26 +987,30 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, } /** - * sc_read_slot_reset - * @brief Set up the read-slot-reset-state rtas system call + * rtas_read_slot_reset + * @brief Interface to the ibm,read-slot-reset-state rtas call * - * @param token * @param cfg_addr configuration address of slot to read - * @param phbid PHB ID of slot to read - * @param state + * @param phbid PHB ID of the slot to read + * @param state reference to variable to return slot state in * @param eeh * @return 0 on success, !0 otherwise */ int -sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, +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; do { - rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), + rc = rtas_call(token, 3, 3, htobe32(cfg_addr), BITS32_HI(htobe64(phbid)), BITS32_LO(htobe64(phbid)), &status, state, eeh); @@ -1017,28 +1029,33 @@ sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, } /** - * sc_scan_log_dump + * rtas_scan_log_dump + * @brief Interface to the ibm,scan-log-dump rtas call * - * @param token - * @param buffer - * @param length + * @param buffer buffer to return scan log dump in + * @param length size of buffer * @return 0 on success, !0 otherwise */ -int sc_scan_log_dump(int token, void *buffer, size_t length) +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"); - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + if (token < 0) + return token; + + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, buffer, length); do { - rc = sc_rtas_call(token, 2, 1, htobe32(kernbuf_pa), + rc = rtas_call(token, 2, 1, htobe32(kernbuf_pa), htobe32(length), &status); if (rc < 0) break; @@ -1049,41 +1066,60 @@ int sc_scan_log_dump(int token, void *buffer, size_t length) if (rc == 0) memcpy(buffer, kernbuf, length); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); dbg1("(%p, %d) = %d\n", buffer, length, rc ? rc : status); return rc ? rc : status; } /** - * sc_set_dynamic_indicator + * rtas_set_debug + * @brief Interface to set librtas debug level * - * @param token - * @param indicator - * @param new_value + * @param level debug level to set to + * @return 0 on success, !0 otherwise + */ +int rtas_set_debug(int level) +{ + config.debug = level; + + return 0; +} + +/** + * rtas_set_dynamic_indicator + * @brief Interface to the ibm,set-dynamic-indicator rtas call + * + * @param indicator indicator to set + * @param new_value value to set the indicator to * @param loc_code * @return 0 on success, !0 otherwise */ -int sc_set_dynamic_indicator(int token, int indicator, int new_value, +int rtas_set_dynamic_indicator(int indicator, int new_value, void *loc_code) { + 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; size = *(uint32_t *)loc_code + sizeof(uint32_t); - rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); + rc = rtas_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) return rc; memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 3, 1, htobe32(indicator), + rc = rtas_call(token, 3, 1, htobe32(indicator), htobe32(new_value), htobe32(loc_pa), &status); if (rc < 0) break; @@ -1092,7 +1128,7 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, } while (rc == CALL_AGAIN); - (void) sc_free_rmo_buffer(locbuf, loc_pa, size); + (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); dbg1("(%d, %d, %s) = %d\n", indicator, new_value, (char *)loc_code, rc ? rc : status); @@ -1100,23 +1136,28 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, } /** - * sc_set_eeh_option + * rtas_set_eeh_option + * @brief Inerface to the ibm,set-eeh-option rtas call * - * @param token - * @param cfg_addr - * @param phbid + * @param cfg_addr configuration address for slot to set eeh option on + * @param phbid PHB ID for slot to set option on * @param function * @return 0 on success, !0 otherwise */ int -sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) +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"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), + rc = rtas_call(token, 4, 1, htobe32(cfg_addr), BITS32_HI(htobe64(phbid)), BITS32_LO(htobe64(phbid)), htobe32(function), &status); @@ -1132,22 +1173,27 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) } /** - * sc_set_indicator + * rtas_set_indicator + * @brief Interface to the set-indicator rtas call * - * @param token - * @param indicator - * @param index - * @param new_value + * @param indicator indicator to set + * @param index indicator index + * @param new_value value to set the indicator to * @return 0 on success, !0 otherwise */ -int sc_set_indicator(int token, int indicator, int index, int new_value) +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 = sc_rtas_call(token, 3, 1, htobe32(indicator), + rc = rtas_call(token, 3, 1, htobe32(indicator), htobe32(index), htobe32(new_value), &status); if (rc) return rc; @@ -1161,23 +1207,28 @@ int sc_set_indicator(int token, int indicator, int index, int new_value) } /** - * sc_set_power_level + * rtas_set_power_level + * @brief Interface to the set-power-level rtas call * - * @param token * @param powerdomain - * @param level + * @param level power level to set to * @param setlevel * @return 0 on success, !0 otherwise */ -int sc_set_power_level(int token, int powerdomain, int level, int *setlevel) +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 = sc_rtas_call(token, 2, 2, htobe32(powerdomain), + rc = rtas_call(token, 2, 2, htobe32(powerdomain), htobe32(level), &status, &be_setlevel); if (rc) return rc; @@ -1193,28 +1244,33 @@ int sc_set_power_level(int token, int powerdomain, int level, int *setlevel) } /** - * sc_set_poweron_time + * rtas_set_poweron_time + * @brief interface to the set-time-for-power-on rtas call * - * @param token - * @param year - * @param month - * @param day - * @param hour - * @param min - * @param sec - * @param nsec + * @param year year to power on + * @param month month to power on + * @param day day to power on + * @param hour hour to power on + * @param min minute to power on + * @param sec second to power on + * @param nsec nano-second top power on * @return 0 on success, !0 otherwise */ int -sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, +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 = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + rc = rtas_call(token, 7, 1, htobe32(year), htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); if (rc) @@ -1229,31 +1285,36 @@ sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, } /** - * sc_set_sysparm + * rtas_set_sysparm + * @brief Interface to the ibm,set-system-parameter rtas call * - * @param token * @param parameter * @param data * @return 0 on success, !0 otherwise */ -int sc_set_sysparm(int token, unsigned int parameter, char *data) +int rtas_set_sysparm(unsigned int parameter, char *data) { + SANITY_CHECKS(); uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; int status; short size; int rc; + int token = rtas_token("ibm,set-system-parameter"); + + if (token < 0) + return token; size = *(short *)data; - rc = sc_get_rmo_buffer(size + sizeof(short), &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(size + sizeof(short), &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, data, size + sizeof(short)); do { - rc = sc_rtas_call(token, 2, 1, htobe32(parameter), + rc = rtas_call(token, 2, 1, htobe32(parameter), htobe32(kernbuf_pa), &status); if (rc < 0) break; @@ -1261,34 +1322,39 @@ int sc_set_sysparm(int token, unsigned int parameter, char *data) rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, size + sizeof(short)); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, size + sizeof(short)); dbg1("(%d, %p) = %d\n", parameter, data, rc ? rc : status); return rc ? rc : status; } /** - * sc_set_time + * rtas_set_time + * @brief Interface to the set-time-of-day rtas call * - * @param token - * @param year - * @param month - * @param day - * @param hour - * @param min - * @param sec - * @param nsec + * @param year year to set time to + * @param month month to set time to + * @param day day to set time to + * @param hour hour to set time to + * @param min minute to set time to + * @param sec second to set time to + * @param nsec nan-second to set time to * @return 0 on success, !0 otherwise */ -int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, +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; do { - rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + rc = rtas_call(token, 7, 1, htobe32(year), htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); if (rc) @@ -1303,19 +1369,24 @@ int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, } /** - * sc_suspend_me + * rtas_suspend_me + * @brief Interface for ibm,suspend-me rtas call * - * @param token - * @return 0 on success, !0 otherwise + * @return 0 on success, !0 on failure */ -int sc_suspend_me(int token, uint64_t streamid) +int rtas_suspend_me(uint64_t streamid) { + SANITY_CHECKS(); uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,suspend-me"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), + rc = rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), BITS32_LO(htobe64(streamid)), &status); if (rc) return rc; @@ -1328,33 +1399,37 @@ int sc_suspend_me(int token, uint64_t streamid) } /** - * sc_update_nodes - * @brief Set up the ibm,update-nodes rtas system call + * rtas_update_nodes + * @brief Interface for ibm,update-nodes rtas call * - * @param token - * @param workarea - * @param scope - * @return 0 on success, !0 otherwise + * @param workarea input output work area for the rtas call + * @param scope of call + * @return 0 on success, !0 on failure * * Note that the PAPR defines the work area as 4096 bytes (as * opposed to a page), thus we use that rather than PAGE_SIZE below. */ -int sc_update_nodes(int token, char *workarea, unsigned int scope) +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"); - rc = sc_get_rmo_buffer(4096, &kernbuf, &workarea_pa); + if (token < 0) + return token; + + rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) return rc; memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + rc = rtas_call(token, 2, 1, htobe32(workarea_pa), htobe32(scope), &status); if (rc < 0) break; @@ -1365,40 +1440,44 @@ int sc_update_nodes(int token, char *workarea, unsigned int scope) if (rc == 0) memcpy(workarea, kernbuf, 4096); - (void)sc_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); dbg1("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; } -/** - * sc_update_properties - * @brief Set up the ibm,update-properties rtas system call + /** + * rtas_update_properties + * @brief Interface for ibm,update-properties rtas call * - * @param token - * @param workarea - * @param scope - * @return 0 on success, !0 otherwise + * @param workarea input output work area for the rtas call + * @param scope of call + * @return 0 on success, !0 on failure * * Note that the PAPR defines the work area as 4096 bytes (as * opposed to a page), thus we use that rather than PAGE_SIZE below. */ -int sc_update_properties(int token, char *workarea, unsigned int scope) +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; - rc = sc_get_rmo_buffer(4096, &kernbuf, &workarea_pa); + rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) return rc; memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + rc = rtas_call(token, 2, 1, htobe32(workarea_pa), htobe32(scope), &status); if (rc < 0) break; @@ -1409,7 +1488,7 @@ int sc_update_properties(int token, char *workarea, unsigned int scope) if (rc == 0) memcpy(workarea, kernbuf, 4096); - (void)sc_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); dbg1("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index afddad6..cc364f4 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -11,13 +11,12 @@ #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> -#include <unistd.h> #include <sys/mman.h> -#include "common.h" #include "syscall.h" #include "librtas.h" #define MAX_PAGES 64 +#define MAX_PATH_LEN 80 struct workarea_config { int init_done; @@ -37,6 +36,36 @@ static struct workarea_config wa_config = { }; /** + * open_proc_rtas_file + * @brief Open the proc rtas file + * + * @param name filename to open + * @param mode mode to open file in + * @return results of open() call + */ +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]; + int npaths; + int fd; + int i; + + npaths = sizeof(proc_rtas_paths) / sizeof(char *); + for (i = 0; i < npaths; i++) { + sprintf(full_name, "%s/%s", proc_rtas_paths[i], name); + fd = open(full_name, mode, S_IRUSR | S_IWUSR); + if (fd >= 0) + break; + } + + if (fd < 0) + dbg1("Failed to open %s\n", full_name); + + return fd; +} + +/** * read_kregion_bounds * @brief Read the kernel region bounds for RMO memory * @@ -111,7 +140,7 @@ static inline void set_bits(short lobit, short hibit, uint64_t value, /** * acquire_file_lock - * + * * @param start * @param size * @return 0 on success, !0 otherwise @@ -260,7 +289,7 @@ static int release_phys_region(uint32_t phys_addr, size_t size) /** * init_workarea_config - * + * * @return 0 on success, !0 otherwise */ static int init_workarea_config() @@ -338,11 +367,11 @@ static int munmap_dev_mem(void *buf, size_t size) } /** - * sc_interface_exists + * interface_exists * * @return 0 on success, !0 otherwise */ -int sc_interface_exists() +int interface_exists() { int fd = open_proc_rtas_file(rmo_filename, O_RDONLY); int exists; @@ -356,7 +385,8 @@ int sc_interface_exists() } /** - * sc_free_rmo_buffer + * rtas_free_rmo_buffer + * @brief free the rmo buffer used by librtas * * @param buf virtual address of mmap()'ed buffer * @param phys_addr physical address of low mem buffer @@ -365,8 +395,9 @@ int sc_interface_exists() * RTAS_FREE_ERR - Free called before get * RTAS_IO_ASSERT - Unexpected I/O Error */ -int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) +int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) { + SANITY_CHECKS(); int n_pages; int rc; @@ -394,7 +425,12 @@ int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) } /** - * sc_get_rmo_buffer + * rtas_get_rmo_buffer + * @brief Retrive the RMO buffer used by librtas + * + * On successful completion the buf parameter will reference an allocated + * area of RMO memory and the phys_addr parameter will refernce the + * physical address of the RMO buffer. * * @param size Size of requested region. Must be a multiple of 4096. * @param buf Assigned to mmap'ed buffer of acquired region @@ -404,8 +440,9 @@ int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) * RTAS_NO_LOWMEM - Out of rmo memory * RTAS_IO_ASSERT - Unexpected I/O Error */ -int sc_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) +int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) { + SANITY_CHECKS(); uint32_t addr; int n_pages; int rc; -- 1.8.5.2 |
From: Thomas F. <tlf...@li...> - 2014-07-16 20:32:48
|
Since the procfs and common interfaces are being removed, all rtas calls will be fully implemented in the syscall_calls.c and syscall_rmo.c files. Signed-off-by: Thomas Falcon <tlf...@li...> --- librtas_src/syscall.h | 6 +- librtas_src/syscall_calls.c | 955 +++++++++++++++++++++++++++++--------------- librtas_src/syscall_rmo.c | 57 ++- 3 files changed, 672 insertions(+), 346 deletions(-) diff --git a/librtas_src/syscall.h b/librtas_src/syscall.h index 32bffbd..d5da539 100644 --- a/librtas_src/syscall.h +++ b/librtas_src/syscall.h @@ -36,9 +36,9 @@ struct region { struct region *next; }; -extern int sc_get_rmo_buffer(size_t size, void **buf, uint32_t *phys_addr); -extern int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size); -extern int sc_interface_exists(); +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(); #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 01d6ce8..b7f7fe6 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -13,96 +13,11 @@ #include <string.h> #include <errno.h> #include <sys/syscall.h> -#include <unistd.h> #include <linux/unistd.h> #include <linux/types.h> -#include "common.h" #include "syscall.h" #include "librtas.h" -int sc_activate_firmware(int token); -int sc_cfg_connector(int token, char *workarea); -int sc_delay_timeout(uint64_t timeout_ms); -int sc_display_char(int token, char c); -int sc_display_msg(int token, char *buf); -int sc_errinjct(int token, int etoken, int otoken, char *workarea); -int sc_errinjct_close(int token, int otoken); -int sc_errinjct_open(int token, int *otoken); -int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state); -int sc_get_config_addr_info2(int token, uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info); -int sc_get_indices(int token, int is_sensor, int type, char *workarea, - size_t size, int start, int *next); -int sc_get_power_level(int token, int powerdomain, int *level); -int sc_get_sensor(int token, int sensor, int index, int *state); -int sc_get_sysparm(int token, unsigned int parameter, unsigned int length, - char *data); -int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, - uint32_t *hour, uint32_t *min, uint32_t *sec, uint32_t *nsec); -int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, - unsigned int sequence, unsigned int *seq_next, - unsigned int *bytes_ret); -int sc_lpar_perftools(int token, int subfunc, char *workarea, - unsigned int length, unsigned int sequence, - unsigned int *seq_next); -int sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, - void *buffer, size_t length, uint64_t * next_seq, - uint64_t * bytes_ret); -int sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, - int *state, int *eeh); -int sc_scan_log_dump(int token, void *buffer, size_t length); -int sc_set_dynamic_indicator(int token, int indicator, int new_value, - void *loc_code); -int sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, - int function); -int sc_set_indicator(int token, int indicator, int index, int new_value); -int sc_set_power_level(int token, int powerdomain, int level, int *setlevel); -int sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, - uint32_t nsec); -int sc_set_sysparm(int token, unsigned int parameter, char *data); -int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, - uint32_t nsec); -int sc_suspend_me(int token, uint64_t streamid); -int sc_update_nodes(int token, char *workarea, unsigned int scope); -int sc_update_properties(int token, char *workarea, unsigned int scope); - -struct rtas_operations syscall_rtas_ops = { - .activate_firmware = sc_activate_firmware, - .cfg_connector = sc_cfg_connector, - .delay_timeout = sc_delay_timeout, - .display_char = sc_display_char, - .display_msg = sc_display_msg, - .errinjct = sc_errinjct, - .errinjct_close = sc_errinjct_close, - .errinjct_open = sc_errinjct_open, - .free_rmo_buffer = sc_free_rmo_buffer, - .get_config_addr_info2 = sc_get_config_addr_info2, - .get_dynamic_sensor = sc_get_dynamic_sensor, - .get_indices = sc_get_indices, - .get_sensor = sc_get_sensor, - .get_power_level = sc_get_power_level, - .get_rmo_buffer = sc_get_rmo_buffer, - .get_sysparm = sc_get_sysparm, - .get_time = sc_get_time, - .get_vpd = sc_get_vpd, - .lpar_perftools = sc_lpar_perftools, - .platform_dump = sc_platform_dump, - .read_slot_reset = sc_read_slot_reset, - .scan_log_dump = sc_scan_log_dump, - .set_dynamic_indicator = sc_set_dynamic_indicator, - .set_indicator = sc_set_indicator, - .set_eeh_option = sc_set_eeh_option, - .set_power_level = sc_set_power_level, - .set_poweron_time = sc_set_poweron_time, - .set_sysparm = sc_set_sysparm, - .set_time = sc_set_time, - .suspend_me = sc_suspend_me, - .update_nodes = sc_update_nodes, - .update_properties = sc_update_properties, - .interface_exists = sc_interface_exists, -}; - /* The original librtas used the _syscall1 interface to get to the rtas * system call. On recent versions of Linux though the _syscall1 * interface was removed from unistd.h so we have moved to using the @@ -115,6 +30,8 @@ _syscall1(int, rtas, void *, args); #define CALL_AGAIN 1 +struct librtas_config config = { NULL, 0 }; + /** * handle_delay * @brief sleep for the specified delay time @@ -163,7 +80,7 @@ static unsigned int handle_delay(int status, uint64_t * elapsed) * display_rtas_buf * @brief Dump the contents of the rtas call buffer * - * @param args + * @param args * @param after */ static void display_rtas_buf(struct rtas_args *args, int after) @@ -196,10 +113,10 @@ static void display_rtas_buf(struct rtas_args *args, int after) } /** - * sc_rtas_call + * rtas_call * @brief Perform the actual system call for the rtas call - * - * Variable argument list consists of inputs followed by + * + * Variable argument list consists of inputs followed by * pointers to outputs. * * @param token @@ -207,7 +124,7 @@ 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 sc_rtas_call(int token, int ninputs, int nret, ...) +static int rtas_call(int token, int ninputs, int nret, ...) { struct rtas_args args; rtas_arg_t *rets[MAX_ARGS]; @@ -254,20 +171,31 @@ static int sc_rtas_call(int token, int ninputs, int nret, ...) } /** - * sc_activate_firmware - * @brief Set up the activate-firmware rtas system call + * rtas_activate_firmware + * @brief Interface for ibm,activate-firmware rtas call * - * @param token - * @return 0 on success, !0 otherwise + * @return 0 on success, !0 on failure */ -int sc_activate_firmware(int token) +int rtas_activate_firmware() { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,activate-firmware"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 0, 1, &status); + rc = rtas_call(token, 0, 1, &status); if (rc) return rc; @@ -282,15 +210,22 @@ int sc_activate_firmware(int token) #define CFG_RC_MEM 5 /** - * sc_cfg_connector - * @brief Set up the cfg-connector rtas system call + * rtas_cfg_connector + * @brief Interface for ibm,configure-connector rtas call * - * @param token - * @param workarea - * @return 0 on success, !0 otherwise + * @param workarea buffer containg args to ibm,configure-connector + * @return 0 on success, !0 on failure */ -int sc_cfg_connector(int token, char *workarea) +int rtas_cfg_connector(char *workarea) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint32_t workarea_pa; uint32_t extent_pa = 0; uint64_t elapsed = 0; @@ -298,21 +233,25 @@ int sc_cfg_connector(int token, char *workarea) void *extent; int status; int rc; + int token = rtas_token("ibm,configure-connector"); + + if (token < 0) + return token; - rc = sc_get_rmo_buffer(PAGE_SIZE, &kernbuf, &workarea_pa); + rc = rtas_get_rmo_buffer(PAGE_SIZE, &kernbuf, &workarea_pa); if (rc) return rc; memcpy(kernbuf, workarea, PAGE_SIZE); do { - rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + rc = rtas_call(token, 2, 1, htobe32(workarea_pa), htobe32(extent_pa), &status); if (rc < 0) break; - + if ((rc == 0) && (status == CFG_RC_MEM)) { - rc = sc_get_rmo_buffer(PAGE_SIZE, &extent, &extent_pa); + rc = rtas_get_rmo_buffer(PAGE_SIZE, &extent, &extent_pa); if (rc < 0) break; continue; @@ -324,45 +263,64 @@ int sc_cfg_connector(int token, char *workarea) if (rc == 0) memcpy(workarea, kernbuf, PAGE_SIZE); - (void)sc_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); if (extent_pa) - (void)sc_free_rmo_buffer(extent, extent_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(extent, extent_pa, PAGE_SIZE); dbg1("(%p) = %d\n", workarea, rc ? rc : status); return rc ? rc : status; } /** - * sc_delay_timeout - * @brief set the configured timeout value + * rtas_delay_timeout + * @brief Interface to retrieve the rtas timeout delay * - * @param timeout_ms new timeout in milliseconds - * @return 0 on success, !0 otherwise + * @param timeout_ms timeout in milli-seconds + * @return delay time */ -int sc_delay_timeout(uint64_t timeout_ms) +int rtas_delay_timeout(uint64_t timeout_ms) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + config.rtas_timeout_ms = timeout_ms; return 0; } /** - * sc_display_char - * @brief Set up display-char rtas system call - * - * @param token + * rtas_display_char + * @brief Interface for display-character rtas call + * * @param c character to display * @return 0 on success, !0 otherwise */ -int sc_display_char(int token, char c) +int rtas_display_char(char c) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("display-character"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 1, 1, c, &status); + rc = rtas_call(token, 1, 1, c, &status); if (rc) return rc; @@ -374,39 +332,50 @@ int sc_display_char(int token, char c) } /** - * sc_display_msg - * @brief Set up the display-message rtas system call + * rtas_display_msg + * @brief Interface for ibm,display-message rtas call * - * @param token * @param buf message to display * @return 0 on success, !0 otherwise */ -int sc_display_msg(int token, char *buf) +int rtas_display_msg(char *buf) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; str_len = strlen(buf); - rc = sc_get_rmo_buffer(str_len, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(str_len, &kernbuf, &kernbuf_pa); if (rc) return rc; strcpy(kernbuf, buf); do { - rc = sc_rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); + rc = rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); if (rc < 0) break; rc = handle_delay(status, &elapsed); } while ((rc == CALL_AGAIN)); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, str_len); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, str_len); dbg1("(%p) = %d\n", buf, rc ? rc : status); return rc ? rc : status; @@ -415,31 +384,42 @@ int sc_display_msg(int token, char *buf) #define ERRINJCT_BUF_SIZE 1024 /** - * sc_errinjct - * @brief Set up the errinjct rtas system call + * rtas_errinjct + * @brief Interface to the ibm,errinjct rtas call * - * @param token - * @param etoken error injection token - * @param otoken error injection open token - * @param workarea additional args to rtas call + * @param etoken errinjct token + * @param otoken errinjct open token + * @param workarea additional args to ibm,errinjct * @return 0 on success, !0 otherwise */ -int sc_errinjct(int token, int etoken, int otoken, char *workarea) +int rtas_errinjct(int etoken, int otoken, char *workarea) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(ERRINJCT_BUF_SIZE, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(ERRINJCT_BUF_SIZE, &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, workarea, ERRINJCT_BUF_SIZE); do { - rc = sc_rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), + rc = rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), htobe32(kernbuf_pa), &status); if (rc < 0 ) break; @@ -450,28 +430,39 @@ int sc_errinjct(int token, int etoken, int otoken, char *workarea) if (rc == 0) memcpy(workarea, kernbuf, ERRINJCT_BUF_SIZE); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, ERRINJCT_BUF_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, ERRINJCT_BUF_SIZE); dbg1("(%d, %d, %p) = %d\n", etoken, otoken, workarea, rc ? rc : status); return rc ? rc : status; } /** - * sc_errinjct_close - * @brief Set up the errinjct close rtas system call + * rtas_errinjct_close + * @brief Inerface to close the ibm,errinjct facility * - * @param token * @param otoken errinjct open token * @return 0 on success, !0 otherwise */ -int sc_errinjct_close(int token, int otoken) +int rtas_errinjct_close(int otoken) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,close-errinjct"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 1, 1, htobe32(otoken), &status); + rc = rtas_call(token, 1, 1, htobe32(otoken), &status); if (rc) return rc; @@ -483,22 +474,36 @@ int sc_errinjct_close(int token, int otoken) } /** - * sc_errinjct_open - * @brief Set up the errinjct open rtas system call + * rtas_errinjct_open + * @brief Interface to open the ibm,errinjct facility * - * @param token - * @param otoken + * This call will set the value refrenced by otoken to the open token + * for the ibm,errinjct facility + * + * @param otoken pointer to open token * @return 0 on success, !0 otherwise */ -int sc_errinjct_open(int token, int *otoken) +int rtas_errinjct_open(int *otoken) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; __be32 be_otoken; int status; int rc; + int token = rtas_token("ibm,open-errinjct"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 0, 2, &be_otoken, &status); + rc = rtas_call(token, 0, 2, &be_otoken, &status); if (rc) return rc; @@ -512,26 +517,39 @@ int sc_errinjct_open(int token, int *otoken) } /** - * sc_get_config_addr2 - * @brief get the pci slot config address + * rtas_get_config_addr_info2 + * @brief Interface to ibm,get-config-addr-info2 rtas call + * + * On successful completion the info value is returned. * - * @param token * @param config_addr - * @param phb_unit_id - * @param func + * @param PHB_Unit_ID + * @param function * @param info * @return 0 on success, !0 otherwise */ -int sc_get_config_addr_info2(int token, uint32_t config_addr, +int rtas_get_config_addr_info2(uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; do { - rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), + rc = rtas_call(token, 4, 2, htobe32(config_addr), BITS32_HI(htobe64(phb_id)), BITS32_LO(htobe64(phb_id)), htobe32(func), &status, &be_info); @@ -549,17 +567,27 @@ int sc_get_config_addr_info2(int token, uint32_t config_addr, } /** - * sc_get_dynamic_sensor - * @brief Set up the get-dynamic-sensor rtas system call + * rtas_get_dynamic_sensor + * @brief Interface to ibm,get-dynamic-sensor-state rtas call * - * @param token - * @param sensor - * @param loc_code - * @param state + * On success the variable referenced by the state parameter will contain + * the state of the sensor + * + * @param sensor sensor to retrieve + * @param loc_code location code of the sensor + * @param state reference to state variable * @return 0 on success, !0 otherwise */ -int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) +int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint32_t loc_pa = 0; uint64_t elapsed = 0; void *locbuf; @@ -567,17 +595,21 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) __be32 be_state; int status; int rc; + int token = rtas_token("ibm,get-dynamic-sensor-state"); + + if (token < 0) + return token; size = *(uint32_t *)loc_code + sizeof(uint32_t); - rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); + rc = rtas_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) return rc; memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), + rc = rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), &status, &be_state); if (rc < 0) break; @@ -585,7 +617,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - (void) sc_free_rmo_buffer(locbuf, loc_pa, size); + (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); *state = be32toh(be_state); @@ -595,35 +627,46 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) } /** - * sc_get_indices - * @brief Set up the get-indices rtas system call + * rtas_get_indices + * @brief Interface to the ibm,get-indices rtas call * - * @param token - * @param is_sensor + * @param is_sensor is this index a sensor? * @param type - * @param workarea + * @param workarea additional args to the rtas call * @param size * @param start * @param next * @return 0 on success, !0 otherwise */ int -sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, +rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, int start, int *next) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); - if (rc) + rc = rtas_get_rmo_buffer(size, &kernbuf, &kernbuf_pa); + if (rc) return rc; do { - rc = sc_rtas_call(token, 5, 2, htobe32(is_sensor), + rc = rtas_call(token, 5, 2, htobe32(is_sensor), htobe32(type), htobe32(kernbuf_pa), htobe32(size), htobe32(start), &status, &be_next); @@ -636,7 +679,7 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, if (rc == 0) memcpy(workarea, kernbuf, size); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, size); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, size); *next = be32toh(be_next); @@ -646,23 +689,37 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, } /** - * sc_get_power_level - * @brief Set up the get-power-level rtas system call + * rtas_get_power_level + * @brief Interface to the get-power-level rtas call + * + * On success this routine will set the variable referenced by the level + * parameter to the power level * - * @param token * @param powerdomain - * @param level + * @param level reference to the power level variable * @return 0 on success, !0 otherwise */ -int sc_get_power_level(int token, int powerdomain, int *level) +int rtas_get_power_level(int powerdomain, int *level) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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 = sc_rtas_call(token, 1, 2, htobe32(powerdomain), + rc = rtas_call(token, 1, 2, htobe32(powerdomain), &status, &be_level); if (rc) return rc; @@ -678,24 +735,38 @@ int sc_get_power_level(int token, int powerdomain, int *level) } /** - * sc_get_sensor - * @brief Set up the get-sensor rtas system call + * rtas_get_sensor + * @brief Interface to the get-sensor-state rtas call + * + * On successful completion the state parameter will reference the current + * state of the sensor * - * @param token * @param sensor - * @param index - * @param state + * @param index sensor index + * @param state reference to state variable * @return 0 on success, !0 otherwise */ -int sc_get_sensor(int token, int sensor, int index, int *state) +int rtas_get_sensor(int sensor, int index, int *state) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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 = sc_rtas_call(token, 2, 2, htobe32(sensor), + rc = rtas_call(token, 2, 2, htobe32(sensor), htobe32(index), &status, &be_state); if (rc) return rc; @@ -711,31 +782,45 @@ int sc_get_sensor(int token, int sensor, int index, int *state) } /** - * sc_get_sysparm - * @brief Setup the get-system-parameter rtas system call + * rtas_get_sysparm + * @brief Interface to the ibm,get-system-parameter rtas call * - * @param token - * @param parameter - * @param length - * @param data + * On successful completion the data parameter will contain the system + * parameter results + * + * @param parameter system parameter to retrieve + * @param length data buffer length + * @param data reference to buffer to return parameter in * @return 0 on success, !0 otherwise */ int -sc_get_sysparm(int token, unsigned int parameter, unsigned int length, +rtas_get_sysparm(unsigned int parameter, unsigned int length, char *data) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; do { - rc = sc_rtas_call(token, 3, 1, htobe32(parameter), + rc = rtas_call(token, 3, 1, htobe32(parameter), htobe32(kernbuf_pa), htobe32(length), &status); if (rc < 0) @@ -747,17 +832,19 @@ sc_get_sysparm(int token, unsigned int parameter, unsigned int length, if (rc == 0) memcpy(data, kernbuf, length); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); dbg1("(%d, %d, %p) = %d\n", parameter, length, data, rc ? rc : status); return rc ? rc : status; } /** - * sc_get_time - * @brief Set up the get-time rtas system call + * rtas_get_time + * @brief Interface to get-time-of-day rtas call + * + * On successful completion all of the parameters will be filled with + * their respective values for the current time of day. * - * @param token * @param year * @param month * @param day @@ -767,15 +854,27 @@ sc_get_sysparm(int token, unsigned int parameter, unsigned int length, * @param nsec * @return 0 on success, !0 otherwise */ -int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, +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) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("get-time-of-day"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 0, 8, &status, year, month, day, hour, + rc = rtas_call(token, 0, 8, &status, year, month, day, hour, min, sec, nsec); if (rc) return rc; @@ -797,21 +896,29 @@ int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, } /** - * sc_get_vpd + * rtas_get_vpd + * @brief Interface to the ibm,get-vpd rtas call * - * @param token - * @param loc_code - * @param workarea + * @param loc_code location code + * @param workarea additional args to rtas call * @param size * @param sequence * @param seq_next * @param bytes_ret * @return 0 on success, !0 otherwise */ -int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, - unsigned int sequence, unsigned int *seq_next, +int rtas_get_vpd(char *loc_code, char *workarea, size_t size, + unsigned int sequence, unsigned int *seq_next, unsigned int *bytes_ret) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint32_t kernbuf_pa; uint32_t loc_pa = 0; uint32_t rmo_pa = 0; @@ -821,8 +928,12 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, void *locbuf; int status; int rc; - - rc = sc_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); + int token = rtas_token("ibm,get-vpd"); + + if (token < 0) + return token; + + rc = rtas_get_rmo_buffer(size + PAGE_SIZE, &rmobuf, &rmo_pa); if (rc) return rc; kernbuf = rmobuf + PAGE_SIZE; @@ -832,55 +943,67 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, /* If user didn't set loc_code, copy a NULL string */ strncpy(locbuf, loc_code ? loc_code : "", PAGE_SIZE); - + *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 4, 3, htobe32(loc_pa), + rc = rtas_call(token, 4, 3, htobe32(loc_pa), htobe32(kernbuf_pa), htobe32(size), sequence, &status, seq_next, bytes_ret); if (rc < 0) break; - + rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - + if (rc == 0) memcpy(workarea, kernbuf, size); - (void) sc_free_rmo_buffer(rmobuf, rmo_pa, size + PAGE_SIZE); - + (void) rtas_free_rmo_buffer(rmobuf, rmo_pa, size + PAGE_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", - workarea, size, sequence, status, *seq_next, *bytes_ret); - return rc ? rc : status; + workarea, size, sequence, status, *seq_next, *bytes_ret); + return rc ? rc : status; } /** - * sc_lpar_perftools + * rtas_lpar_perftools + * @brief Interface to the ibm,lpa-perftools rtas call * - * @param token * @param subfunc - * @param workarea + * @param workarea additional args to the rtas call * @param length * @param sequence * @param seq_next * @return 0 on success, !0 otherwise */ -int sc_lpar_perftools(int token, int subfunc, char *workarea, +int rtas_lpar_perftools(int subfunc, char *workarea, unsigned int length, unsigned int sequence, unsigned int *seq_next) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; @@ -889,7 +1012,7 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 5, 2, htobe32(subfunc), 0, + rc = rtas_call(token, 5, 2, htobe32(subfunc), 0, htobe32(kernbuf_pa), htobe32(length), sequence, &status, seq_next); if (rc < 0) @@ -901,7 +1024,7 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, if (rc == 0) memcpy(workarea, kernbuf, length); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); *seq_next = be32toh(*seq_next); @@ -909,23 +1032,30 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, length, sequence, seq_next, rc ? rc : status, *seq_next); return rc ? rc : status; } - /** - * sc_platform_dump + * rtas_platform_dump + * Interface to the ibm,platform-dump rtas call * - * @param token * @param dump_tag * @param sequence - * @param buffer - * @param length - * @param seq_next + * @param buffer buffer to write dump to + * @param length buffer length + * @param next_seq * @param bytes_ret - * @return 0 on success, !0 otherwise + * @return 0 on success, !0 othwerwise */ int -sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, +rtas_platform_dump(uint64_t dump_tag, uint64_t sequence, void *buffer, size_t length, uint64_t * seq_next, uint64_t * bytes_ret) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; uint32_t kernbuf_pa = 0; uint32_t next_hi, next_lo; @@ -933,9 +1063,13 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, void *kernbuf; int status; int rc; + int token = rtas_token("ibm,platform-dump"); + + if (token < 0) + return token; if (buffer) { - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; } @@ -943,7 +1077,7 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, *seq_next = htobe64(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), + rc = rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), BITS32_LO(htobe64(dump_tag)), BITS32_HI(sequence), BITS32_LO(sequence), @@ -952,7 +1086,7 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, &bytes_lo); if (rc < 0) break; - + *seq_next = BITS64(next_hi, next_lo); dbg1("%s: seq_next = 0x%llx\n", __FUNCTION__, *seq_next); @@ -961,9 +1095,9 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, if (buffer && (rc == 0)) memcpy(buffer, kernbuf, length); - + if (kernbuf) - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); next_hi = be32toh(next_hi); next_lo = be32toh(next_lo); @@ -979,26 +1113,37 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, } /** - * sc_read_slot_reset - * @brief Set up the read-slot-reset-state rtas system call + * rtas_read_slot_reset + * @brief Interface to the ibm,read-slot-reset-state rtas call * - * @param token * @param cfg_addr configuration address of slot to read - * @param phbid PHB ID of slot to read - * @param state + * @param phbid PHB ID of the slot to read + * @param state reference to variable to return slot state in * @param eeh * @return 0 on success, !0 otherwise */ int -sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, +rtas_read_slot_reset(uint32_t cfg_addr, uint64_t phbid, int *state, int *eeh) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,read-slot-reset-state"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), + rc = rtas_call(token, 3, 3, htobe32(cfg_addr), BITS32_HI(htobe64(phbid)), BITS32_LO(htobe64(phbid)), &status, state, eeh); @@ -1017,28 +1162,40 @@ sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, } /** - * sc_scan_log_dump + * rtas_scan_log_dump + * @brief Interface to the ibm,scan-log-dump rtas call * - * @param token - * @param buffer - * @param length + * @param buffer buffer to return scan log dump in + * @param length size of buffer * @return 0 on success, !0 otherwise */ -int sc_scan_log_dump(int token, void *buffer, size_t length) +int rtas_scan_log_dump(void *buffer, size_t length) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(length, &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, buffer, length); do { - rc = sc_rtas_call(token, 2, 1, htobe32(kernbuf_pa), + rc = rtas_call(token, 2, 1, htobe32(kernbuf_pa), htobe32(length), &status); if (rc < 0) break; @@ -1049,41 +1206,67 @@ int sc_scan_log_dump(int token, void *buffer, size_t length) if (rc == 0) memcpy(buffer, kernbuf, length); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, length); dbg1("(%p, %d) = %d\n", buffer, length, rc ? rc : status); return rc ? rc : status; } /** - * sc_set_dynamic_indicator + * rtas_set_debug + * @brief Interface to set librtas debug level * - * @param token - * @param indicator - * @param new_value + * @param level debug level to set to + * @return 0 on success, !0 otherwise + */ +int rtas_set_debug(int level) +{ + config.debug = level; + + return 0; +} + +/** + * rtas_set_dynamic_indicator + * @brief Interface to the ibm,set-dynamic-indicator rtas call + * + * @param indicator indicator to set + * @param new_value value to set the indicator to * @param loc_code * @return 0 on success, !0 otherwise */ -int sc_set_dynamic_indicator(int token, int indicator, int new_value, +int rtas_set_dynamic_indicator(int indicator, int new_value, void *loc_code) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; size = *(uint32_t *)loc_code + sizeof(uint32_t); - rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); + rc = rtas_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) return rc; memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 3, 1, htobe32(indicator), + rc = rtas_call(token, 3, 1, htobe32(indicator), htobe32(new_value), htobe32(loc_pa), &status); if (rc < 0) break; @@ -1092,7 +1275,7 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, } while (rc == CALL_AGAIN); - (void) sc_free_rmo_buffer(locbuf, loc_pa, size); + (void) rtas_free_rmo_buffer(locbuf, loc_pa, size); dbg1("(%d, %d, %s) = %d\n", indicator, new_value, (char *)loc_code, rc ? rc : status); @@ -1100,23 +1283,35 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, } /** - * sc_set_eeh_option + * rtas_set_eeh_option + * @brief Inerface to the ibm,set-eeh-option rtas call * - * @param token - * @param cfg_addr - * @param phbid + * @param cfg_addr configuration address for slot to set eeh option on + * @param phbid PHB ID for slot to set option on * @param function * @return 0 on success, !0 otherwise */ int -sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) +rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,set-eeh-option"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), + rc = rtas_call(token, 4, 1, htobe32(cfg_addr), BITS32_HI(htobe64(phbid)), BITS32_LO(htobe64(phbid)), htobe32(function), &status); @@ -1132,22 +1327,34 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) } /** - * sc_set_indicator + * rtas_set_indicator + * @brief Interface to the set-indicator rtas call * - * @param token - * @param indicator - * @param index - * @param new_value + * @param indicator indicator to set + * @param index indicator index + * @param new_value value to set the indicator to * @return 0 on success, !0 otherwise */ -int sc_set_indicator(int token, int indicator, int index, int new_value) +int rtas_set_indicator(int indicator, int index, int new_value) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("set-indicator"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 3, 1, htobe32(indicator), + rc = rtas_call(token, 3, 1, htobe32(indicator), htobe32(index), htobe32(new_value), &status); if (rc) return rc; @@ -1161,23 +1368,35 @@ int sc_set_indicator(int token, int indicator, int index, int new_value) } /** - * sc_set_power_level + * rtas_set_power_level + * @brief Interface to the set-power-level rtas call * - * @param token * @param powerdomain - * @param level + * @param level power level to set to * @param setlevel * @return 0 on success, !0 otherwise */ -int sc_set_power_level(int token, int powerdomain, int level, int *setlevel) +int rtas_set_power_level(int powerdomain, int level, int *setlevel) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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 = sc_rtas_call(token, 2, 2, htobe32(powerdomain), + rc = rtas_call(token, 2, 2, htobe32(powerdomain), htobe32(level), &status, &be_setlevel); if (rc) return rc; @@ -1193,28 +1412,40 @@ int sc_set_power_level(int token, int powerdomain, int level, int *setlevel) } /** - * sc_set_poweron_time + * rtas_set_poweron_time + * @brief interface to the set-time-for-power-on rtas call * - * @param token - * @param year - * @param month - * @param day - * @param hour - * @param min - * @param sec - * @param nsec + * @param year year to power on + * @param month month to power on + * @param day day to power on + * @param hour hour to power on + * @param min minute to power on + * @param sec second to power on + * @param nsec nano-second top power on * @return 0 on success, !0 otherwise */ int -sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, +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) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("set-time-for-power-on"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + rc = rtas_call(token, 7, 1, htobe32(year), htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); if (rc) @@ -1229,31 +1460,43 @@ sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, } /** - * sc_set_sysparm + * rtas_set_sysparm + * @brief Interface to the ibm,set-system-parameter rtas call * - * @param token * @param parameter * @param data * @return 0 on success, !0 otherwise */ -int sc_set_sysparm(int token, unsigned int parameter, char *data) +int rtas_set_sysparm(unsigned int parameter, char *data) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; uint32_t kernbuf_pa; void *kernbuf; int status; short size; int rc; + int token = rtas_token("ibm,set-system-parameter"); + + if (token < 0) + return token; size = *(short *)data; - rc = sc_get_rmo_buffer(size + sizeof(short), &kernbuf, &kernbuf_pa); + rc = rtas_get_rmo_buffer(size + sizeof(short), &kernbuf, &kernbuf_pa); if (rc) return rc; memcpy(kernbuf, data, size + sizeof(short)); do { - rc = sc_rtas_call(token, 2, 1, htobe32(parameter), + rc = rtas_call(token, 2, 1, htobe32(parameter), htobe32(kernbuf_pa), &status); if (rc < 0) break; @@ -1261,34 +1504,46 @@ int sc_set_sysparm(int token, unsigned int parameter, char *data) rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); - (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, size + sizeof(short)); + (void)rtas_free_rmo_buffer(kernbuf, kernbuf_pa, size + sizeof(short)); dbg1("(%d, %p) = %d\n", parameter, data, rc ? rc : status); return rc ? rc : status; } /** - * sc_set_time + * rtas_set_time + * @brief Interface to the set-time-of-day rtas call * - * @param token - * @param year - * @param month - * @param day - * @param hour - * @param min - * @param sec - * @param nsec + * @param year year to set time to + * @param month month to set time to + * @param day day to set time to + * @param hour hour to set time to + * @param min minute to set time to + * @param sec second to set time to + * @param nsec nan-second to set time to * @return 0 on success, !0 otherwise */ -int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, +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) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("set-time-of-day"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + rc = rtas_call(token, 7, 1, htobe32(year), htobe32(month), htobe32(day), htobe32(hour), htobe32(min), htobe32(sec), htobe32(nsec), &status); if (rc) @@ -1303,19 +1558,31 @@ int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, } /** - * sc_suspend_me + * rtas_suspend_me + * @brief Interface for ibm,suspend-me rtas call * - * @param token - * @return 0 on success, !0 otherwise + * @return 0 on success, !0 on failure */ -int sc_suspend_me(int token, uint64_t streamid) +int rtas_suspend_me(uint64_t streamid) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + uint64_t elapsed = 0; int status; int rc; + int token = rtas_token("ibm,suspend-me"); + + if (token < 0) + return token; do { - rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), + rc = rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), BITS32_LO(htobe64(streamid)), &status); if (rc) return rc; @@ -1328,33 +1595,44 @@ int sc_suspend_me(int token, uint64_t streamid) } /** - * sc_update_nodes - * @brief Set up the ibm,update-nodes rtas system call + * rtas_update_nodes + * @brief Interface for ibm,update-nodes rtas call * - * @param token - * @param workarea - * @param scope - * @return 0 on success, !0 otherwise + * @param workarea input output work area for the rtas call + * @param scope of call + * @return 0 on success, !0 on failure * * Note that the PAPR defines the work area as 4096 bytes (as * opposed to a page), thus we use that rather than PAGE_SIZE below. */ -int sc_update_nodes(int token, char *workarea, unsigned int scope) +int rtas_update_nodes(char *workarea, unsigned int scope) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(4096, &kernbuf, &workarea_pa); + rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) return rc; memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + rc = rtas_call(token, 2, 1, htobe32(workarea_pa), htobe32(scope), &status); if (rc < 0) break; @@ -1365,40 +1643,51 @@ int sc_update_nodes(int token, char *workarea, unsigned int scope) if (rc == 0) memcpy(workarea, kernbuf, 4096); - (void)sc_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); dbg1("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; } -/** - * sc_update_properties - * @brief Set up the ibm,update-properties rtas system call + /** + * rtas_update_properties + * @brief Interface for ibm,update-properties rtas call * - * @param token - * @param workarea - * @param scope - * @return 0 on success, !0 otherwise + * @param workarea input output work area for the rtas call + * @param scope of call + * @return 0 on success, !0 on failure * * Note that the PAPR defines the work area as 4096 bytes (as * opposed to a page), thus we use that rather than PAGE_SIZE below. */ -int sc_update_properties(int token, char *workarea, unsigned int scope) +int rtas_update_properties(char *workarea, unsigned int scope) { + /* Check credentials */ + if (geteuid() != (uid_t) 0) + return RTAS_PERM; + + /* Check for any kernel RTAS interface */ + if (!interface_exists()) + return RTAS_KERNEL_INT; + 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; - rc = sc_get_rmo_buffer(4096, &kernbuf, &workarea_pa); + rc = rtas_get_rmo_buffer(4096, &kernbuf, &workarea_pa); if (rc) return rc; memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + rc = rtas_call(token, 2, 1, htobe32(workarea_pa), htobe32(scope), &status); if (rc < 0) break; @@ -1409,7 +1698,7 @@ int sc_update_properties(int token, char *workarea, unsigned int scope) if (rc == 0) memcpy(workarea, kernbuf, 4096); - (void)sc_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); + (void)rtas_free_rmo_buffer(kernbuf, workarea_pa, PAGE_SIZE); dbg1("(%p) %d = %d\n", workarea, scope, rc ? rc : status); return rc ? rc : status; diff --git a/librtas_src/syscall_rmo.c b/librtas_src/syscall_rmo.c index afddad6..cc364f4 100644 --- a/librtas_src/syscall_rmo.c +++ b/librtas_src/syscall_rmo.c @@ -11,13 +11,12 @@ #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> -#include <unistd.h> #include <sys/mman.h> -#include "common.h" #include "syscall.h" #include "librtas.h" #define MAX_PAGES 64 +#define MAX_PATH_LEN 80 struct workarea_config { int init_done; @@ -37,6 +36,36 @@ static struct workarea_config wa_config = { }; /** + * open_proc_rtas_file + * @brief Open the proc rtas file + * + * @param name filename to open + * @param mode mode to open file in + * @return results of open() call + */ +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]; + int npaths; + int fd; + int i; + + npaths = sizeof(proc_rtas_paths) / sizeof(char *); + for (i = 0; i < npaths; i++) { + sprintf(full_name, "%s/%s", proc_rtas_paths[i], name); + fd = open(full_name, mode, S_IRUSR | S_IWUSR); + if (fd >= 0) + break; + } + + if (fd < 0) + dbg1("Failed to open %s\n", full_name); + + return fd; +} + +/** * read_kregion_bounds * @brief Read the kernel region bounds for RMO memory * @@ -111,7 +140,7 @@ static inline void set_bits(short lobit, short hibit, uint64_t value, /** * acquire_file_lock - * + * * @param start * @param size * @return 0 on success, !0 otherwise @@ -260,7 +289,7 @@ static int release_phys_region(uint32_t phys_addr, size_t size) /** * init_workarea_config - * + * * @return 0 on success, !0 otherwise */ static int init_workarea_config() @@ -338,11 +367,11 @@ static int munmap_dev_mem(void *buf, size_t size) } /** - * sc_interface_exists + * interface_exists * * @return 0 on success, !0 otherwise */ -int sc_interface_exists() +int interface_exists() { int fd = open_proc_rtas_file(rmo_filename, O_RDONLY); int exists; @@ -356,7 +385,8 @@ int sc_interface_exists() } /** - * sc_free_rmo_buffer + * rtas_free_rmo_buffer + * @brief free the rmo buffer used by librtas * * @param buf virtual address of mmap()'ed buffer * @param phys_addr physical address of low mem buffer @@ -365,8 +395,9 @@ int sc_interface_exists() * RTAS_FREE_ERR - Free called before get * RTAS_IO_ASSERT - Unexpected I/O Error */ -int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) +int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) { + SANITY_CHECKS(); int n_pages; int rc; @@ -394,7 +425,12 @@ int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) } /** - * sc_get_rmo_buffer + * rtas_get_rmo_buffer + * @brief Retrive the RMO buffer used by librtas + * + * On successful completion the buf parameter will reference an allocated + * area of RMO memory and the phys_addr parameter will refernce the + * physical address of the RMO buffer. * * @param size Size of requested region. Must be a multiple of 4096. * @param buf Assigned to mmap'ed buffer of acquired region @@ -404,8 +440,9 @@ int sc_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) * RTAS_NO_LOWMEM - Out of rmo memory * RTAS_IO_ASSERT - Unexpected I/O Error */ -int sc_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) +int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) { + SANITY_CHECKS(); uint32_t addr; int n_pages; int rc; -- 1.8.5.2 |
From: Thomas F. <tlf...@li...> - 2014-07-16 20:32:47
|
The common files are being removed with the removal of procfs in order to simplify librtas. Signed-off-by: Thomas Falcon <tlf...@li...> --- librtas_src/Makefile | 4 +- librtas_src/common.c | 751 --------------------------------------------------- librtas_src/common.h | 107 -------- librtas_src/ofdt.c | 2 - 4 files changed, 2 insertions(+), 862 deletions(-) delete mode 100644 librtas_src/common.c delete mode 100644 librtas_src/common.h diff --git a/librtas_src/Makefile b/librtas_src/Makefile index 4ef70f6..84c52dc 100644 --- a/librtas_src/Makefile +++ b/librtas_src/Makefile @@ -11,10 +11,10 @@ LIBRTAS_SONAME = librtas.so LIBRTAS_STATIC = librtas.a LIBRTAS = $(LIBRTAS_SONAME).$(VERSION) -LIBRTAS_OBJS = common.o ofdt.o syscall_calls.o syscall_rmo.o +LIBRTAS_OBJS = ofdt.o syscall_calls.o syscall_rmo.o LIBRTAS_HDR = librtas.h -HEADERS = $(LIBRTAS_HDR) common.h +HEADERS = $(LIBRTAS_HDR) CFLAGS += -fPIC -DPIC LDFLAGS += -shared -Wl,-soname -Wl,$(LIBRTAS_SONAME).$(MAJOR_NO) diff --git a/librtas_src/common.c b/librtas_src/common.c deleted file mode 100644 index 2c2c630..0000000 --- a/librtas_src/common.c +++ /dev/null @@ -1,751 +0,0 @@ -/** - * @file common.c - * - * Copyright (C) 2005 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author John Rose <joh...@us...> - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include "librtas.h" -#include "common.h" - -extern struct rtas_operations syscall_rtas_ops; -extern struct rtas_operations procfs_rtas_ops; - -struct librtas_config config = { NULL, 0ll, 0 }; - -#define SANITY_CHECKS(_name) \ - /* Check credentials */ \ - if (geteuid() != (uid_t) 0) \ - return RTAS_PERM; \ - \ - /* Check for any kernel RTAS interface */ \ - if (config.rtas_ops == NULL) \ - if (init_interface()) \ - return RTAS_KERNEL_INT; \ - \ - /* Check for kernel implementation of function */ \ - if (config.rtas_ops->_name == NULL) \ - return RTAS_KERNEL_IMP - -#define CALL_RTAS_METHOD(_name, _token, _args...) \ - SANITY_CHECKS(_name); \ - \ - /* Call interface-specific RTAS routine, \ - * passing in token */ \ - return config.rtas_ops->_name(_token, ##_args) - -#define CALL_HELPER_METHOD(_name, _args...) \ - SANITY_CHECKS(_name); \ - \ - /* Call interface-specific helper routine */ \ - return config.rtas_ops->_name(_args) \ - -#define MAX_PATH_LEN 80 - -/** - * open_proc_rtas_file - * @brief Open the proc rtas file - * - * @param name filename to open - * @param mode mode to open file in - * @return results of open() call - */ -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]; - int npaths; - int fd; - int i; - - npaths = sizeof(proc_rtas_paths) / sizeof(char *); - for (i = 0; i < npaths; i++) { - sprintf(full_name, "%s/%s", proc_rtas_paths[i], name); - fd = open(full_name, mode, S_IRUSR | S_IWUSR); - if (fd >= 0) - break; - } - - if (fd < 0) - dbg1("Failed to open %s\n", full_name); - - return fd; -} - -/** - * init_interface - * @brief Initialize the librtas interface to use - * - * @return 0 on sucess, 1 on failure - */ -static int init_interface() -{ - if (syscall_rtas_ops.interface_exists()) - config.rtas_ops = &syscall_rtas_ops; - else if (procfs_rtas_ops.interface_exists()) - config.rtas_ops = &procfs_rtas_ops; - else - return 1; - - return 0; -} - -/** - * rtas_activate_firmware - * @brief Interface for ibm,activate-firmware rtas call - * - * @return 0 on success, !0 on failure - */ -int rtas_activate_firmware() -{ - int token = rtas_token("ibm,activate-firmware"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(activate_firmware, token); -} - -/** - * rtas_cfg_connector - * @brief Interface for ibm,configure-connector rtas call - * - * @param workarea buffer containg args to ibm,configure-connector - * @return 0 on success, !0 on failure - */ -int rtas_cfg_connector(char *workarea) -{ - int token = rtas_token("ibm,configure-connector"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(cfg_connector, token, workarea); -} - -/** - * rtas_delay_timeout - * @brief Interface to retrieve the rtas timeout delay - * - * @param timeout_ms timeout in milli-seconds - * @return delay time - */ -int rtas_delay_timeout(uint64_t timeout_ms) -{ - CALL_HELPER_METHOD(delay_timeout, timeout_ms); -} - -/** - * rtas_diaply_char - * @brief Interface for display-character rtas call - * - * @param c character to display - * @return 0 on success, !0 otherwise - */ -int rtas_display_char(char c) -{ - int token = rtas_token("display-character"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(display_char, token, c); -} - -/** - * rtas_diaplay_msg - * @brief Interface for ibm,display-message rtas call - * - * @param buf message to display - * @return 0 on success, !0 otherwise - */ -int rtas_display_msg(char *buf) -{ - int token = rtas_token("ibm,display-message"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(display_msg, token, buf); -} - -/** - * rtas_errinjct - * @brief Interface to the ibm,errinjct rtas call - * - * @param etoken errinjct token - * @param otoken errinjct open token - * @param workarea additional args to ibm,errinjct - * @return 0 on success, !0 otherwise - */ -int rtas_errinjct(int etoken, int otoken, char *workarea) -{ - int token = rtas_token("ibm,errinjct"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(errinjct, token, etoken, otoken, workarea); -} - -/** - * rtas_errinjct_close - * @brief Inerface to close the ibm,errinjct facility - * - * @param otoken errinjct open token - * @return 0 on success, !0 otherwise - */ -int rtas_errinjct_close(int otoken) -{ - int token = rtas_token("ibm,close-errinjct"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(errinjct_close, token, otoken); -} - -/** - * rtas_errinjct_open - * @brief Interface to open the ibm,errinjct facility - * - * This call will set the value refrenced by otoken to the open token - * for the ibm,errinjct facility - * - * @param otoken pointer to open token - * @return 0 on success, !0 otherwise - */ -int rtas_errinjct_open(int *otoken) -{ - int token = rtas_token("ibm,open-errinjct"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(errinjct_open, token, otoken); -} - -/** - * rtas_free_rmp_buffer - * @brief free the rmo buffer used by librtas - * - * @param buf rmo buffer to free - * @param phys_addr physical address of the buffer - * @param size buf size - * @return 0 on success, !0 otherwise - */ -int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size) -{ - CALL_HELPER_METHOD(free_rmo_buffer, buf, phys_addr, size); -} - -/** - * rtas_get_config_addr_info2 - * @brief Interface to ibm,get-config-addr-info2 rtas call - * - * On successful completion the info value is returned. - * - * @param config_addr - * @param PHB_Unit_ID - * @param function - * @param info - * @return 0 on success, !0 otherwise - */ -int rtas_get_config_addr_info2(uint32_t config_addr, - uint64_t phb_id, uint32_t function, uint32_t *info) -{ - int token = rtas_token("ibm,get-config-addr-info2"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_config_addr_info2, token, config_addr, - phb_id, function, info); -} - -/** - * rtas_get_dynamic_sensor - * @brief Interface to ibm,get-dynamic-sensor-state rtas call - * - * On success the variable referenced by the state parameter will contain - * the state of the sensor - * - * @param sensor sensor to retrieve - * @param loc_code location code of the sensor - * @param state reference to state variable - * @return 0 on success, !0 otherwise - */ -int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state) -{ - int token = rtas_token("ibm,get-dynamic-sensor-state"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_dynamic_sensor, token, sensor, loc_code, state); -} - -/** - * rtas_get_indices - * @brief Interface to the ibm,get-indices rtas call - * - * @param is_sensor is this index a sensor? - * @param type - * @param workarea additional args to the rtas call - * @param size - * @param start - * @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 token = rtas_token("ibm,get-indices"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_indices, token, is_sensor, type, workarea, size, - start, next); -} - -/** - * rtas_get_power_level - * @brief Interface to the get-power-level rtas call - * - * On success this routine will set the variable referenced by the level - * parameter to the power level - * - * @param powerdomain - * @param level reference to the power level variable - * @return 0 on success, !0 otherwise - */ -int rtas_get_power_level(int powerdomain, int *level) -{ - int token = rtas_token("get-power-level"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_power_level, token, powerdomain, level); -} - -/** - * rtas_get_rmo_buffer - * @brief Retrive the RMO buffer used by librtas - * - * On successful completion the buf parameter will reference an allocated - * area of RMO memory and the phys_addr parameter will refernce the - * physical address of the RMO buffer. - * - * @param size buffer size to retrieve - * @param buf reference to buffer pointer - * @param phys_addr reference to the phys_addr variable - * @return 0 on success, !0 otherwise - */ -int rtas_get_rmo_buffer(size_t size, void **buf, uint32_t * phys_addr) -{ - CALL_HELPER_METHOD(get_rmo_buffer, size, buf, phys_addr); -} - -/** - * rtas_get_sensor - * @brief Interface to the get-sensor-state rtas call - * - * On successful completion the state parameter will reference the current - * state of the sensor - * - * @param sensor - * @param index sensor index - * @param state reference to state variable - * @return 0 on success, !0 otherwise - */ -int rtas_get_sensor(int sensor, int index, int *state) -{ - int token = rtas_token("get-sensor-state"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_sensor, token, sensor, index, state); -} - -/** - * rtas_get_sysparm - * @brief Interface to the ibm,get-system-parameter rtas call - * - * On successful completion the data parameter will contain the system - * parameter results - * - * @param parameter system parameter to retrieve - * @param length data buffer length - * @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 token = rtas_token("ibm,get-system-parameter"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_sysparm, token, parameter, length, data); -} - -/** - * rtas_get_time - * @brief Interface to get-time-of-day rtas call - * - * On successful completion all of the parameters will be filled with - * their respective values for the current time of day. - * - * @param year - * @param month - * @param day - * @param hour - * @param min - * @param sec - * @param nsec - * @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) -{ - int token = rtas_token("get-time-of-day"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_time, token, year, month, day, hour, min, sec, - nsec); -} - -/** - * rtas_get_vpd - * @brief Interface to the ibm,get-vpd rtas call - * - * @param loc_code location code - * @param workarea additional args to rtas call - * @param size - * @param sequence - * @param seq_next - * @param bytes_ret - * @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) -{ - int token = rtas_token("ibm,get-vpd"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(get_vpd, token, loc_code, workarea, size, sequence, - seq_next, bytes_ret); -} - -/** - * rtas_lpar_perftools - * @brief Interface to the ibm,lpa-perftools rtas call - * - * @param subfunc - * @param workarea additional args to the rtas call - * @param length - * @param sequence - * @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 token = rtas_token("ibm,lpar-perftools"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(lpar_perftools, token, subfunc, workarea, length, - sequence, seq_next); -} - -/** - * rtas_platform_dump - * Interface to the ibm,platform-dump rtas call - * - * @param dump_tag - * @param sequence - * @param buffer buffer to write dump to - * @param length buffer length - * @param next_seq - * @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 * next_seq, uint64_t * bytes_ret) -{ - int token = rtas_token("ibm,platform-dump"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(platform_dump, token, dump_tag, sequence, buffer, - length, next_seq, bytes_ret); -} - -/** - * rtas_read_slot_reset - * @brief Interface to the ibm,read-slot-reset-state rtas call - * - * @param cfg_addr configuration address of slot to read - * @param phbid PHB ID of the slot to read - * @param state reference to variable to return slot state in - * @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 token = rtas_token("ibm,read-slot-reset-state"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(read_slot_reset, token, cfg_addr, phbid, state, eeh); -} - -/** - * rtas_scan_log_dump - * @brief Interface to the ibm,scan-log-dump rtas call - * - * @param buffer buffer to return scan log dump in - * @param length size of buffer - * @return 0 on success, !0 otherwise - */ -int rtas_scan_log_dump(void *buffer, size_t length) -{ - int token = rtas_token("ibm,scan-log-dump"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(scan_log_dump, token, buffer, length); -} - -/** - * rtas_set_debug - * @brief Interface to set librtas debug level - * - * @param level debug level to set to - * @return 0 on success, !0 otherwise - */ -int rtas_set_debug(int level) -{ - config.debug = level; - - return 0; -} -/** - * rtas_set_dynamic_indicator - * @brief Interface to the ibm,set-dynamic-indicator rtas call - * - * @param indicator indicator to set - * @param new_value value to set the indicator to - * @param loc_code - * @return 0 on success, !0 otherwise - */ -int rtas_set_dynamic_indicator(int indicator, int new_value, void *loc_code) -{ - int token = rtas_token("ibm,set-dynamic-indicator"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_dynamic_indicator, token, indicator, new_value, - loc_code); -} - -/** - * 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 - * @param phbid PHB ID for slot to set option on - * @param function - * @return 0 on success, !0 otherwise - */ -int rtas_set_eeh_option(uint32_t cfg_addr, uint64_t phbid, int function) -{ - int token = rtas_token("ibm,set-eeh-option"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_eeh_option, token, cfg_addr, phbid, function); -} - -/** - * rtas_set_indicator - * @brief Interface to the set-indicator rtas call - * - * @param indicator indicator to set - * @param index indicator index - * @param new_value value to set the indicator to - * @return 0 on success, !0 otherwise - */ -int rtas_set_indicator(int indicator, int index, int new_value) -{ - int token = rtas_token("set-indicator"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_indicator, token, indicator, index, new_value); -} - -/** - * rtas_set_power_level - * @brief Interface to the set-power-level rtas call - * - * @param powerdomain - * @param level power level to set to - * @param setlevel - * @return 0 on success, !0 otherwise - */ -int rtas_set_power_level(int powerdomain, int level, int *setlevel) -{ - int token = rtas_token("set-power-level"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_power_level, token, powerdomain, level, setlevel); -} - -/** - * rtas_set_poweron_time - * @brief interface to the set-time-for-power-on rtas call - * - * @param year year to power on - * @param month month to power on - * @param day day to power on - * @param hour hour to power on - * @param min minute to power on - * @param sec second to power on - * @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 token = rtas_token("set-time-for-power-on"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_poweron_time, token, year, month, day, hour, min, - sec, nsec); -} - -/** - * rtas_set_sysparm - * @brief Interface to the ibm,set-system-parameter rtas call - * - * @param parameter - * @param data - * @return 0 on success, !0 otherwise - */ -int rtas_set_sysparm(unsigned int parameter, char *data) -{ - int token = rtas_token("ibm,set-system-parameter"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_sysparm, token, parameter, data); -} - -/** - * rtas_set_time - * @brief Interface to the set-time-of-day rtas call - * - * @param year year to set time to - * @param month month to set time to - * @param day day to set time to - * @param hour hour to set time to - * @param min minute to set time to - * @param sec second to set time to - * @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 token = rtas_token("set-time-of-day"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(set_time, token, year, month, day, hour, min, sec, - nsec); -} - -/** - * rtas_suspend_me - * @brief Interface for ibm,suspend-me rtas call - * - * @return 0 on success, !0 on failure - */ -int rtas_suspend_me(uint64_t streamid) -{ - int token = rtas_token("ibm,suspend-me"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(suspend_me, token, streamid); -} - -/** - * rtas_update_nodes - * @brief Interface for ibm,update-nodes rtas call - * - * @param workarea input output work area for the rtas call - * @param scope of call - * @return 0 on success, !0 on failure - */ -int rtas_update_nodes(char *workarea, unsigned int scope ) -{ - int token = rtas_token("ibm,update-nodes"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(update_nodes, token, workarea, scope); -} - -/** - * rtas_update_properties - * @brief Interface for ibm,update-properties rtas call - * - * @param workarea input output work area for the rtas call - * @param scope of call - * @return 0 on success, !0 on failure - */ -int rtas_update_properties(char *workarea, unsigned int scope ) -{ - int token = rtas_token("ibm,update-properties"); - - if (token < 0) - return token; - - CALL_RTAS_METHOD(update_properties, token, workarea, scope); -} diff --git a/librtas_src/common.h b/librtas_src/common.h deleted file mode 100644 index eb7e821..0000000 --- a/librtas_src/common.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * @file common.h - * - * Copyright (C) 2005 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author John Rose <joh...@us...> - */ - -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include <stdio.h> -#include <stdint.h> - -#define RC_BUSY -2 -#define EXTENDED_DELAY_MIN 9900 -#define EXTENDED_DELAY_MAX 9905 - -#define PAGE_SIZE 4096 - -/* - * When adding an RTAS call, argument list below should - * consist of an int token followed by the call arguments - * defined in librtas.h - */ -struct rtas_operations { - int (*activate_firmware)(int token); - int (*cfg_connector)(int token, char *workarea); - int (*delay_timeout)(uint64_t timeout_ms); - int (*display_char)(int token, char c); - int (*display_msg)(int token, char *buf); - int (*errinjct)(int token, int etoken, int otoken, char *workarea); - int (*errinjct_close)(int token, int otoken); - int (*errinjct_open)(int token, int *otoken); - int (*free_rmo_buffer)(void *buf, uint32_t phys_addr, size_t size); - int (*get_config_addr_info2)(int token, uint32_t cfg_addr, - uint64_t phb_id, uint32_t func, uint32_t *info); - int (*get_dynamic_sensor)(int token, int sensor, void *loc_code, - int *state); - int (*get_indices)(int token, int is_sensor, int type, char *workarea, - size_t size, int start, int *next); - int (*get_power_level)(int token, int powerdomain, int *level); - int (*get_rmo_buffer)(size_t size, void **buf, uint32_t *phys_addr); - int (*get_sensor)(int token, int sensor, int index, int *state); - int (*get_sysparm)(int token, unsigned int parameter, - unsigned int length, char *data); - int (*get_time)(int token, uint32_t *year, uint32_t *month, - uint32_t *day, uint32_t *hour, uint32_t *min, - uint32_t *sec, uint32_t *nsec); - int (*get_vpd)(int token, char *loc_code, char *workarea, size_t size, - unsigned int sequence, unsigned int *seq_next, - unsigned int *bytes_ret); - int (*lpar_perftools)(int token, int subfunc, char *workarea, - unsigned int length, unsigned int sequence, - unsigned int *seq_next); - int (*platform_dump)(int token, uint64_t dump_tag, uint64_t sequence, - void *buffer, size_t length, - uint64_t *next_seq, uint64_t *bytes_ret); - int (*read_slot_reset)(int token, uint32_t cfg_addr, uint64_t phbid, - int *state, int *eeh); - int (*scan_log_dump)(int token, void *buffer, size_t length); - int (*set_dynamic_indicator)(int token, int indicator, int new_value, - void *loc_code); - int (*set_eeh_option)(int token, uint32_t cfg_addr, uint64_t phbid, - int function); - int (*set_indicator)(int token, int indicator, int index, - int new_value); - int (*set_power_level)(int token, int powerdomain, int level, - int *setlevel); - int (*set_poweron_time)(int token, uint32_t year, uint32_t month, - uint32_t day, uint32_t hour, uint32_t min, - uint32_t sec, uint32_t nsec); - int (*set_sysparm)(int token, unsigned int parameter, char *data); - int (*set_time)(int token, uint32_t year, uint32_t month, uint32_t day, - uint32_t hour, uint32_t min, uint32_t sec, - uint32_t nsec); - int (*suspend_me)(int token, uint64_t streamid); - int (*update_nodes)(int token, char *workarea, unsigned int scope); - int (*update_properties)(int token, char *workarea, unsigned int scope); - int (*interface_exists)(); -}; - -struct librtas_config { - struct rtas_operations *rtas_ops; - 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 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) \ - -#endif diff --git a/librtas_src/ofdt.c b/librtas_src/ofdt.c index 1a04b25..226735a 100644 --- a/librtas_src/ofdt.c +++ b/librtas_src/ofdt.c @@ -9,13 +9,11 @@ #include <stdlib.h> #include <fcntl.h> -#include <unistd.h> #include <string.h> #include <errno.h> #include <endian.h> #include <byteswap.h> #include "librtas.h" -#include "common.h" static const char *ofdt_rtas_path = "/proc/device-tree/rtas"; -- 1.8.5.2 |
From: Thomas F. <tlf...@li...> - 2014-07-16 20:32:45
|
The procfs interface is no longer used. As a result, it is being removed to simplify librtas. Signed-off-by: Thomas Falcon <tlf...@li...> --- librtas_src/Makefile | 2 +- librtas_src/procfs.h | 49 --------- librtas_src/procfs_calls.c | 262 --------------------------------------------- 3 files changed, 1 insertion(+), 312 deletions(-) delete mode 100644 librtas_src/procfs.h delete mode 100644 librtas_src/procfs_calls.c diff --git a/librtas_src/Makefile b/librtas_src/Makefile index 3a10222..4ef70f6 100644 --- a/librtas_src/Makefile +++ b/librtas_src/Makefile @@ -11,7 +11,7 @@ LIBRTAS_SONAME = librtas.so LIBRTAS_STATIC = librtas.a LIBRTAS = $(LIBRTAS_SONAME).$(VERSION) -LIBRTAS_OBJS = common.o ofdt.o syscall_calls.o syscall_rmo.o procfs_calls.o +LIBRTAS_OBJS = common.o ofdt.o syscall_calls.o syscall_rmo.o LIBRTAS_HDR = librtas.h HEADERS = $(LIBRTAS_HDR) common.h diff --git a/librtas_src/procfs.h b/librtas_src/procfs.h deleted file mode 100644 index b582982..0000000 --- a/librtas_src/procfs.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file procfs.h - * - * Copyright (C) 2005 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author John Rose <joh...@us...> - */ - -#ifndef _PROCFS_H_ -#define _PROCFS_H_ - -#define PFS_BUF_SIZE 4096 - -struct rtas_set_indicator { - int indicator; /* Indicator Token */ - int index; /* Indicator Index */ - int new_value; /* New value or State */ - int status; /* Returned status */ -}; -struct rtas_get_sensor { - int sensor; /* Sensor Token */ - int index; /* Sensor Index */ - int state; /* Returned State of the sensor */ - int status; /* Returned status */ -}; -struct rtas_cfg_connector { - char workarea[PFS_BUF_SIZE]; /* Config work area */ - int status; /* Returned status */ -}; -struct rtas_get_power_level { - int powerdomain; /* Power Domain Token */ - int level; /* Current Power Level */ - int status; /* Returned status */ -}; -struct rtas_set_power_level { - int powerdomain; /* Power Domain Token */ - int level; /* Power Level Token */ - int setlevel; /* Returned Set Power Level */ - int status; /* Returned status */ -}; -struct rtas_get_sysparm { - unsigned int parameter; /* System parameter value */ - char data[PFS_BUF_SIZE]; /* Parameter data */ - unsigned int length; /* Length of data buffer */ - int status; /* Returned status */ -}; - -#endif diff --git a/librtas_src/procfs_calls.c b/librtas_src/procfs_calls.c deleted file mode 100644 index 320365c..0000000 --- a/librtas_src/procfs_calls.c +++ /dev/null @@ -1,262 +0,0 @@ -/** - * @file procfs_calls.c - * - * Copyright (C) 2005 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author John Rose <joh...@us...> - */ - -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include "common.h" -#include "procfs.h" -#include "librtas.h" - -#define CFG_CONN_FILE "cfg_connector" -#define GET_POWER_FILE "get_power" -#define GET_SENSOR_FILE "get_sensor" -#define GET_SYSPARM_FILE "get_sysparm" -#define SET_INDICATOR_FILE "set_indicator" -#define SET_POWER_FILE "set_power" - -int pfs_cfg_connector(int token, char *workarea); -int pfs_get_power(int token, int domain, int *level); -int pfs_get_sensor(int token, int sensor, int index, int *state); -int pfs_get_sysparm(int token, unsigned int parameter, unsigned int length, - char *data); -int pfs_set_indicator(int token, int indicator, int index, int new_value); -int pfs_set_power(int token, int domain, int level, int *setlevel); - -int procfs_interface_exists(); - -struct rtas_operations procfs_rtas_ops = { - .cfg_connector = pfs_cfg_connector, - .get_power_level = pfs_get_power, - .get_sensor = pfs_get_sensor, - .get_sysparm = pfs_get_sysparm, - .set_indicator = pfs_set_indicator, - .set_power_level = pfs_set_power, - .interface_exists = procfs_interface_exists, -}; - -/** - * do_rtas_op - * @brief Perform the actual rtas call via the supplied procfs file - * - * @param proc_filename procfs filename for the rtas call - * @param buf buffer to read rtas call results into - * @param buf_size size of the buf - * @return 0 on success, !0 otherwise - */ -static int do_rtas_op(const char *proc_filename, void *buf, size_t buf_size) -{ - int rc; - int fd; - - /* Open /proc file */ - fd = open_proc_rtas_file(proc_filename, O_RDWR); - if (fd <= 0) - return RTAS_KERNEL_IMP; - - /* Write RTAS call args buf */ - rc = write(fd, buf, buf_size); - if (rc < (int)buf_size) { - fprintf(stderr, "Failed to write proc file %s\n", - proc_filename); - return RTAS_IO_ASSERT; - } - - /* Read results */ - rc = read(fd, buf, buf_size); - if (rc < (int)buf_size) { - fprintf(stderr, "Failed to read proc file %s\n", proc_filename); - return RTAS_IO_ASSERT; - } - - /* Close /proc file */ - close(fd); - - return 0; -} - -/** - * pfs_cfg_connector - * @brief Set up arguments for procfs cfg-connector rtas call - * - * @param token - * @param workarea - * @return 0 on success, !0 otherwise - */ -int pfs_cfg_connector(int token, char *workarea) -{ - struct rtas_cfg_connector args; - int rc; - - memcpy(&args.workarea[0], workarea, PAGE_SIZE); - rc = do_rtas_op(CFG_CONN_FILE, &args, - sizeof(struct rtas_cfg_connector)); - if (rc) - return rc; - - memcpy(workarea, &args.workarea[0], PAGE_SIZE); - - return args.status; -} - -/** - * pfs_get_power - * @brief Set up args for procfs get-power-level rtas call - * - * @param token - * @param domain - * @param level - * @return 0 on success, !0 otherwise - */ -int pfs_get_power(int token, int domain, int *level) -{ - struct rtas_get_power_level args; - int rc; - - args.powerdomain = domain; - - rc = do_rtas_op(GET_POWER_FILE, &args, - sizeof(struct rtas_get_power_level)); - if (rc) - return rc; - - *level = args.level; - - return args.status; -} - -/** - * pfs_get_sensor - * @brief Set up args for procfs get-sensor-state rtas call - * - * @param token - * @param sensor - * @param index - * @param state - * @return 0 on success, !0 otherwise - */ -int pfs_get_sensor(int token, int sensor, int index, int *state) -{ - struct rtas_get_sensor args; - int rc; - - args.sensor = sensor; - args.index = index; - - rc = do_rtas_op(GET_SENSOR_FILE, &args, sizeof(struct rtas_get_sensor)); - if (rc) - return rc; - - *state = args.state; - - return args.status; -} - -/** - * pfs_get_sysparm - * @brief Set up call to procfs get-system-parameter rtas call - * - * @param token - * @param parameter - * @param length - * @param data - * @return 0 on success, !0 otherwise - */ -int pfs_get_sysparm(int token, unsigned int parameter, unsigned int length, - char *data) -{ - struct rtas_get_sysparm args; - int rc; - - args.parameter = parameter; - args.length = length; - memcpy(&args.data[0], data, PAGE_SIZE); - - rc = do_rtas_op(GET_SYSPARM_FILE, &args, - sizeof(struct rtas_get_sysparm)); - - if (args.status == 0) - memcpy(data, &args.data[0], PAGE_SIZE); - - return args.status; -} - -/** - * pfs_set_indicator - * @brief Set up call to procfs set-indicator rtas call - * - * @param token - * @param indicator - * @param index - * @param new_value - * @return 0 on success, !0 otherwise - */ -int pfs_set_indicator(int token, int indicator, int index, int new_value) -{ - struct rtas_set_indicator args; - int rc; - - args.indicator = indicator; - args.index = index; - args.new_value = new_value; - - rc = do_rtas_op(SET_INDICATOR_FILE, &args, - sizeof(struct rtas_set_indicator)); - if (rc) - return rc; - - return args.status; -} - -/** - * pfs_set_power - * - * @param token - * @param domain - * @param level - * @param setlevel - * @return 0 on success, !0 otherwise - */ -int pfs_set_power(int token, int domain, int level, int *setlevel) -{ - struct rtas_set_power_level args; - int rc; - - args.powerdomain = domain; - args.level = level; - - rc = do_rtas_op(SET_POWER_FILE, &args, - sizeof(struct rtas_set_power_level)); - if (rc) - return rc; - - *setlevel = args.setlevel; - - return args.status; -} - -/** - * procfs_interfac_exists - * @brief VAlidate that the procfs interface to rtas exists - * - * @return 0 on success, !0 otherwise - */ -int procfs_interface_exists() -{ - int fd; - int exists; - - fd = open_proc_rtas_file("get_sensor", O_RDWR); - exists = (fd >= 0); - - if (exists) - close(fd); - - return exists; -} -- 1.8.5.2 |
From: Thomas F. <tlf...@li...> - 2014-07-16 20:32:45
|
This group of patches attempts to remove the procfs interface and to simplify librtas by removing common.c and using the rtas calls implemented in the syscall interface only. Thomas Falcon (4): librtas: removing procfs interface librtas: removal of common code librtas: common.h merged into librtas.h librtas: rtas calls fully implemented in syscalls librtas_src/Makefile | 4 +- librtas_src/common.c | 751 ---------------------------------- librtas_src/common.h | 107 ----- librtas_src/librtas.h | 52 ++- librtas_src/ofdt.c | 2 - librtas_src/procfs.h | 49 --- librtas_src/procfs_calls.c | 262 ------------ librtas_src/syscall.h | 6 +- librtas_src/syscall_calls.c | 955 +++++++++++++++++++++++++++++--------------- librtas_src/syscall_rmo.c | 57 ++- 10 files changed, 717 insertions(+), 1528 deletions(-) delete mode 100644 librtas_src/common.c delete mode 100644 librtas_src/common.h delete mode 100644 librtas_src/procfs.h delete mode 100644 librtas_src/procfs_calls.c -- 1.8.5.2 |
From: Thomas F. <tlf...@li...> - 2014-07-16 20:32:45
|
Code in common.h was added to librtas.h Signed-off-by: Thomas Falcon <tlf...@li...> --- librtas_src/librtas.h | 52 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index 98fa469..eaeda0a 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -10,6 +10,8 @@ #ifndef _LIBRTAS_H_ #define _LIBRTAS_H_ +#include <stdio.h> +#include <unistd.h> #include <sys/types.h> #include <stdint.h> @@ -23,16 +25,16 @@ #define RTAS_IO_ASSERT -1098 /* Unexpected I/O Error */ #define RTAS_UNKNOWN_OP -1099 /* No Firmware Implementation of Function */ +#define RC_BUSY -2 +#define EXTENDED_DELAY_MIN 9900 +#define EXTENDED_DELAY_MAX 9905 + +#define PAGE_SIZE 4096 + /* 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 new function in common.c. Use the existing - * ones as an example. - * 3) A function pointer definition in struct rtas_operations in common.h. - * Prepend a "token" argument to the argument list. - * 4) An implementation-specific version of the RTAS function, in - * syscall_calls.c and/or procfs_calls.c. Remember to add your new - * function to the rtas_operations struct at the top of the file. + * 2) An implementation of the RTAS function, in librtas_calls.c. */ #ifdef __cplusplus @@ -48,7 +50,8 @@ extern int rtas_errinjct(int etoken, int otoken, char *workarea); extern int rtas_errinjct_close(int otoken); extern int rtas_errinjct_open(int *otoken); extern int rtas_free_rmo_buffer(void *buf, uint32_t phys_addr, size_t size); -extern int rtas_get_config_addr_info2(uint32_t cfg_addr, uint64_t phb_id, uint32_t func, uint32_t *info); +extern int rtas_get_config_addr_info2(uint32_t cfg_addr, uint64_t phb_id, + uint32_t func, uint32_t *info); extern int rtas_get_dynamic_sensor(int sensor, void *loc_code, int *state); extern int rtas_get_indices(int is_sensor, int type, char *workarea, size_t size, int start, int *next); @@ -93,5 +96,36 @@ extern int rtas_update_properties(char *workarea, unsigned int scope); #ifdef __cplusplus } #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 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) \ + return RTAS_PERM; \ + \ + /* Check for any kernel RTAS interface */ \ + if (!interface_exists()) \ + return RTAS_KERNEL_INT; + #endif /* _LIBRTAS_H_ */ -- 1.8.5.2 |
From: Anshuman K. <kha...@li...> - 2014-07-14 10:56:45
|
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...> --- librtas_src/syscall_calls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 01d6ce8..da8f25b 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -568,7 +568,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) int status; int rc; - size = *(uint32_t *)loc_code + sizeof(uint32_t); + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) @@ -1074,7 +1074,7 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, int status; int rc; - size = *(uint32_t *)loc_code + sizeof(uint32_t); + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) -- 1.8.5.2 |
From: Anshuman K. <kha...@li...> - 2014-07-14 10:50:54
|
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...> --- librtas_src/syscall_calls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 01d6ce8..da8f25b 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -568,7 +568,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) int status; int rc; - size = *(uint32_t *)loc_code + sizeof(uint32_t); + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) @@ -1074,7 +1074,7 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, int status; int rc; - size = *(uint32_t *)loc_code + sizeof(uint32_t); + size = be32toh(*(uint32_t *)loc_code) + sizeof(uint32_t); rc = sc_get_rmo_buffer(size, &locbuf, &loc_pa); if (rc) -- 1.8.5.2 |
From: Nathan F. <nf...@li...> - 2014-07-02 17:11:57
|
On 07/02/2014 04:29 AM, Vasant Hegde wrote: > On 06/28/2014 04:01 AM, Thomas Falcon wrote: >> As the procfs interface is rarely used, it is being > > I think we don't use procfs interface now a days.. Its outdated . > >> removed to simplify the librtas codebase. >> >> Signed-off-by: Thomas Falcon <tlf...@li...> >> --- >> Note: >> >> As this proposed patch does little more than remove the procfs interface, > > Not sure what extra this does apart from removing procfs interface and adjusting makefiles. > >> I would appreciate any comments regarding any further simplifications >> of librtas. Thanks. > > I quickly glanced through the code and it looks good.. > > Once we remove procfs interface we just left with syscall interface.. Now we can further simplify by removing common.c logic..We can simply implement the RTAS call itself.. But considering the amount of effort involved and the benefit we get , its probably ok to keep existing logic as is. > > I will leave it to Nathan to take final call. > This looks good. It would be nice to get rid of the code in common.c and just go directly to the rtas call routines. That would take some work and is definitely a lower priority item, but it would clean up the code a lot. -Nathan |
From: Vasant H. <heg...@li...> - 2014-07-02 09:29:29
|
On 06/28/2014 04:01 AM, Thomas Falcon wrote: > As the procfs interface is rarely used, it is being I think we don't use procfs interface now a days.. Its outdated . > removed to simplify the librtas codebase. > > Signed-off-by: Thomas Falcon <tlf...@li...> > --- > Note: > > As this proposed patch does little more than remove the procfs interface, Not sure what extra this does apart from removing procfs interface and adjusting makefiles. > I would appreciate any comments regarding any further simplifications > of librtas. Thanks. I quickly glanced through the code and it looks good.. Once we remove procfs interface we just left with syscall interface.. Now we can further simplify by removing common.c logic..We can simply implement the RTAS call itself.. But considering the amount of effort involved and the benefit we get , its probably ok to keep existing logic as is. I will leave it to Nathan to take final call. -Vasant |
From: Vasant H. <heg...@li...> - 2014-07-02 09:21:53
|
On 07/01/2014 10:52 PM, Thomas Falcon wrote: > Some mistakes were made in adding little endian support for the > sc_platform_dump function. As the values being handled are 64-bit integers, > it makes much more sense to use the 64-bit byteswap function. The > endianness of seq_next also needs to be handled. > > Signed-off-by: Thomas Falcon <tlf...@li...> > --- > librtas_src/syscall_calls.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c > index 01d6ce8..8779fb7 100644 > --- a/librtas_src/syscall_calls.c > +++ b/librtas_src/syscall_calls.c > @@ -965,12 +965,9 @@ 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); > Tom, We get BE data for status variable as well. Shouldn't we convert status value in handle_delay() call? Rest of the patch looks good. -Vasant > - next_hi = be32toh(next_hi); > - next_lo = be32toh(next_lo); > - bytes_hi = be32toh(bytes_hi); > - bytes_lo = be32toh(bytes_lo); > - > - *bytes_ret = BITS64(be32toh(bytes_hi), 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, > |
From: Thomas F. <tlf...@li...> - 2014-07-01 17:22:40
|
Some mistakes were made in adding little endian support for the sc_platform_dump function. As the values being handled are 64-bit integers, it makes much more sense to use the 64-bit byteswap function. The endianness of seq_next also needs to be handled. Signed-off-by: Thomas Falcon <tlf...@li...> --- librtas_src/syscall_calls.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 01d6ce8..8779fb7 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -965,12 +965,9 @@ 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); - next_hi = be32toh(next_hi); - next_lo = be32toh(next_lo); - bytes_hi = be32toh(bytes_hi); - bytes_lo = be32toh(bytes_lo); - - *bytes_ret = BITS64(be32toh(bytes_hi), 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: Thomas F. <tlf...@li...> - 2014-06-27 22:31:40
|
As the procfs interface is rarely used, it is being removed to simplify the librtas codebase. Signed-off-by: Thomas Falcon <tlf...@li...> --- Note: As this proposed patch does little more than remove the procfs interface, I would appreciate any comments regarding any further simplifications of librtas. Thanks. --- librtas_src/Makefile | 2 +- librtas_src/common.c | 3 - librtas_src/librtas.h | 4 +- librtas_src/procfs.h | 49 --------- librtas_src/procfs_calls.c | 262 --------------------------------------------- 5 files changed, 3 insertions(+), 317 deletions(-) delete mode 100644 librtas_src/procfs.h delete mode 100644 librtas_src/procfs_calls.c diff --git a/librtas_src/Makefile b/librtas_src/Makefile index 3a10222..4ef70f6 100644 --- a/librtas_src/Makefile +++ b/librtas_src/Makefile @@ -11,7 +11,7 @@ LIBRTAS_SONAME = librtas.so LIBRTAS_STATIC = librtas.a LIBRTAS = $(LIBRTAS_SONAME).$(VERSION) -LIBRTAS_OBJS = common.o ofdt.o syscall_calls.o syscall_rmo.o procfs_calls.o +LIBRTAS_OBJS = common.o ofdt.o syscall_calls.o syscall_rmo.o LIBRTAS_HDR = librtas.h HEADERS = $(LIBRTAS_HDR) common.h diff --git a/librtas_src/common.c b/librtas_src/common.c index 2c2c630..f423ea6 100644 --- a/librtas_src/common.c +++ b/librtas_src/common.c @@ -15,7 +15,6 @@ #include "common.h" extern struct rtas_operations syscall_rtas_ops; -extern struct rtas_operations procfs_rtas_ops; struct librtas_config config = { NULL, 0ll, 0 }; @@ -88,8 +87,6 @@ static int init_interface() { if (syscall_rtas_ops.interface_exists()) config.rtas_ops = &syscall_rtas_ops; - else if (procfs_rtas_ops.interface_exists()) - config.rtas_ops = &procfs_rtas_ops; else return 1; diff --git a/librtas_src/librtas.h b/librtas_src/librtas.h index 98fa469..5808762 100644 --- a/librtas_src/librtas.h +++ b/librtas_src/librtas.h @@ -31,8 +31,8 @@ * 3) A function pointer definition in struct rtas_operations in common.h. * Prepend a "token" argument to the argument list. * 4) An implementation-specific version of the RTAS function, in - * syscall_calls.c and/or procfs_calls.c. Remember to add your new - * function to the rtas_operations struct at the top of the file. + * syscall_calls.c. Remember to add your new function to the + * rtas_operations struct at the top of the file. */ #ifdef __cplusplus diff --git a/librtas_src/procfs.h b/librtas_src/procfs.h deleted file mode 100644 index b582982..0000000 --- a/librtas_src/procfs.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file procfs.h - * - * Copyright (C) 2005 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author John Rose <joh...@us...> - */ - -#ifndef _PROCFS_H_ -#define _PROCFS_H_ - -#define PFS_BUF_SIZE 4096 - -struct rtas_set_indicator { - int indicator; /* Indicator Token */ - int index; /* Indicator Index */ - int new_value; /* New value or State */ - int status; /* Returned status */ -}; -struct rtas_get_sensor { - int sensor; /* Sensor Token */ - int index; /* Sensor Index */ - int state; /* Returned State of the sensor */ - int status; /* Returned status */ -}; -struct rtas_cfg_connector { - char workarea[PFS_BUF_SIZE]; /* Config work area */ - int status; /* Returned status */ -}; -struct rtas_get_power_level { - int powerdomain; /* Power Domain Token */ - int level; /* Current Power Level */ - int status; /* Returned status */ -}; -struct rtas_set_power_level { - int powerdomain; /* Power Domain Token */ - int level; /* Power Level Token */ - int setlevel; /* Returned Set Power Level */ - int status; /* Returned status */ -}; -struct rtas_get_sysparm { - unsigned int parameter; /* System parameter value */ - char data[PFS_BUF_SIZE]; /* Parameter data */ - unsigned int length; /* Length of data buffer */ - int status; /* Returned status */ -}; - -#endif diff --git a/librtas_src/procfs_calls.c b/librtas_src/procfs_calls.c deleted file mode 100644 index 320365c..0000000 --- a/librtas_src/procfs_calls.c +++ /dev/null @@ -1,262 +0,0 @@ -/** - * @file procfs_calls.c - * - * Copyright (C) 2005 IBM Corporation - * Common Public License Version 1.0 (see COPYRIGHT) - * - * @author John Rose <joh...@us...> - */ - -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include "common.h" -#include "procfs.h" -#include "librtas.h" - -#define CFG_CONN_FILE "cfg_connector" -#define GET_POWER_FILE "get_power" -#define GET_SENSOR_FILE "get_sensor" -#define GET_SYSPARM_FILE "get_sysparm" -#define SET_INDICATOR_FILE "set_indicator" -#define SET_POWER_FILE "set_power" - -int pfs_cfg_connector(int token, char *workarea); -int pfs_get_power(int token, int domain, int *level); -int pfs_get_sensor(int token, int sensor, int index, int *state); -int pfs_get_sysparm(int token, unsigned int parameter, unsigned int length, - char *data); -int pfs_set_indicator(int token, int indicator, int index, int new_value); -int pfs_set_power(int token, int domain, int level, int *setlevel); - -int procfs_interface_exists(); - -struct rtas_operations procfs_rtas_ops = { - .cfg_connector = pfs_cfg_connector, - .get_power_level = pfs_get_power, - .get_sensor = pfs_get_sensor, - .get_sysparm = pfs_get_sysparm, - .set_indicator = pfs_set_indicator, - .set_power_level = pfs_set_power, - .interface_exists = procfs_interface_exists, -}; - -/** - * do_rtas_op - * @brief Perform the actual rtas call via the supplied procfs file - * - * @param proc_filename procfs filename for the rtas call - * @param buf buffer to read rtas call results into - * @param buf_size size of the buf - * @return 0 on success, !0 otherwise - */ -static int do_rtas_op(const char *proc_filename, void *buf, size_t buf_size) -{ - int rc; - int fd; - - /* Open /proc file */ - fd = open_proc_rtas_file(proc_filename, O_RDWR); - if (fd <= 0) - return RTAS_KERNEL_IMP; - - /* Write RTAS call args buf */ - rc = write(fd, buf, buf_size); - if (rc < (int)buf_size) { - fprintf(stderr, "Failed to write proc file %s\n", - proc_filename); - return RTAS_IO_ASSERT; - } - - /* Read results */ - rc = read(fd, buf, buf_size); - if (rc < (int)buf_size) { - fprintf(stderr, "Failed to read proc file %s\n", proc_filename); - return RTAS_IO_ASSERT; - } - - /* Close /proc file */ - close(fd); - - return 0; -} - -/** - * pfs_cfg_connector - * @brief Set up arguments for procfs cfg-connector rtas call - * - * @param token - * @param workarea - * @return 0 on success, !0 otherwise - */ -int pfs_cfg_connector(int token, char *workarea) -{ - struct rtas_cfg_connector args; - int rc; - - memcpy(&args.workarea[0], workarea, PAGE_SIZE); - rc = do_rtas_op(CFG_CONN_FILE, &args, - sizeof(struct rtas_cfg_connector)); - if (rc) - return rc; - - memcpy(workarea, &args.workarea[0], PAGE_SIZE); - - return args.status; -} - -/** - * pfs_get_power - * @brief Set up args for procfs get-power-level rtas call - * - * @param token - * @param domain - * @param level - * @return 0 on success, !0 otherwise - */ -int pfs_get_power(int token, int domain, int *level) -{ - struct rtas_get_power_level args; - int rc; - - args.powerdomain = domain; - - rc = do_rtas_op(GET_POWER_FILE, &args, - sizeof(struct rtas_get_power_level)); - if (rc) - return rc; - - *level = args.level; - - return args.status; -} - -/** - * pfs_get_sensor - * @brief Set up args for procfs get-sensor-state rtas call - * - * @param token - * @param sensor - * @param index - * @param state - * @return 0 on success, !0 otherwise - */ -int pfs_get_sensor(int token, int sensor, int index, int *state) -{ - struct rtas_get_sensor args; - int rc; - - args.sensor = sensor; - args.index = index; - - rc = do_rtas_op(GET_SENSOR_FILE, &args, sizeof(struct rtas_get_sensor)); - if (rc) - return rc; - - *state = args.state; - - return args.status; -} - -/** - * pfs_get_sysparm - * @brief Set up call to procfs get-system-parameter rtas call - * - * @param token - * @param parameter - * @param length - * @param data - * @return 0 on success, !0 otherwise - */ -int pfs_get_sysparm(int token, unsigned int parameter, unsigned int length, - char *data) -{ - struct rtas_get_sysparm args; - int rc; - - args.parameter = parameter; - args.length = length; - memcpy(&args.data[0], data, PAGE_SIZE); - - rc = do_rtas_op(GET_SYSPARM_FILE, &args, - sizeof(struct rtas_get_sysparm)); - - if (args.status == 0) - memcpy(data, &args.data[0], PAGE_SIZE); - - return args.status; -} - -/** - * pfs_set_indicator - * @brief Set up call to procfs set-indicator rtas call - * - * @param token - * @param indicator - * @param index - * @param new_value - * @return 0 on success, !0 otherwise - */ -int pfs_set_indicator(int token, int indicator, int index, int new_value) -{ - struct rtas_set_indicator args; - int rc; - - args.indicator = indicator; - args.index = index; - args.new_value = new_value; - - rc = do_rtas_op(SET_INDICATOR_FILE, &args, - sizeof(struct rtas_set_indicator)); - if (rc) - return rc; - - return args.status; -} - -/** - * pfs_set_power - * - * @param token - * @param domain - * @param level - * @param setlevel - * @return 0 on success, !0 otherwise - */ -int pfs_set_power(int token, int domain, int level, int *setlevel) -{ - struct rtas_set_power_level args; - int rc; - - args.powerdomain = domain; - args.level = level; - - rc = do_rtas_op(SET_POWER_FILE, &args, - sizeof(struct rtas_set_power_level)); - if (rc) - return rc; - - *setlevel = args.setlevel; - - return args.status; -} - -/** - * procfs_interfac_exists - * @brief VAlidate that the procfs interface to rtas exists - * - * @return 0 on success, !0 otherwise - */ -int procfs_interface_exists() -{ - int fd; - int exists; - - fd = open_proc_rtas_file("get_sensor", O_RDWR); - exists = (fd >= 0); - - if (exists) - close(fd); - - return exists; -} -- 1.8.5.2 |
From: Suzuki K. P. <su...@in...> - 2014-06-27 06:07:48
|
On 06/27/2014 05:47 AM, Sam Bobroff wrote: > On 26/06/14 17:50, Suzuki K. Poulose wrote: >> On 06/18/2014 11:15 AM, Sam Bobroff wrote: >>> Hi librtas developers, >>> >>> While using librtas to call the RTAS "ibm,get-system-parameter" function >>> , I noticed some odd behavior. (These questions probably only apply when librtas >>> is using the syscall backend and making RTAS calls rather than reading from proc.) >>> >>> First, when calling rtas_get_sysparm(token, buflen, buf) any unused part of buf is >>> filled with garbage (often the result of previous calls). This is because the code >>> in sc_get_sysparm() uses a separately allocated, uninitialized, buffer for the RTAS >>> call and always copies the entire result into buf even though only some bytes have >>> been written to by the RTAS call. It seems like this would be less surprising if any >>> unused bytes remained unchanged. >> I guess this should be retained as it is. The first two bytes of the o/p >> buffer tells you the size of the data anyways. So you shouldn't worry >> about whats beyond the size. > > Right. Would you like me to send a patch? I meant, we don't need the above change. You have the length of the actual data copied in the first two bytes. So, the user need not worry about whats beyond the 'bytes' written by RTAS. > >>> Second, calling rtas_get_sysparm(token, buflen, buf) with a zero length buffer fails >>> with RTAS_IO_ASSERT but I think the call is supposed to succeed and just return no data. >>> The failure is not coming from the RTAS call, but instead from librtas attempting to mmap() >>> a zero-size area. If I tweak the code to avoid the mmap() on a zero size then the call succeeds. >>> >> There is a catch here. When you return a success, the first two bytes of >> the buffer should indicate the length of the data, even if it is >> truncated in the o/p due to requested_length < length_of_param_data. So >> a 0 length could cause issues where the buffer doesn't indicate the >> length of the data on Success, which is against the expectations of API. >> Also we cannot write the length to the buffer on a 0 length request, >> because we may be writing to a buffer which doesn't even have 2 b >> length (which is legal from the users point of view). > > I'm not sure if I understand your point. Which API do you mean? rtas_get_sysparm () > > Aren't the length bytes written by RTAS (and not by librtas) and wouldn't the edge cases like this be up to RTAS (and the caller) to handle? Why should librtas be involved in it? > Yes and no. RTAS writes to a buffer. librtas copies the data from the buffer to the 'user buffer'. > Are you saying that librtas needs to protect the user from this case or that we need to protect RTAS from it? > No. As per PAPR, when rtas_get_sysparm() call succeeds, the first two bytes int the buffer should indicate the length of the data. In this case, we cannot satisfy this requirement as we cannot trust the user supplied buffer (since the length was specified as 0, it may even be a 0 length buffer ). >>> Are these issues something that should be fixed? >>> >> >> So I don't think they need any fix here. It works as expected. > > Oh I wasn't suggesting that they *needed* to be fixed but if you think that it would be *nice* to fix them I'm happy to do the work and send some patches :-) > I do understand your point. But I meant to say, the things are working as expected. Thanks Suzuki >> Nathan, >> >> Please feel free to correct me. >> >> Thanks >> Suzuki > > Cheers, > Sam. > |
From: Sam B. <sam...@au...> - 2014-06-27 00:17:24
|
On 26/06/14 17:50, Suzuki K. Poulose wrote: > On 06/18/2014 11:15 AM, Sam Bobroff wrote: >> Hi librtas developers, >> >> While using librtas to call the RTAS "ibm,get-system-parameter" function >> , I noticed some odd behavior. (These questions probably only apply when librtas >> is using the syscall backend and making RTAS calls rather than reading from proc.) >> >> First, when calling rtas_get_sysparm(token, buflen, buf) any unused part of buf is >> filled with garbage (often the result of previous calls). This is because the code >> in sc_get_sysparm() uses a separately allocated, uninitialized, buffer for the RTAS >> call and always copies the entire result into buf even though only some bytes have >> been written to by the RTAS call. It seems like this would be less surprising if any >> unused bytes remained unchanged. > I guess this should be retained as it is. The first two bytes of the o/p > buffer tells you the size of the data anyways. So you shouldn't worry > about whats beyond the size. Right. Would you like me to send a patch? >> Second, calling rtas_get_sysparm(token, buflen, buf) with a zero length buffer fails >> with RTAS_IO_ASSERT but I think the call is supposed to succeed and just return no data. >> The failure is not coming from the RTAS call, but instead from librtas attempting to mmap() >> a zero-size area. If I tweak the code to avoid the mmap() on a zero size then the call succeeds. >> > There is a catch here. When you return a success, the first two bytes of > the buffer should indicate the length of the data, even if it is > truncated in the o/p due to requested_length < length_of_param_data. So > a 0 length could cause issues where the buffer doesn't indicate the > length of the data on Success, which is against the expectations of API. > Also we cannot write the length to the buffer on a 0 length request, > because we may be writing to a buffer which doesn't even have 2 b > length (which is legal from the users point of view). I'm not sure if I understand your point. Which API do you mean? Aren't the length bytes written by RTAS (and not by librtas) and wouldn't the edge cases like this be up to RTAS (and the caller) to handle? Why should librtas be involved in it? Are you saying that librtas needs to protect the user from this case or that we need to protect RTAS from it? >> Are these issues something that should be fixed? >> > > So I don't think they need any fix here. It works as expected. Oh I wasn't suggesting that they *needed* to be fixed but if you think that it would be *nice* to fix them I'm happy to do the work and send some patches :-) > Nathan, > > Please feel free to correct me. > > Thanks > Suzuki Cheers, Sam. |
From: Suzuki K. P. <su...@in...> - 2014-06-26 08:54:43
|
fyi, On 06/26/2014 01:20 PM, Suzuki K. Poulose wrote: > On 06/18/2014 11:15 AM, Sam Bobroff wrote: >> Hi librtas developers, >> >> While using librtas to call the RTAS "ibm,get-system-parameter" function >> , I noticed some odd behavior. (These questions probably only apply when librtas >> is using the syscall backend and making RTAS calls rather than reading from proc.) >> >> First, when calling rtas_get_sysparm(token, buflen, buf) any unused part of buf is >> filled with garbage (often the result of previous calls). This is because the code >> in sc_get_sysparm() uses a separately allocated, uninitialized, buffer for the RTAS >> call and always copies the entire result into buf even though only some bytes have >> been written to by the RTAS call. It seems like this would be less surprising if any >> unused bytes remained unchanged. > I guess this should be retained as it is. The first two bytes of the o/p > buffer tells you the size of the data anyways. So you shouldn't worry > about whats beyond the size. > >> >> Second, calling rtas_get_sysparm(token, buflen, buf) with a zero length buffer fails >> with RTAS_IO_ASSERT but I think the call is supposed to succeed and just return no data. >> The failure is not coming from the RTAS call, but instead from librtas attempting to mmap() >> a zero-size area. If I tweak the code to avoid the mmap() on a zero size then the call succeeds. >> > There is a catch here. When you return a success, the first two bytes of > the buffer should indicate the length of the data, even if it is > truncated in the o/p due to requested_length < length_of_param_data. So > a 0 length could cause issues where the buffer doesn't indicate the > length of the data on Success, which is against the expectations of API. > Also we cannot write the length to the buffer on a 0 length request, > because we may be writing to a buffer which doesn't even have 2 bytes > length (which is legal from the users point of view). > >> Are these issues something that should be fixed? >> > > So I don't think they need any fix here. It works as expected. > > Nathan, > > Please feel free to correct me. > > Thanks > Suzuki > > > ------------------------------------------------------------------------------ > Open source business process management suite built on Java and Eclipse > Turn processes into business applications with Bonita BPM Community Edition > Quickly connect people, data, and systems into organized workflows > Winner of BOSSIE, CODIE, OW2 and Gartner awards > http://p.sf.net/sfu/Bonitasoft > _______________________________________________ > Librtas-devel mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/librtas-devel > |
From: Suzuki K. P. <su...@in...> - 2014-06-26 08:21:01
|
On 06/18/2014 11:15 AM, Sam Bobroff wrote: > Hi librtas developers, > > While using librtas to call the RTAS "ibm,get-system-parameter" function >, I noticed some odd behavior. (These questions probably only apply when librtas > is using the syscall backend and making RTAS calls rather than reading from proc.) > > First, when calling rtas_get_sysparm(token, buflen, buf) any unused part of buf is > filled with garbage (often the result of previous calls). This is because the code > in sc_get_sysparm() uses a separately allocated, uninitialized, buffer for the RTAS > call and always copies the entire result into buf even though only some bytes have > been written to by the RTAS call. It seems like this would be less surprising if any > unused bytes remained unchanged. I guess this should be retained as it is. The first two bytes of the o/p buffer tells you the size of the data anyways. So you shouldn't worry about whats beyond the size. > > Second, calling rtas_get_sysparm(token, buflen, buf) with a zero length buffer fails > with RTAS_IO_ASSERT but I think the call is supposed to succeed and just return no data. > The failure is not coming from the RTAS call, but instead from librtas attempting to mmap() > a zero-size area. If I tweak the code to avoid the mmap() on a zero size then the call succeeds. > There is a catch here. When you return a success, the first two bytes of the buffer should indicate the length of the data, even if it is truncated in the o/p due to requested_length < length_of_param_data. So a 0 length could cause issues where the buffer doesn't indicate the length of the data on Success, which is against the expectations of API. Also we cannot write the length to the buffer on a 0 length request, because we may be writing to a buffer which doesn't even have 2 bytes length (which is legal from the users point of view). > Are these issues something that should be fixed? > So I don't think they need any fix here. It works as expected. Nathan, Please feel free to correct me. Thanks Suzuki |
From: Nathan F. <nf...@li...> - 2014-06-25 16:03:24
|
Looks good. Since ytou have a SOB I'll go ahead and pull it in. -Nathan On 06/23/2014 03:24 PM, Thomas Falcon wrote: > Signed-off-by: Thomas Falcon <tlf...@li...> > --- > README | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/README b/README > index 4c54cc6..ef781ae 100644 > --- a/README > +++ b/README > @@ -38,4 +38,20 @@ su - root > make install > /sbin/ldconfig > > - > +Endian Concerns: > +---------------- > +RTAS expects integer values to be in a 32 bit, big endian format. This > +requirement will be handled by librtas except when values are passed > +to or from RTAS via a buffer. In this case, we expect the caller to handle > +the endianess of these values. The librtas calls that employ this > +method are listed below: > + > +rtas_cfg_connector > +rtas_errinjct > +rtas_get_indices > +rtas_get_sysparm > +rtas_get_vpd > +rtas_lpar_perftools > +rtas_set_sysparm > +rtas_update_nodes > +rtas_update_properties > |
From: Thomas F. <tlf...@li...> - 2014-06-23 20:24:55
|
Signed-off-by: Thomas Falcon <tlf...@li...> --- README | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README b/README index 4c54cc6..ef781ae 100644 --- a/README +++ b/README @@ -38,4 +38,20 @@ su - root make install /sbin/ldconfig - +Endian Concerns: +---------------- +RTAS expects integer values to be in a 32 bit, big endian format. This +requirement will be handled by librtas except when values are passed +to or from RTAS via a buffer. In this case, we expect the caller to handle +the endianess of these values. The librtas calls that employ this +method are listed below: + +rtas_cfg_connector +rtas_errinjct +rtas_get_indices +rtas_get_sysparm +rtas_get_vpd +rtas_lpar_perftools +rtas_set_sysparm +rtas_update_nodes +rtas_update_properties -- 1.8.5.2 |
From: Sam B. <sam...@au...> - 2014-06-18 06:16:20
|
Hi librtas developers, While using librtas to call the RTAS "ibm,get-system-parameter" function, I noticed some odd behavior. (These questions probably only apply when librtas is using the syscall backend and making RTAS calls rather than reading from proc.) First, when calling rtas_get_sysparm(token, buflen, buf) any unused part of buf is filled with garbage (often the result of previous calls). This is because the code in sc_get_sysparm() uses a separately allocated, uninitialized, buffer for the RTAS call and always copies the entire result into buf even though only some bytes have been written to by the RTAS call. It seems like this would be less surprising if any unused bytes remained unchanged. Second, calling rtas_get_sysparm(token, buflen, buf) with a zero length buffer fails with RTAS_IO_ASSERT but I think the call is supposed to succeed and just return no data. The failure is not coming from the RTAS call, but instead from librtas attempting to mmap() a zero-size area. If I tweak the code to avoid the mmap() on a zero size then the call succeeds. Are these issues something that should be fixed? Should I post patches? Cheers, Sam. |
From: Thomas F. <tlf...@li...> - 2014-06-06 19:35:44
|
This patch attempts to make rtas syscalls compatible for Little Endian systems by ensuring rtas call parameters are Big Endian and return values are host endian. Signed-off-by: Thomas Falcon <tlf...@li...> --- Changes since v3: Fixed a bug in sc_get_vpd when byteswapping the sequence parameter Applied similar fixes to other functions --- librtas_src/syscall_calls.c | 143 +++++++++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 43 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 26111f9..01d6ce8 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -15,6 +15,7 @@ #include <sys/syscall.h> #include <unistd.h> #include <linux/unistd.h> +#include <linux/types.h> #include "common.h" #include "syscall.h" #include "librtas.h" @@ -398,7 +399,7 @@ int sc_display_msg(int token, char *buf) strcpy(kernbuf, buf); do { - rc = sc_rtas_call(token, 1, 1, kernbuf_pa, &status); + rc = sc_rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); if (rc < 0) break; @@ -438,8 +439,8 @@ int sc_errinjct(int token, int etoken, int otoken, char *workarea) memcpy(kernbuf, workarea, ERRINJCT_BUF_SIZE); do { - rc = sc_rtas_call(token, 3, 1, etoken, otoken, kernbuf_pa, - &status); + rc = sc_rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), + htobe32(kernbuf_pa), &status); if (rc < 0 ) break; @@ -470,7 +471,7 @@ int sc_errinjct_close(int token, int otoken) int rc; do { - rc = sc_rtas_call(token, 1, 1, otoken, &status); + rc = sc_rtas_call(token, 1, 1, htobe32(otoken), &status); if (rc) return rc; @@ -492,17 +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; int status; int rc; do { - rc = sc_rtas_call(token, 0, 2, otoken, &status); + rc = sc_rtas_call(token, 0, 2, &be_otoken, &status); if (rc) return rc; 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; } @@ -522,18 +526,23 @@ int sc_get_config_addr_info2(int token, uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info) { uint64_t elapsed = 0; + __be32 be_info; int status; int rc; do { - rc = sc_rtas_call(token, 4, 2, config_addr, - BITS32_HI(phb_id), BITS32_LO(phb_id), func, &status, info); + rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), + BITS32_HI(htobe64(phb_id)), + BITS32_LO(htobe64(phb_id)), + htobe32(func), &status, &be_info); if (rc) break; rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *info = be32toh(be_info); + dbg1("(0x%x, 0x%llx, %d) = %d, 0x%x\n", config_addr, phb_id, func, rc ? rc : status, *info); return rc ? rc : status; @@ -555,6 +564,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) uint64_t elapsed = 0; void *locbuf; uint32_t size; + __be32 be_state; int status; int rc; @@ -567,8 +577,8 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 2, 2, sensor, loc_pa, - &status, state); + rc = sc_rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), + &status, &be_state); if (rc < 0) break; @@ -577,6 +587,8 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) (void) sc_free_rmo_buffer(locbuf, loc_pa, size); + *state = be32toh(be_state); + dbg1("(%d, %s, %p) = %d, %d\n", sensor, (char *)loc_code, state, rc ? rc : status, *state); return rc ? rc : status; @@ -601,6 +613,7 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, { uint64_t elapsed = 0; uint32_t kernbuf_pa; + __be32 be_next; void *kernbuf; int status; int rc; @@ -610,8 +623,10 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, return rc; do { - rc = sc_rtas_call(token, 5, 2, is_sensor, type, kernbuf_pa, - size, start, &status, next); + rc = sc_rtas_call(token, 5, 2, htobe32(is_sensor), + htobe32(type), htobe32(kernbuf_pa), + htobe32(size), htobe32(start), + &status, &be_next); if (rc < 0) break; @@ -623,6 +638,8 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, size); + *next = be32toh(be_next); + dbg1("(%d, %d, %p, %d, %d, %p) = %d, %d\n", is_sensor, type, workarea, size, start, next, rc ? rc : status, *next); return rc ? rc : status; @@ -640,17 +657,21 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, int sc_get_power_level(int token, int powerdomain, int *level) { uint64_t elapsed = 0; + __be32 be_level; int status; int rc; do { - rc = sc_rtas_call(token, 1, 2, powerdomain, &status, level); + rc = sc_rtas_call(token, 1, 2, htobe32(powerdomain), + &status, &be_level); if (rc) return rc; rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *level = be32toh(be_level); + dbg1("(%d, %p) = %d, %d\n", powerdomain, level, rc ? rc : status, *level); return rc ? rc : status; @@ -669,7 +690,7 @@ int sc_get_power_level(int token, int powerdomain, int *level) int sc_get_sensor(int token, int sensor, int index, int *state) { uint64_t elapsed = 0; - uint32_t be_state; + __be32 be_state; int status; int rc; @@ -714,7 +735,8 @@ sc_get_sysparm(int token, unsigned int parameter, unsigned int length, return rc; do { - rc = sc_rtas_call(token, 3, 1, parameter, kernbuf_pa, length, + rc = sc_rtas_call(token, 3, 1, htobe32(parameter), + htobe32(kernbuf_pa), htobe32(length), &status); if (rc < 0) break; @@ -761,6 +783,14 @@ int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *year = be32toh(*year); + *month = be32toh(*month); + *day = be32toh(*day); + *hour = be32toh(*hour); + *min = be32toh(*min); + *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); return rc ? rc : status; @@ -803,11 +833,13 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, /* If user didn't set loc_code, copy a NULL string */ strncpy(locbuf, loc_code ? loc_code : "", PAGE_SIZE); - *seq_next = sequence; + *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 4, 3, loc_pa, kernbuf_pa, size, - sequence, &status, seq_next, bytes_ret); + rc = sc_rtas_call(token, 4, 3, htobe32(loc_pa), + htobe32(kernbuf_pa), htobe32(size), + sequence, &status, seq_next, + bytes_ret); if (rc < 0) break; @@ -819,6 +851,9 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, (void) sc_free_rmo_buffer(rmobuf, rmo_pa, size + PAGE_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", workarea, size, sequence, status, *seq_next, *bytes_ret); return rc ? rc : status; @@ -851,10 +886,11 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, memcpy(kernbuf, workarea, PAGE_SIZE); - *seq_next = sequence; + *seq_next = htobe32(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 5, 2, subfunc, 0, kernbuf_pa, length, + rc = sc_rtas_call(token, 5, 2, htobe32(subfunc), 0, + htobe32(kernbuf_pa), htobe32(length), sequence, &status, seq_next); if (rc < 0) break; @@ -867,6 +903,8 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + *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); return rc ? rc : status; @@ -902,12 +940,14 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, return rc; } - *seq_next = sequence; + *seq_next = htobe64(sequence); do { sequence = *seq_next; - rc = sc_rtas_call(token, 6, 5, BITS32_HI(dump_tag), - BITS32_LO(dump_tag), BITS32_HI(sequence), - BITS32_LO(sequence), kernbuf_pa, length, + rc = sc_rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), + BITS32_LO(htobe64(dump_tag)), + BITS32_HI(sequence), + BITS32_LO(sequence), + htobe32(kernbuf_pa), htobe32(length), &status, &next_hi, &next_lo, &bytes_hi, &bytes_lo); if (rc < 0) @@ -925,7 +965,12 @@ 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); - *bytes_ret = BITS64(bytes_hi, bytes_lo); + next_hi = be32toh(next_hi); + next_lo = be32toh(next_lo); + bytes_hi = be32toh(bytes_hi); + bytes_lo = be32toh(bytes_lo); + + *bytes_ret = BITS64(be32toh(bytes_hi), be32toh(bytes_lo)); dbg1("(0x%llx, 0x%llx, %p, %d, %p, %p) = %d, 0x%llx, 0x%llx\n", dump_tag, sequence, buffer, length, seq_next, bytes_ret, @@ -953,14 +998,19 @@ sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, int rc; do { - rc = sc_rtas_call(token, 3, 3, cfg_addr, BITS32_HI(phbid), - BITS32_LO(phbid), &status, state, eeh); + rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), + BITS32_HI(htobe64(phbid)), + BITS32_LO(htobe64(phbid)), &status, + state, eeh); if (rc) return rc; rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *state = be32toh(*state); + *eeh = be32toh(*eeh); + dbg1("(0x%x, 0x%llx, %p, %p) = %d, %d, %d\n", cfg_addr, phbid, state, eeh, rc ? rc : status, *state, *eeh); return rc ? rc : status; @@ -988,7 +1038,8 @@ int sc_scan_log_dump(int token, void *buffer, size_t length) memcpy(kernbuf, buffer, length); do { - rc = sc_rtas_call(token, 2, 1, kernbuf_pa, length, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(kernbuf_pa), + htobe32(length), &status); if (rc < 0) break; @@ -1032,8 +1083,8 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 3, 1, indicator, new_value, - loc_pa, &status); + rc = sc_rtas_call(token, 3, 1, htobe32(indicator), + htobe32(new_value), htobe32(loc_pa), &status); if (rc < 0) break; @@ -1065,8 +1116,10 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) int rc; do { - rc = sc_rtas_call(token, 4, 1, cfg_addr, BITS32_HI(phbid), - BITS32_LO(phbid), function, &status); + rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), + BITS32_HI(htobe64(phbid)), + BITS32_LO(htobe64(phbid)), + htobe32(function), &status); if (rc) return rc; @@ -1095,8 +1148,7 @@ int sc_set_indicator(int token, int indicator, int index, int new_value) do { rc = sc_rtas_call(token, 3, 1, htobe32(indicator), - htobe32(index), - htobe32(new_value), &status); + htobe32(index), htobe32(new_value), &status); if (rc) return rc; @@ -1120,7 +1172,7 @@ int sc_set_indicator(int token, int indicator, int index, int new_value) int sc_set_power_level(int token, int powerdomain, int level, int *setlevel) { uint64_t elapsed = 0; - uint32_t be_setlevel; + __be32 be_setlevel; int status; int rc; @@ -1162,8 +1214,9 @@ sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, int rc; do { - rc = sc_rtas_call(token, 7, 1, year, month, day, hour, min, - sec, nsec, &status); + rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + htobe32(day), htobe32(hour), htobe32(min), + htobe32(sec), htobe32(nsec), &status); if (rc) return rc; @@ -1200,7 +1253,8 @@ int sc_set_sysparm(int token, unsigned int parameter, char *data) memcpy(kernbuf, data, size + sizeof(short)); do { - rc = sc_rtas_call(token, 2, 1, parameter, kernbuf_pa, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(parameter), + htobe32(kernbuf_pa), &status); if (rc < 0) break; @@ -1234,8 +1288,9 @@ int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, int rc; do { - rc = sc_rtas_call(token, 7, 1, year, month, day, hour, min, - sec, nsec, &status); + rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + htobe32(day), htobe32(hour), htobe32(min), + htobe32(sec), htobe32(nsec), &status); if (rc) return rc; @@ -1260,8 +1315,8 @@ int sc_suspend_me(int token, uint64_t streamid) int rc; do { - rc = sc_rtas_call(token, 2, 1, BITS32_HI(streamid), - BITS32_LO(streamid), &status); + rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), + BITS32_LO(htobe64(streamid)), &status); if (rc) return rc; @@ -1299,7 +1354,8 @@ int sc_update_nodes(int token, char *workarea, unsigned int scope) memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, workarea_pa, scope, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + htobe32(scope), &status); if (rc < 0) break; @@ -1342,7 +1398,8 @@ int sc_update_properties(int token, char *workarea, unsigned int scope) memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, workarea_pa, scope, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + htobe32(scope), &status); if (rc < 0) break; -- 1.8.5.2 |
From: Vasant H. <heg...@li...> - 2014-05-29 16:18:39
|
On 05/29/2014 09:09 PM, tlf...@li... wrote: > From: Thomas Falcon <tlf...@li...> > > This patch attempts to make rtas syscalls compatible for Little > Endian systems by ensuring rtas call parameters are Big Endian and > return values are host endian. > > Signed-off-by: Thomas Falcon <tlf...@li...> Reviewed-by: Vasant Hegde <heg...@li...> -Vasant |
From: <tlf...@li...> - 2014-05-29 15:39:01
|
From: Thomas Falcon <tlf...@li...> This patch attempts to make rtas syscalls compatible for Little Endian systems by ensuring rtas call parameters are Big Endian and return values are host endian. Signed-off-by: Thomas Falcon <tlf...@li...> --- Differences from v3: converted a variable, size --- librtas_src/syscall_calls.c | 139 +++++++++++++++++++++++++++++++------------- 1 file changed, 98 insertions(+), 41 deletions(-) diff --git a/librtas_src/syscall_calls.c b/librtas_src/syscall_calls.c index 26111f9..8da96b9 100644 --- a/librtas_src/syscall_calls.c +++ b/librtas_src/syscall_calls.c @@ -15,6 +15,7 @@ #include <sys/syscall.h> #include <unistd.h> #include <linux/unistd.h> +#include <linux/types.h> #include "common.h" #include "syscall.h" #include "librtas.h" @@ -398,7 +399,7 @@ int sc_display_msg(int token, char *buf) strcpy(kernbuf, buf); do { - rc = sc_rtas_call(token, 1, 1, kernbuf_pa, &status); + rc = sc_rtas_call(token, 1, 1, htobe32(kernbuf_pa), &status); if (rc < 0) break; @@ -438,8 +439,8 @@ int sc_errinjct(int token, int etoken, int otoken, char *workarea) memcpy(kernbuf, workarea, ERRINJCT_BUF_SIZE); do { - rc = sc_rtas_call(token, 3, 1, etoken, otoken, kernbuf_pa, - &status); + rc = sc_rtas_call(token, 3, 1, htobe32(etoken), htobe32(otoken), + htobe32(kernbuf_pa), &status); if (rc < 0 ) break; @@ -470,7 +471,7 @@ int sc_errinjct_close(int token, int otoken) int rc; do { - rc = sc_rtas_call(token, 1, 1, otoken, &status); + rc = sc_rtas_call(token, 1, 1, htobe32(otoken), &status); if (rc) return rc; @@ -492,17 +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; int status; int rc; do { - rc = sc_rtas_call(token, 0, 2, otoken, &status); + rc = sc_rtas_call(token, 0, 2, &be_otoken, &status); if (rc) return rc; 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; } @@ -522,18 +526,23 @@ int sc_get_config_addr_info2(int token, uint32_t config_addr, uint64_t phb_id, uint32_t func, uint32_t *info) { uint64_t elapsed = 0; + __be32 be_info; int status; int rc; do { - rc = sc_rtas_call(token, 4, 2, config_addr, - BITS32_HI(phb_id), BITS32_LO(phb_id), func, &status, info); + rc = sc_rtas_call(token, 4, 2, htobe32(config_addr), + BITS32_HI(htobe64(phb_id)), + BITS32_LO(htobe64(phb_id)), + htobe32(func), &status, &be_info); if (rc) break; rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *info = be32toh(be_info); + dbg1("(0x%x, 0x%llx, %d) = %d, 0x%x\n", config_addr, phb_id, func, rc ? rc : status, *info); return rc ? rc : status; @@ -555,6 +564,7 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) uint64_t elapsed = 0; void *locbuf; uint32_t size; + __be32 be_state; int status; int rc; @@ -567,8 +577,8 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 2, 2, sensor, loc_pa, - &status, state); + rc = sc_rtas_call(token, 2, 2, htobe32(sensor), htobe32(loc_pa), + &status, &be_state); if (rc < 0) break; @@ -577,6 +587,8 @@ int sc_get_dynamic_sensor(int token, int sensor, void *loc_code, int *state) (void) sc_free_rmo_buffer(locbuf, loc_pa, size); + *state = be32toh(be_state); + dbg1("(%d, %s, %p) = %d, %d\n", sensor, (char *)loc_code, state, rc ? rc : status, *state); return rc ? rc : status; @@ -601,6 +613,7 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, { uint64_t elapsed = 0; uint32_t kernbuf_pa; + __be32 be_next; void *kernbuf; int status; int rc; @@ -610,8 +623,10 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, return rc; do { - rc = sc_rtas_call(token, 5, 2, is_sensor, type, kernbuf_pa, - size, start, &status, next); + rc = sc_rtas_call(token, 5, 2, htobe32(is_sensor), + htobe32(type), htobe32(kernbuf_pa), + htobe32(size), htobe32(start), + &status, &be_next); if (rc < 0) break; @@ -623,6 +638,8 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, size); + *next = be32toh(be_next); + dbg1("(%d, %d, %p, %d, %d, %p) = %d, %d\n", is_sensor, type, workarea, size, start, next, rc ? rc : status, *next); return rc ? rc : status; @@ -640,17 +657,21 @@ sc_get_indices(int token, int is_sensor, int type, char *workarea, size_t size, int sc_get_power_level(int token, int powerdomain, int *level) { uint64_t elapsed = 0; + __be32 be_level; int status; int rc; do { - rc = sc_rtas_call(token, 1, 2, powerdomain, &status, level); + rc = sc_rtas_call(token, 1, 2, htobe32(powerdomain), + &status, &be_level); if (rc) return rc; rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *level = be32toh(be_level); + dbg1("(%d, %p) = %d, %d\n", powerdomain, level, rc ? rc : status, *level); return rc ? rc : status; @@ -669,7 +690,7 @@ int sc_get_power_level(int token, int powerdomain, int *level) int sc_get_sensor(int token, int sensor, int index, int *state) { uint64_t elapsed = 0; - uint32_t be_state; + __be32 be_state; int status; int rc; @@ -714,7 +735,8 @@ sc_get_sysparm(int token, unsigned int parameter, unsigned int length, return rc; do { - rc = sc_rtas_call(token, 3, 1, parameter, kernbuf_pa, length, + rc = sc_rtas_call(token, 3, 1, htobe32(parameter), + htobe32(kernbuf_pa), htobe32(length), &status); if (rc < 0) break; @@ -761,6 +783,14 @@ int sc_get_time(int token, uint32_t *year, uint32_t *month, uint32_t *day, rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *year = be32toh(*year); + *month = be32toh(*month); + *day = be32toh(*day); + *hour = be32toh(*hour); + *min = be32toh(*min); + *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); return rc ? rc : status; @@ -806,8 +836,10 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, *seq_next = sequence; do { sequence = *seq_next; - rc = sc_rtas_call(token, 4, 3, loc_pa, kernbuf_pa, size, - sequence, &status, seq_next, bytes_ret); + rc = sc_rtas_call(token, 4, 3, htobe32(loc_pa), + htobe32(kernbuf_pa), htobe32(size), + htobe32(sequence), &status, seq_next, + bytes_ret); if (rc < 0) break; @@ -819,6 +851,9 @@ int sc_get_vpd(int token, char *loc_code, char *workarea, size_t size, (void) sc_free_rmo_buffer(rmobuf, rmo_pa, size + PAGE_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", workarea, size, sequence, status, *seq_next, *bytes_ret); return rc ? rc : status; @@ -854,8 +889,9 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, *seq_next = sequence; do { sequence = *seq_next; - rc = sc_rtas_call(token, 5, 2, subfunc, 0, kernbuf_pa, length, - sequence, &status, seq_next); + rc = sc_rtas_call(token, 5, 2, htobe32(subfunc), 0, + htobe32(kernbuf_pa), htobe32(length), + htobe32(sequence), &status, seq_next); if (rc < 0) break; @@ -867,6 +903,8 @@ int sc_lpar_perftools(int token, int subfunc, char *workarea, (void)sc_free_rmo_buffer(kernbuf, kernbuf_pa, length); + *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); return rc ? rc : status; @@ -905,9 +943,11 @@ sc_platform_dump(int token, uint64_t dump_tag, uint64_t sequence, void *buffer, *seq_next = sequence; do { sequence = *seq_next; - rc = sc_rtas_call(token, 6, 5, BITS32_HI(dump_tag), - BITS32_LO(dump_tag), BITS32_HI(sequence), - BITS32_LO(sequence), kernbuf_pa, length, + rc = sc_rtas_call(token, 6, 5, BITS32_HI(htobe64(dump_tag)), + BITS32_LO(htobe64(dump_tag)), + BITS32_HI(htobe64(sequence)), + BITS32_LO(htobe64(sequence)), + htobe32(kernbuf_pa), htobe32(length), &status, &next_hi, &next_lo, &bytes_hi, &bytes_lo); if (rc < 0) @@ -925,7 +965,12 @@ 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); - *bytes_ret = BITS64(bytes_hi, bytes_lo); + next_hi = be32toh(next_hi); + next_lo = be32toh(next_lo); + bytes_hi = be32toh(bytes_hi); + bytes_lo = be32toh(bytes_lo); + + *bytes_ret = BITS64(be32toh(bytes_hi), be32toh(bytes_lo)); dbg1("(0x%llx, 0x%llx, %p, %d, %p, %p) = %d, 0x%llx, 0x%llx\n", dump_tag, sequence, buffer, length, seq_next, bytes_ret, @@ -953,14 +998,19 @@ sc_read_slot_reset(int token, uint32_t cfg_addr, uint64_t phbid, int *state, int rc; do { - rc = sc_rtas_call(token, 3, 3, cfg_addr, BITS32_HI(phbid), - BITS32_LO(phbid), &status, state, eeh); + rc = sc_rtas_call(token, 3, 3, htobe32(cfg_addr), + BITS32_HI(htobe64(phbid)), + BITS32_LO(htobe64(phbid)), &status, + state, eeh); if (rc) return rc; rc = handle_delay(status, &elapsed); } while (rc == CALL_AGAIN); + *state = be32toh(*state); + *eeh = be32toh(*eeh); + dbg1("(0x%x, 0x%llx, %p, %p) = %d, %d, %d\n", cfg_addr, phbid, state, eeh, rc ? rc : status, *state, *eeh); return rc ? rc : status; @@ -988,7 +1038,8 @@ int sc_scan_log_dump(int token, void *buffer, size_t length) memcpy(kernbuf, buffer, length); do { - rc = sc_rtas_call(token, 2, 1, kernbuf_pa, length, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(kernbuf_pa), + htobe32(length), &status); if (rc < 0) break; @@ -1032,8 +1083,8 @@ int sc_set_dynamic_indicator(int token, int indicator, int new_value, memcpy(locbuf, loc_code, size); do { - rc = sc_rtas_call(token, 3, 1, indicator, new_value, - loc_pa, &status); + rc = sc_rtas_call(token, 3, 1, htobe32(indicator), + htobe32(new_value), htobe32(loc_pa), &status); if (rc < 0) break; @@ -1065,8 +1116,10 @@ sc_set_eeh_option(int token, uint32_t cfg_addr, uint64_t phbid, int function) int rc; do { - rc = sc_rtas_call(token, 4, 1, cfg_addr, BITS32_HI(phbid), - BITS32_LO(phbid), function, &status); + rc = sc_rtas_call(token, 4, 1, htobe32(cfg_addr), + BITS32_HI(htobe64(phbid)), + BITS32_LO(htobe64(phbid)), + htobe32(function), &status); if (rc) return rc; @@ -1095,8 +1148,7 @@ int sc_set_indicator(int token, int indicator, int index, int new_value) do { rc = sc_rtas_call(token, 3, 1, htobe32(indicator), - htobe32(index), - htobe32(new_value), &status); + htobe32(index), htobe32(new_value), &status); if (rc) return rc; @@ -1120,7 +1172,7 @@ int sc_set_indicator(int token, int indicator, int index, int new_value) int sc_set_power_level(int token, int powerdomain, int level, int *setlevel) { uint64_t elapsed = 0; - uint32_t be_setlevel; + __be32 be_setlevel; int status; int rc; @@ -1162,8 +1214,9 @@ sc_set_poweron_time(int token, uint32_t year, uint32_t month, uint32_t day, int rc; do { - rc = sc_rtas_call(token, 7, 1, year, month, day, hour, min, - sec, nsec, &status); + rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + htobe32(day), htobe32(hour), htobe32(min), + htobe32(sec), htobe32(nsec), &status); if (rc) return rc; @@ -1200,7 +1253,8 @@ int sc_set_sysparm(int token, unsigned int parameter, char *data) memcpy(kernbuf, data, size + sizeof(short)); do { - rc = sc_rtas_call(token, 2, 1, parameter, kernbuf_pa, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(parameter), + htobe32(kernbuf_pa), &status); if (rc < 0) break; @@ -1234,8 +1288,9 @@ int sc_set_time(int token, uint32_t year, uint32_t month, uint32_t day, int rc; do { - rc = sc_rtas_call(token, 7, 1, year, month, day, hour, min, - sec, nsec, &status); + rc = sc_rtas_call(token, 7, 1, htobe32(year), htobe32(month), + htobe32(day), htobe32(hour), htobe32(min), + htobe32(sec), htobe32(nsec), &status); if (rc) return rc; @@ -1260,8 +1315,8 @@ int sc_suspend_me(int token, uint64_t streamid) int rc; do { - rc = sc_rtas_call(token, 2, 1, BITS32_HI(streamid), - BITS32_LO(streamid), &status); + rc = sc_rtas_call(token, 2, 1, BITS32_HI(htobe64(streamid)), + BITS32_LO(htobe64(streamid)), &status); if (rc) return rc; @@ -1299,7 +1354,8 @@ int sc_update_nodes(int token, char *workarea, unsigned int scope) memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, workarea_pa, scope, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + htobe32(scope), &status); if (rc < 0) break; @@ -1342,7 +1398,8 @@ int sc_update_properties(int token, char *workarea, unsigned int scope) memcpy(kernbuf, workarea, 4096); do { - rc = sc_rtas_call(token, 2, 1, workarea_pa, scope, &status); + rc = sc_rtas_call(token, 2, 1, htobe32(workarea_pa), + htobe32(scope), &status); if (rc < 0) break; -- 1.8.5.2 |