Path: blob/master/arch/powerpc/platforms/pseries/hvcserver.c
10818 views
/*1* hvcserver.c2* Copyright (C) 2004 Ryan S Arnold, IBM Corporation3*4* PPC64 virtual I/O console server support.5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*/2021#include <linux/kernel.h>22#include <linux/list.h>23#include <linux/module.h>24#include <linux/slab.h>2526#include <asm/hvcall.h>27#include <asm/hvcserver.h>28#include <asm/io.h>2930#define HVCS_ARCH_VERSION "1.0.0"3132MODULE_AUTHOR("Ryan S. Arnold <[email protected]>");33MODULE_DESCRIPTION("IBM hvcs ppc64 API");34MODULE_LICENSE("GPL");35MODULE_VERSION(HVCS_ARCH_VERSION);3637/*38* Convert arch specific return codes into relevant errnos. The hvcs39* functions aren't performance sensitive, so this conversion isn't an40* issue.41*/42static int hvcs_convert(long to_convert)43{44switch (to_convert) {45case H_SUCCESS:46return 0;47case H_PARAMETER:48return -EINVAL;49case H_HARDWARE:50return -EIO;51case H_BUSY:52case H_LONG_BUSY_ORDER_1_MSEC:53case H_LONG_BUSY_ORDER_10_MSEC:54case H_LONG_BUSY_ORDER_100_MSEC:55case H_LONG_BUSY_ORDER_1_SEC:56case H_LONG_BUSY_ORDER_10_SEC:57case H_LONG_BUSY_ORDER_100_SEC:58return -EBUSY;59case H_FUNCTION: /* fall through */60default:61return -EPERM;62}63}6465/**66* hvcs_free_partner_info - free pi allocated by hvcs_get_partner_info67* @head: list_head pointer for an allocated list of partner info structs to68* free.69*70* This function is used to free the partner info list that was returned by71* calling hvcs_get_partner_info().72*/73int hvcs_free_partner_info(struct list_head *head)74{75struct hvcs_partner_info *pi;76struct list_head *element;7778if (!head)79return -EINVAL;8081while (!list_empty(head)) {82element = head->next;83pi = list_entry(element, struct hvcs_partner_info, node);84list_del(element);85kfree(pi);86}8788return 0;89}90EXPORT_SYMBOL(hvcs_free_partner_info);9192/* Helper function for hvcs_get_partner_info */93static int hvcs_next_partner(uint32_t unit_address,94unsigned long last_p_partition_ID,95unsigned long last_p_unit_address, unsigned long *pi_buff)9697{98long retval;99retval = plpar_hcall_norets(H_VTERM_PARTNER_INFO, unit_address,100last_p_partition_ID,101last_p_unit_address, virt_to_phys(pi_buff));102return hvcs_convert(retval);103}104105/**106* hvcs_get_partner_info - Get all of the partner info for a vty-server adapter107* @unit_address: The unit_address of the vty-server adapter for which this108* function is fetching partner info.109* @head: An initialized list_head pointer to an empty list to use to return the110* list of partner info fetched from the hypervisor to the caller.111* @pi_buff: A page sized buffer pre-allocated prior to calling this function112* that is to be used to be used by firmware as an iterator to keep track113* of the partner info retrieval.114*115* This function returns non-zero on success, or if there is no partner info.116*117* The pi_buff is pre-allocated prior to calling this function because this118* function may be called with a spin_lock held and kmalloc of a page is not119* recommended as GFP_ATOMIC.120*121* The first long of this buffer is used to store a partner unit address. The122* second long is used to store a partner partition ID and starting at123* pi_buff[2] is the 79 character Converged Location Code (diff size than the124* unsigned longs, hence the casting mumbo jumbo you see later).125*126* Invocation of this function should always be followed by an invocation of127* hvcs_free_partner_info() using a pointer to the SAME list head instance128* that was passed as a parameter to this function.129*/130int hvcs_get_partner_info(uint32_t unit_address, struct list_head *head,131unsigned long *pi_buff)132{133/*134* Dealt with as longs because of the hcall interface even though the135* values are uint32_t.136*/137unsigned long last_p_partition_ID;138unsigned long last_p_unit_address;139struct hvcs_partner_info *next_partner_info = NULL;140int more = 1;141int retval;142143memset(pi_buff, 0x00, PAGE_SIZE);144/* invalid parameters */145if (!head || !pi_buff)146return -EINVAL;147148last_p_partition_ID = last_p_unit_address = ~0UL;149INIT_LIST_HEAD(head);150151do {152retval = hvcs_next_partner(unit_address, last_p_partition_ID,153last_p_unit_address, pi_buff);154if (retval) {155/*156* Don't indicate that we've failed if we have157* any list elements.158*/159if (!list_empty(head))160return 0;161return retval;162}163164last_p_partition_ID = pi_buff[0];165last_p_unit_address = pi_buff[1];166167/* This indicates that there are no further partners */168if (last_p_partition_ID == ~0UL169&& last_p_unit_address == ~0UL)170break;171172/* This is a very small struct and will be freed soon in173* hvcs_free_partner_info(). */174next_partner_info = kmalloc(sizeof(struct hvcs_partner_info),175GFP_ATOMIC);176177if (!next_partner_info) {178printk(KERN_WARNING "HVCONSOLE: kmalloc() failed to"179" allocate partner info struct.\n");180hvcs_free_partner_info(head);181return -ENOMEM;182}183184next_partner_info->unit_address185= (unsigned int)last_p_unit_address;186next_partner_info->partition_ID187= (unsigned int)last_p_partition_ID;188189/* copy the Null-term char too */190strncpy(&next_partner_info->location_code[0],191(char *)&pi_buff[2],192strlen((char *)&pi_buff[2]) + 1);193194list_add_tail(&(next_partner_info->node), head);195next_partner_info = NULL;196197} while (more);198199return 0;200}201EXPORT_SYMBOL(hvcs_get_partner_info);202203/**204* hvcs_register_connection - establish a connection between this vty-server and205* a vty.206* @unit_address: The unit address of the vty-server adapter that is to be207* establish a connection.208* @p_partition_ID: The partition ID of the vty adapter that is to be connected.209* @p_unit_address: The unit address of the vty adapter to which the vty-server210* is to be connected.211*212* If this function is called once and -EINVAL is returned it may213* indicate that the partner info needs to be refreshed for the214* target unit address at which point the caller must invoke215* hvcs_get_partner_info() and then call this function again. If,216* for a second time, -EINVAL is returned then it indicates that217* there is probably already a partner connection registered to a218* different vty-server adapter. It is also possible that a second219* -EINVAL may indicate that one of the parms is not valid, for220* instance if the link was removed between the vty-server adapter221* and the vty adapter that you are trying to open. Don't shoot the222* messenger. Firmware implemented it this way.223*/224int hvcs_register_connection( uint32_t unit_address,225uint32_t p_partition_ID, uint32_t p_unit_address)226{227long retval;228retval = plpar_hcall_norets(H_REGISTER_VTERM, unit_address,229p_partition_ID, p_unit_address);230return hvcs_convert(retval);231}232EXPORT_SYMBOL(hvcs_register_connection);233234/**235* hvcs_free_connection - free the connection between a vty-server and vty236* @unit_address: The unit address of the vty-server that is to have its237* connection severed.238*239* This function is used to free the partner connection between a vty-server240* adapter and a vty adapter.241*242* If -EBUSY is returned continue to call this function until 0 is returned.243*/244int hvcs_free_connection(uint32_t unit_address)245{246long retval;247retval = plpar_hcall_norets(H_FREE_VTERM, unit_address);248return hvcs_convert(retval);249}250EXPORT_SYMBOL(hvcs_free_connection);251252253