From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSg03-0000Qo-0m for qemu-devel@nongnu.org; Tue, 03 Mar 2015 01:08:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSfzz-00027C-FH for qemu-devel@nongnu.org; Tue, 03 Mar 2015 01:08:10 -0500 Date: Tue, 3 Mar 2015 16:52:57 +1100 From: David Gibson Message-ID: <20150303055257.GP29409@voom.fritz.box> References: <1425006675-19976-1-git-send-email-mdroth@linux.vnet.ibm.com> <1425006675-19976-11-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="o41d8xLWOaLD8vYh" Content-Disposition: inline In-Reply-To: <1425006675-19976-11-git-send-email-mdroth@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v6 10/15] spapr_drc: add spapr_drc_populate_dt() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: aik@ozlabs.ru, qemu-devel@nongnu.org, agraf@suse.de, ncmike@ncultra.org, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, bharata.rao@gmail.com, nfont@linux.vnet.ibm.com --o41d8xLWOaLD8vYh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 26, 2015 at 09:11:10PM -0600, Michael Roth wrote: > This function handles generation of ibm,drc-* array device tree > properties to describe DRC topology to guests. This will by used > by the guest to direct RTAS calls to manage any dynamic resources > we associate with a particular DR Connector as part of > hotplug/unplug. >=20 > Since general management of boot-time device trees are handled > outside of sPAPRDRConnector, we insert these values blindly given > an FDT and offset. A mask of sPAPRDRConnector types is given to > instruct us on what types of connectors entries should be generated > for, since descriptions for different connectors may live in > different parts of the device tree. >=20 > Based on code originally written by Nathan Fontenot. >=20 > Signed-off-by: Nathan Fontenot > Signed-off-by: Michael Roth This makes me wonder if I should implement an fdt_setprop_inplace_partial() to avoid fdt creators needing to mess about with temporary allocations like this does. But that's a project for another day. Reviewed-by: David Gibson > --- > hw/ppc/spapr_drc.c | 165 +++++++++++++++++++++++++++++++++++++++= ++++++ > include/hw/ppc/spapr_drc.h | 2 + > 2 files changed, 167 insertions(+) >=20 > diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c > index bf22e1d..2a3195c 100644 > --- a/hw/ppc/spapr_drc.c > +++ b/hw/ppc/spapr_drc.c > @@ -583,3 +583,168 @@ sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRC= onnectorType type, > (get_type_shift(type) << DRC_INDEX_TYPE_SHIFT) | > (id & DRC_INDEX_ID_MASK)); > } > + > +/* generate a string the describes the DRC to encode into the > + * device tree. > + * > + * as documented by PAPR+ v2.7, 13.5.2.6 and C.6.1 > + */ > +static char *spapr_drc_get_type_str(sPAPRDRConnectorType type) > +{ > + char *type_str =3D NULL; > + > + switch (type) { > + case SPAPR_DR_CONNECTOR_TYPE_CPU: > + type_str =3D g_strdup_printf("CPU"); > + break; > + case SPAPR_DR_CONNECTOR_TYPE_PHB: > + type_str =3D g_strdup_printf("PHB"); > + break; > + case SPAPR_DR_CONNECTOR_TYPE_VIO: > + type_str =3D g_strdup_printf("SLOT"); > + break; > + case SPAPR_DR_CONNECTOR_TYPE_PCI: > + type_str =3D g_strdup_printf("28"); > + break; > + case SPAPR_DR_CONNECTOR_TYPE_LMB: > + type_str =3D g_strdup_printf("MEM"); So, at present this always returns a string literal, which means you could avoid the strdup()s and the free in the caller. That would break down if you ever need to return something computed here though. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --o41d8xLWOaLD8vYh Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU9Uw5AAoJEGw4ysog2bOS/q8P/0nqS9oYIynR5sUOaN926fiY bdhIllUN8vSg269gt4u2FYFSO5urd6a6JI1CCpdFBgSxG0825Saw1UpCH+Ti+32Z XP6/I8/IDLQ095WCS0Mb8rRRWe/ySdlhLns/2/E784tcYCimahiGG1R1bWt3E5Ah 3nB8VcXVA3OhS4NR1buKVwNNsncHXrBGDe1/RRFXTFD4gWAe4BG0GWHR5xZnfDwG 1aXx1N5SRZ7BzLGjcTUD8lR+EM5D462C9UDzNuPDROv62xy16Zm/VHy3VRzWG9Eo pgVvSqP7jkeoNisMZzY0xnLOQld3V2pxUl/fy7+3ilaruD7hylkNpsmhI2vBbUvC d5pvJ+2yPGWTVess9ohk1/iLTs+R8Z/pF6M3NqrYwms1J4B5BO80Tbk23Obt/qUE tOEsLAyaXwYXrjTArHpluqDDZN78P0zw97SOV4lst7IdGHMJQfovTPjcaQglMR9/ 0OIU1bVw6sJvqlN5Nj0yH4VZlxyhi79WBKu7OXmZAGCWnn0CjLMh6Rakr1+EQdsr 4fV8zRHteaiD9ysCi60J5q5Ih8yG2Ror6WCP+0mdNnLpCUzsJfhFO1fA7A6K3t8f LYDy4txQNXhRyaIcH56rJH8dt60wDpxGj/trNEYoYKRvvi0yb1HVaM5VLqOi/qCu RG+ioaVGdxvY1iWdajYA =wXwr -----END PGP SIGNATURE----- --o41d8xLWOaLD8vYh--