linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: michael.neuling@au1.ibm.com, stewart@linux.vnet.ibm.com,
	apopple@au1.ibm.com, hbabu@us.ibm.com, oohall@gmail.com,
	bsingharora@gmail.com, linuxppc-dev@ozlabs.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 04/11] VAS: Define vas_init() and vas_exit()
Date: Mon, 24 Apr 2017 16:25:57 +1000	[thread overview]
Message-ID: <1493015157.25766.211.camel@kernel.crashing.org> (raw)
In-Reply-To: <1490937224-29149-5-git-send-email-sukadev@linux.vnet.ibm.com>

On Thu, 2017-03-30 at 22:13 -0700, Sukadev Bhattiprolu wrote:
> 
> +	p = of_get_property(dn, "vas-id", NULL);
> +	if (!p) {
> +		pr_err("VAS: NULL vas-id? %p\n", p);
> +		return -ENODEV;
> +	}
> +
> +	vinst->vas_id = of_read_number(p, 1);

of_property_read_u32()

> +	/*
> +	 * Hardcoded 6 is tied to corresponding code in
> +	 *      skiboot.git/core/vas.c
> +	 */
> +	rc = of_property_read_variable_u64_array(dn, "reg", values,
> 6, 6);
> +	if (rc != 6) {
> +		pr_err("VAS %d: Unable to read reg properties, rc
> %d\n",
> +				vinst->vas_id, rc);
> +		return rc;
> +	}
> +
> +	vinst->hvwc_bar_start = values[0];
> +	vinst->hvwc_bar_len = values[1];
> +	vinst->uwc_bar_start = values[2];
> +	vinst->uwc_bar_len = values[3];
> +	vinst->win_base_addr = values[4];
> +	vinst->win_id_shift = values[5];

If you make the VAS a proper MMIO device on the powerbus (as explained
in my comment to your OPAL patch), and you create this as a platform
device based on the DT, the core will parse the reg property for you
and will populate the device struct resource array for you.

> +	return 0;
> +}
> +
> +/*
> + * Although this is read/used multiple times, it is written to only
> + * during initialization.
> + */
> +struct vas_instance *find_vas_instance(int vasid)
> +{
> +	int i;
> +	struct vas_instance *vinst;
> +
> +	for (i = 0; i < vas_num_instances; i++) {
> +		vinst = &vas_instances[i];
> +		if (vinst->vas_id == vasid)
> +			return vinst;
> +	}
> +	pr_err("VAS instance for vas-id %d not found\n", vasid);
> +	WARN_ON_ONCE(1);
> +	return NULL;
> +}

This is gross. What is it needed for  ?

> +
> +bool vas_initialized(void)
> +{
> +	return init_done;
> +}
> +
> +int vas_init(void)
> +{
> +	int rc;
> +	struct device_node *dn;
> +	struct vas_instance *vinst;
> +
> +	if (!pvr_version_is(PVR_POWER9))
> +		return -ENODEV;

No. Create a platform device that matches the corresponding device-tree
node. One per instance.

The resulting VAS "driver" thus becomes a loadable module which you can
put elsewhere in the tree, matching on the DT node "compatible"
property.

You can then have the copros be chilren of it. The VAS driver can then
create additional platform devices for its children, who can have their
own module (which *can* depend on symbols exportd by the VAS one)
etc...

> +	vas_num_instances = 0;
> +	for_each_node_by_name(dn, "vas")
> +		vas_num_instances++;
> +
> +	if (!vas_num_instances)
> +		return -ENODEV;
> +
> +	vas_instances = kcalloc(vas_num_instances, sizeof(*vinst),
> GFP_KERNEL);
> +	if (!vas_instances)
> +		return -ENOMEM;
> +
> +	vinst = &vas_instances[0];
> +	for_each_node_by_name(dn, "vas") {
> +		rc = init_vas_instance(dn, vinst);
> +		if (rc) {
> +			pr_err("Error %d initializing VAS instance
> %ld\n", rc,
> +					(vinst-&vas_instances[0]));
> +			goto cleanup;
> +		}
> +		vinst++;
> +	}
> +
> +	rc = -ENODEV;
> +	if (vinst == &vas_instances[0]) {
> +		/* Should not happen as we saw some above. */
> +		pr_err("VAS: Did not find any VAS DT nodes now!\n");
> +		goto cleanup;
> +	}
> +
> +	pr_devel("VAS: Initialized %d instances\n",
> vas_num_instances);
> +	init_done = true;
> +
> +	return 0;
> +
> +cleanup:
> +	kfree(vas_instances);
> +	return rc;
> +}
> +
> +void vas_exit(void)
> +{
> +	init_done = false;
> +	kfree(vas_instances);
> +}
> +
> +module_init(vas_init);
> +module_exit(vas_exit);
> +MODULE_DESCRIPTION("IBM Virtual Accelerator Switchboard");
> +MODULE_AUTHOR("Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>");
> +MODULE_LICENSE("GPL");
> diff --git a/arch/powerpc/platforms/powernv/vas.h
> b/arch/powerpc/platforms/powernv/vas.h
> index c63395d..46aaa17 100644
> --- a/arch/powerpc/platforms/powernv/vas.h
> +++ b/arch/powerpc/platforms/powernv/vas.h
> @@ -384,4 +384,7 @@ struct vas_winctx {
>  	enum vas_notify_after_count notify_after_count;
>  };
>  
> +extern bool vas_initialized(void);
> +extern struct vas_instance *find_vas_instance(int vasid);
> +
>  #endif /* _VAS_H */

  parent reply	other threads:[~2017-04-24  6:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31  5:13 [PATCH v4 00/11] Enable VAS Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 01/11] Add Power9 PVR Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 02/11] VAS: Define macros, register fields and structures Sukadev Bhattiprolu
2017-04-04 17:17   ` Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 03/11] Move GET_FIELD/SET_FIELD to vas.h Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 04/11] VAS: Define vas_init() and vas_exit() Sukadev Bhattiprolu
2017-04-02 20:23   ` kbuild test robot
2017-04-04 17:20   ` Sukadev Bhattiprolu
2017-04-24  6:18   ` Benjamin Herrenschmidt
2017-04-24  6:25   ` Benjamin Herrenschmidt [this message]
2017-04-24 20:32   ` Tyrel Datwyler
2017-05-25  5:29     ` Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 05/11] VAS: Define helpers for access MMIO regions Sukadev Bhattiprolu
2017-04-24  6:28   ` Benjamin Herrenschmidt
2017-04-24 17:25     ` Sukadev Bhattiprolu
2017-04-24 23:19       ` Benjamin Herrenschmidt
2017-03-31  5:13 ` [PATCH v4 06/11] VAS: Define helpers to init window context Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 07/11] VAS: Define helpers to alloc/free windows Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 08/11] VAS: Define vas_rx_win_open() interface Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 09/11] VAS: Define vas_win_close() interface Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 10/11] VAS: Define vas_tx_win_open() Sukadev Bhattiprolu
2017-03-31  5:13 ` [PATCH v4 11/11] VAS: Define copy/paste interfaces Sukadev Bhattiprolu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493015157.25766.211.camel@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    --cc=apopple@au1.ibm.com \
    --cc=bsingharora@gmail.com \
    --cc=hbabu@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=michael.neuling@au1.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=oohall@gmail.com \
    --cc=stewart@linux.vnet.ibm.com \
    --cc=sukadev@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).