From patchwork Thu May 4 10:48:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 758496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wJWws63c4z9ryr for ; Thu, 4 May 2017 20:49:01 +1000 (AEST) Received: from localhost ([::1]:40969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJf-0006sW-3K for incoming@patchwork.ozlabs.org; Thu, 04 May 2017 06:48:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJ1-0006rI-J6 for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EIx-0005xo-Rw for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57513 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6EIx-0005vh-Lk for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:15 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v44AiCtj052250 for ; Thu, 4 May 2017 06:48:14 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a7w8kxs52-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:14 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:13 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:10 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmAFe40173712; Thu, 4 May 2017 10:48:10 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C2B742045; Thu, 4 May 2017 11:46:49 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5731242041; Thu, 4 May 2017 11:46:49 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:49 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:00 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0040-0000-0000-0000039DCFDF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0041-0000-0000-00001FF9F9F5 Message-Id: <20170504104806.8120-3-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 2/8] s390x/css: Add an algorithm to find a free chpid X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cornelia Huck , borntraeger@de.ibm.com, Jing Liu , agraf@suse.de, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jing Liu This introduces a function named css_find_free_chpid() to find a free channel path. Because virtio-ccw device used zero as its channel path number, it would be sensible to skip the reserved one and search upwards. Signed-off-by: Jing Liu Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/s390x/css.c | 21 +++++++++++++++++++++ include/hw/s390x/css.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index c03bb20bc9..d94498a97b 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1302,6 +1302,27 @@ bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid) (MAX_SCHID + 1) / sizeof(unsigned long)); } +unsigned int css_find_free_chpid(uint8_t cssid) +{ + CssImage *css = channel_subsys.css[cssid]; + unsigned int chpid; + + if (!css) { + return MAX_CHPID + 1; + } + + for (chpid = 0; chpid <= MAX_CHPID; chpid++) { + /* skip reserved chpid */ + if (chpid == VIRTIO_CCW_CHPID) { + continue; + } + if (!css->chpids[chpid].in_use) { + return chpid; + } + } + return MAX_CHPID + 1; +} + static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type) { CssImage *css; diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index f1f0d7f07a..e61fa74d9b 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -28,6 +28,7 @@ #define MAX_CIWS 62 #define VIRTUAL_CSSID 0xfe +#define VIRTIO_CCW_CHPID 0 /* used by convention */ typedef struct CIW { uint8_t type; @@ -115,6 +116,7 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno); void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno, SubchDev *sch); void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type); +unsigned int css_find_free_chpid(uint8_t cssid); uint16_t css_build_subchannel_id(SubchDev *sch); void css_reset(void); void css_reset_sch(SubchDev *sch);