Re: [PATCH v2 17/21] ASoC: samsung: i2s: Change indentation in SAMSUNG_I2S_FMTS definition

2019-02-12 Thread Krzysztof Kozlowski
On Tue, 12 Feb 2019 at 19:05, Sylwester Nawrocki  wrote:
>
> Change indentation so this macro definition spans 2 rows and looks
> more consistent with surrounding code.
>
> Signed-off-by: Sylwester Nawrocki 
> ---
>  sound/soc/samsung/i2s.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>

Acked-by: Krzysztof Kozlowski 

Best regards,
Krzysztof


Re: [PATCH v2 16/21] ASoC: samsung: i2s: Simplify pri_dai, sec_dai pointers usage

2019-02-12 Thread Krzysztof Kozlowski
On Tue, 12 Feb 2019 at 19:05, Sylwester Nawrocki  wrote:
>
> If the probe call is on the primary DAI we can use 'other' in place of
> i2s->sec_dai, if the probe call is on the secondary DAI we can use 'i2s'
> in place of other->sec_dai.
>
> While at it fix one whitespace issue.
>
> Signed-off-by: Sylwester Nawrocki 
> ---
>  sound/soc/samsung/i2s.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)

Acked-by: Krzysztof Kozlowski 

Best regards,
Krzysztof


Re: [tip:x86/boot] x86/boot: Early parse RSDP and save it in boot_params

2019-02-12 Thread Chao Fan
On Wed, Feb 13, 2019 at 08:36:12AM +0100, Boris Petkov wrote:
>On February 13, 2019 2:54:29 AM GMT+01:00, Chao Fan  
>wrote:
>>Yes, your PATCH really works well. I tried both efi32 OVMF and efi64
>>OVMF, all boot.
>
>What about the real hardware you are normally testing on? Boots there too?

I testet it in a real EFI machine, it booted, but from command:
> cat /sys/firmware/efi/fw_platform_size
64

We can see it's a 64-bit EFI firmware, and there is no 32-bit EFI firmware 
available.

Thanks,
Chao Fan

>
>Thx.
>
>-- 
>Sent from a small device: formatting sux and brevity is inevitable.
>
>




Re: [PATCH] mmc: mmc: Fix HS setting in mmc_hs400_to_hs200()

2019-02-12 Thread Chaotian Jing
On Wed, 2019-02-13 at 08:24 +0100, Ulf Hansson wrote:
> On Wed, 13 Feb 2019 at 04:13, Chaotian Jing  
> wrote:
> >
> > On Wed, 2019-02-13 at 08:54 +0800, Chaotian Jing wrote:
> > > On Tue, 2019-02-12 at 10:04 +0200, Adrian Hunter wrote:
> > > > On 12/02/19 4:04 AM, Chaotian Jing wrote:
> > > > > On Tue, 2019-02-05 at 15:42 +0200, Adrian Hunter wrote:
> > > > >> On 5/02/19 3:06 PM, Ulf Hansson wrote:
> > > > >>> On Mon, 4 Feb 2019 at 14:42, Adrian Hunter 
> > > > >>>  wrote:
> > > > 
> > > >  On 4/02/19 12:54 PM, Ulf Hansson wrote:
> > > > > On Mon, 4 Feb 2019 at 10:58, Adrian Hunter 
> > > > >  wrote:
> > > > >>
> > > > >> On 1/02/19 10:10 AM, Ulf Hansson wrote:
> > > > >>> On Fri, 1 Feb 2019 at 02:38, Chaotian Jing 
> > > > >>>  wrote:
> > > > 
> > > >  On Thu, 2019-01-31 at 16:58 +0100, Ulf Hansson wrote:
> > > > > On Thu, 31 Jan 2019 at 08:53, Chaotian Jing 
> > > > >  wrote:
> > > > >>
> > > > >> mmc_hs400_to_hs200() begins with the card and host in HS400 
> > > > >> mode.
> > > > >> Therefore, any commands sent to the card should use HS400 
> > > > >> timing.
> > > > >> It is incorrect to reduce frequency to 50Mhz before sending 
> > > > >> the switch
> > > > >> command, in this case, only reduce clock frequency to 50Mhz 
> > > > >> but without
> > > > >> host timming change, host is still in hs400 mode but clock 
> > > > >> changed from
> > > > >> 200Mhz to 50Mhz, which makes the tuning result unsuitable 
> > > > >> and cause
> > > > >> the switch command gets response CRC error.
> > > > >
> > > > > According the eMMC spec there is no violation by decreasing 
> > > > > the clock
> > > > > frequency like this. We can use whatever value <=200MHz.
> > > > >
> > > > > However, perhaps in practice this becomes an issue, due to 
> > > > > the tuning
> > > > > for HS400 has been done on the "current" frequency.
> > > > >
> > > > > As as start, I think you need to clarify this in the 
> > > > > changelog.
> > > > >
> > > >  Yes, reduce clock frequency to 50Mhz is no Spec violation, but 
> > > >  it may
> > > >  cause __mmc_switch() gets response CRC error, decreasing the 
> > > >  clock but
> > > >  without HOST mode change, on the host side, host driver do not 
> > > >  know
> > > >  what's operation the core layer want to do and can only set 
> > > >  current bus
> > > >  clock to 50Mhz, without tuning parameter change, it has a 
> > > >  chance lead to
> > > >  response CRC error. even lower clock frequency, but with the 
> > > >  wrong
> > > >  tuning parameter setting(the setting is of hs400 tuning 
> > > >  @200Mhz).
> > > > >>>
> > > > >>> Right, makes sense.
> > > > >>>
> > > > >>
> > > > >> this patch refers to mmc_select_hs400(), make the reduce 
> > > > >> clock frequency
> > > > >> after card timing change.
> > > > >>
> > > > >> Signed-off-by: Chaotian Jing 
> > > > >> ---
> > > > >>  drivers/mmc/core/mmc.c | 8 
> > > > >>  1 file changed, 4 insertions(+), 4 deletions(-)
> > > > >>
> > > > >> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> > > > >> index da892a5..21b811e 100644
> > > > >> --- a/drivers/mmc/core/mmc.c
> > > > >> +++ b/drivers/mmc/core/mmc.c
> > > > >> @@ -1239,10 +1239,6 @@ int mmc_hs400_to_hs200(struct 
> > > > >> mmc_card *card)
> > > > >> int err;
> > > > >> u8 val;
> > > > >>
> > > > >> -   /* Reduce frequency to HS */
> > > > >> -   max_dtr = card->ext_csd.hs_max_dtr;
> > > > >> -   mmc_set_clock(host, max_dtr);
> > > > >> -
> > > > >
> > > > > As far as I can tell, the reason to why we change the clock 
> > > > > frequency
> > > > > *before* the call to __mmc_switch() below, is probably to try 
> > > > > to be on
> > > > > the safe side and conform to the spec.
> > > > >
> > > >  Agree, it Must be more safe with lower clock frequency, but the
> > > >  precondition is to make the host side recognize current timing 
> > > >  is not
> > > >  HS400 mode. it has no method to find a safe setting to ensure 
> > > >  no
> > > >  response CRC error when reduce clock from 200Mhz to 50Mhz.
> > > > > However, I think you have a point, as the call to 
> > > > > __mmc_switch(),
> > > > > passes the "send_status" parameter as false, no other command 
> > > > > than the
> > > > > CMD6 is sent to the card.
> > > > >
> > > >

Re: [PATCH] Documentation/atomic_t: Clarify signed vs unsigned

2019-02-12 Thread Ingo Molnar


* Peter Zijlstra  wrote:

> 
> Clarify the whole signed vs unsigned issue for atomic_t.
> 
> There has been enough confusion on this topic to warrant a few explicit
> words I feel.
> 
> Signed-off-by: Peter Zijlstra (Intel) 
> ---
>  Documentation/atomic_t.txt | 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git a/Documentation/atomic_t.txt b/Documentation/atomic_t.txt
> index 913396ac5824..dca3fb0554db 100644
> --- a/Documentation/atomic_t.txt
> +++ b/Documentation/atomic_t.txt
> @@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ 
> prefixes omitted for
>smp_mb__{before,after}_atomic()
>  
>  
> +TYPES (signed vs unsigned)

s/vs/vs.

> +-
> +
> +While atomic_t, atomic_long_t and atomic64_t use int, long and s64
> +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow
> +(which implies -fwrapv) and defines signed overflow to behave like
> +2s-complement.
> +
> +Therefore, an explicitly unsigned variant of the atomic ops is strictly
> +unnecessary and we can simply cast, there is no UB.

s/UB/Undefined Behavior

Had to read that twice. Acronyms Seriously Suck.

> +
> +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for
> +signed types.
> +
> +With this we also conform to the C/C++ _Atomic behaviour and things like
> +P1236R1.

Acked-by: Ingo Molnar 

Thanks,

Ingo


RE: [PATCH v4 6/6] RISC-V: Free-up initrd in free_initrd_mem()

2019-02-12 Thread Anup Patel



> -Original Message-
> From: Mike Rapoport [mailto:r...@linux.ibm.com]
> Sent: Wednesday, February 13, 2019 1:09 PM
> To: Christoph Hellwig 
> Cc: Anup Patel ; Palmer Dabbelt
> ; Albert Ou ; Atish Patra
> ; Paul Walmsley ; linux-
> ri...@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v4 6/6] RISC-V: Free-up initrd in free_initrd_mem()
> 
> Hi,
> 
> On Tue, Feb 12, 2019 at 10:44:19PM -0800, Christoph Hellwig wrote:
> > On Wed, Feb 13, 2019 at 06:32:24AM +, Anup Patel wrote:
> > > index 9cd583b6d1cd..c22b873de856 100644
> > > --- a/arch/riscv/kernel/setup.c
> > > +++ b/arch/riscv/kernel/setup.c
> > > @@ -97,8 +97,9 @@ static void __init setup_initrd(void)
> > >   initrd_end = 0;
> > >  }
> > >
> > > -void free_initrd_mem(unsigned long start, unsigned long end)
> > > +void __init free_initrd_mem(unsigned long start, unsigned long end)
> > >  {
> > > + memblock_free(__pa(start), end - start);
> >
> > I'm pretty sure this should be a call to free_reserved_area instead.
> >
> > All regions reserved using memblock_reserved and not freed before
> > initializing the MM are marked reserved and don't have valid page
> > counts, etc.
> >
> > So we need the actions in free_reserved_area to actually make the
> > memory useful.  Now every other architecture except for arm64 seems to
> > do fine without a memblock_free.  I'm not an expert on memblock (but
> > I've CCed one), but I guess the reason is that once the kernel has
> > booted we don't really care about freeing memblock area.
> 
> This late in the boot process there should be a call to
> free_reserved_area() to give pages to the buddy allocator.
> 
> memblock_free() is has no real effect at this point, no idea why arm64 calls 
> it.

Thanks for the info. I will update this patch to use free_reserved_area().

Regards,
Anup


Re: Linux 4.4.174

2019-02-12 Thread Greg KH
On Tue, Feb 12, 2019 at 08:13:11PM -0800, Mark D Rustad wrote:
> On Feb 9, 2019, at 12:13 AM, Greg KH  wrote:
> 
> > On Fri, Feb 08, 2019 at 08:44:32PM -0800, Mark D Rustad wrote:
> > > On Feb 8, 2019, at 2:54 AM, Greg KH  wrote:
> > > 
> > > > diff --git a/Documentation/networking/ip-sysctl.txt
> > > > b/Documentation/networking/ip-sysctl.txt
> > > > index 2ea4c45cf1c8..7c229f59016f 100644
> > > > --- a/Documentation/networking/ip-sysctl.txt
> > > > +++ b/Documentation/networking/ip-sysctl.txt
> > > > @@ -112,14 +112,11 @@ min_adv_mss - INTEGER
> > > > 
> > > >  IP Fragmentation:
> > > > 
> > > > -ipfrag_high_thresh - INTEGER
> > > > -   Maximum memory used to reassemble IP fragments. When
> > > > -   ipfrag_high_thresh bytes of memory is allocated for this 
> > > > purpose,
> > > > -   the fragment handler will toss packets until ipfrag_low_thresh
> > > > -   is reached. This also serves as a maximum limit to namespaces
> > > > -   different from the initial one.
> > > > -
> > > > -ipfrag_low_thresh - INTEGER
> > > > +ipfrag_high_thresh - LONG INTEGER
> > > > +   Maximum memory used to reassemble IP fragments.
> > > > +
> > > > +ipfrag_low_thresh - LONG INTEGER
> > > > +   (Obsolete since linux-4.17)
> > > 
> > > It seems very strange to say that it is obsolete since 4.17 in a 4.4
> > > kernel.
> > 
> > 4.17 is a point in time :)
> 
> Of course I understand, but some random non-kernel-developer tuning a kernel
> may be pretty puzzled. I don't know right off the top something brief that
> would be more generally meaningful, but maybe someone might. What does
> obsolete mean in this context? It exists but does nothing? It exists and
> does something but will eventually go away?

Fair enough, want to provide a patch with the real kernel version this
happened in?

thanks,

greg k-h


[PATCH v3 9/9] device connection: Find device connections also from device graphs

2019-02-12 Thread Heikki Krogerus
If connections between devices are described in OF graph or
ACPI device graph, we can find them by using the
fwnode_graph_*() functions.

Acked-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Tested-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/base/devcon.c | 38 +++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index 858b8d2f6ef8..04db9ae235e4 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -7,10 +7,37 @@
  */
 
 #include 
+#include 
 
 static DEFINE_MUTEX(devcon_lock);
 static LIST_HEAD(devcon_list);
 
+typedef void *(*devcon_match_fn_t)(struct device_connection *con, int ep,
+  void *data);
+
+static void *
+fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id,
+ void *data, devcon_match_fn_t match)
+{
+   struct device_connection con = { .id = con_id };
+   struct fwnode_handle *ep;
+   void *ret;
+
+   fwnode_graph_for_each_endpoint(fwnode, ep) {
+   con.fwnode = fwnode_graph_get_remote_port_parent(ep);
+   if (!fwnode_device_is_available(con.fwnode))
+   continue;
+
+   ret = match(&con, -1, data);
+   fwnode_handle_put(con.fwnode);
+   if (ret) {
+   fwnode_handle_put(ep);
+   return ret;
+   }
+   }
+   return NULL;
+}
+
 /**
  * device_connection_find_match - Find physical connection to a device
  * @dev: Device with the connection
@@ -23,10 +50,9 @@ static LIST_HEAD(devcon_list);
  * caller is expecting to be returned.
  */
 void *device_connection_find_match(struct device *dev, const char *con_id,
-  void *data,
-  void *(*match)(struct device_connection *con,
- int ep, void *data))
+  void *data, devcon_match_fn_t match)
 {
+   struct fwnode_handle *fwnode = dev_fwnode(dev);
const char *devname = dev_name(dev);
struct device_connection *con;
void *ret = NULL;
@@ -35,6 +61,12 @@ void *device_connection_find_match(struct device *dev, const 
char *con_id,
if (!match)
return NULL;
 
+   if (fwnode) {
+   ret = fwnode_graph_devcon_match(fwnode, con_id, data, match);
+   if (ret)
+   return ret;
+   }
+
mutex_lock(&devcon_lock);
 
list_for_each_entry(con, &devcon_list, list) {
-- 
2.20.1



[PATCH v3 5/9] usb: typec: mux: Find the muxes by also matching against the device node

2019-02-12 Thread Heikki Krogerus
When the connections are defined in firmware, struct
device_connection will have the fwnode member pointing to
the device node (struct fwnode_handle) of the requested
device, and the endpoint will not be used at all in that
case.

Acked-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/typec/mux.c | 86 +++--
 1 file changed, 74 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index 8975f58e1d60..a5947d98824d 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -11,6 +11,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 static DEFINE_MUTEX(switch_lock);
@@ -23,15 +25,25 @@ static void *typec_switch_match(struct device_connection 
*con, int ep,
 {
struct typec_switch *sw;
 
-   list_for_each_entry(sw, &switch_list, entry)
-   if (!strcmp(con->endpoint[ep], dev_name(sw->dev)))
-   return sw;
+   if (!con->fwnode) {
+   list_for_each_entry(sw, &switch_list, entry)
+   if (!strcmp(con->endpoint[ep], dev_name(sw->dev)))
+   return sw;
+   return ERR_PTR(-EPROBE_DEFER);
+   }
 
/*
-* We only get called if a connection was found, tell the caller to
-* wait for the switch to show up.
+* With OF graph the mux node must have a boolean device property named
+* "orientation-switch".
 */
-   return ERR_PTR(-EPROBE_DEFER);
+   if (con->id && !fwnode_property_present(con->fwnode, con->id))
+   return NULL;
+
+   list_for_each_entry(sw, &switch_list, entry)
+   if (dev_fwnode(sw->dev) == con->fwnode)
+   return sw;
+
+   return con->id ? ERR_PTR(-EPROBE_DEFER) : NULL;
 }
 
 /**
@@ -112,17 +124,67 @@ EXPORT_SYMBOL_GPL(typec_switch_unregister);
 
 static void *typec_mux_match(struct device_connection *con, int ep, void *data)
 {
+   const struct typec_altmode_desc *desc = data;
struct typec_mux *mux;
+   size_t nval;
+   bool match;
+   u16 *val;
+   int i;
 
-   list_for_each_entry(mux, &mux_list, entry)
-   if (!strcmp(con->endpoint[ep], dev_name(mux->dev)))
-   return mux;
+   if (!con->fwnode) {
+   list_for_each_entry(mux, &mux_list, entry)
+   if (!strcmp(con->endpoint[ep], dev_name(mux->dev)))
+   return mux;
+   return ERR_PTR(-EPROBE_DEFER);
+   }
 
/*
-* We only get called if a connection was found, tell the caller to
-* wait for the switch to show up.
+* Check has the identifier already been "consumed". If it
+* has, no need to do any extra connection identification.
 */
-   return ERR_PTR(-EPROBE_DEFER);
+   match = !con->id;
+   if (match)
+   goto find_mux;
+
+   /* Accessory Mode muxes */
+   if (!desc) {
+   match = fwnode_property_present(con->fwnode, "accessory");
+   if (match)
+   goto find_mux;
+   return NULL;
+   }
+
+   /* Alternate Mode muxes */
+   nval = fwnode_property_read_u16_array(con->fwnode, "svid", NULL, 0);
+   if (nval <= 0)
+   return NULL;
+
+   val = kcalloc(nval, sizeof(*val), GFP_KERNEL);
+   if (!val)
+   return ERR_PTR(-ENOMEM);
+
+   nval = fwnode_property_read_u16_array(con->fwnode, "svid", val, nval);
+   if (nval < 0) {
+   kfree(val);
+   return ERR_PTR(nval);
+   }
+
+   for (i = 0; i < nval; i++) {
+   match = val[i] == desc->svid;
+   if (match) {
+   kfree(val);
+   goto find_mux;
+   }
+   }
+   kfree(val);
+   return NULL;
+
+find_mux:
+   list_for_each_entry(mux, &mux_list, entry)
+   if (dev_fwnode(mux->dev) == con->fwnode)
+   return mux;
+
+   return match ? ERR_PTR(-EPROBE_DEFER) : NULL;
 }
 
 /**
-- 
2.20.1



[PATCH v3 8/9] device connection: Prepare support for firmware described connections

2019-02-12 Thread Heikki Krogerus
When the connections are defined in firmware, struct
device_connection will have the fwnode member pointing to
the device node (struct fwnode_handle) of the requested
device. The endpoint member for the device names will not be
used at all in that case.

Acked-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Tested-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/base/devcon.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index d427e806cd73..858b8d2f6ef8 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -75,12 +75,36 @@ static struct bus_type *generic_match_buses[] = {
NULL,
 };
 
+static int device_fwnode_match(struct device *dev, void *fwnode)
+{
+   return dev_fwnode(dev) == fwnode;
+}
+
+static void *device_connection_fwnode_match(struct device_connection *con)
+{
+   struct bus_type *bus;
+   struct device *dev;
+
+   for (bus = generic_match_buses[0]; bus; bus++) {
+   dev = bus_find_device(bus, NULL, (void *)con->fwnode,
+ device_fwnode_match);
+   if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
+   return dev;
+
+   put_device(dev);
+   }
+   return NULL;
+}
+
 /* This tries to find the device from the most common bus types by name. */
 static void *generic_match(struct device_connection *con, int ep, void *data)
 {
struct bus_type *bus;
struct device *dev;
 
+   if (con->fwnode)
+   return device_connection_fwnode_match(con);
+
for (bus = generic_match_buses[0]; bus; bus++) {
dev = bus_find_device_by_name(bus, NULL, con->endpoint[ep]);
if (dev)
-- 
2.20.1



[PATCH v3 2/9] usb: typec: Rationalize the API for the muxes

2019-02-12 Thread Heikki Krogerus
Since with accessory modes there is no need for additional
identification when requesting a handle to the mux, we can
replace the second parameter that is passed to the
typec_mux_get() function with a pointer to alternate mode
description structure, and simply passing NULL with
accessory modes.

This change means the naming of the mux device connections
can be updated. Alternate and Accessory Modes will both be
handled with muxes named "mode-switch", and the orientation
switches will be named "orientation-switch".

Future identification of the alternate modes will be later
done using device property "svid" of the mux.

Reviewed-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/typec/class.c |  7 ++-
 drivers/usb/typec/mux.c   | 10 ++
 include/linux/usb/typec_mux.h |  3 ++-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 41c0d790a50f..45abe2c7e9f3 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1496,11 +1496,8 @@ typec_port_register_altmode(struct typec_port *port,
 {
struct typec_altmode *adev;
struct typec_mux *mux;
-   char id[10];
 
-   sprintf(id, "id%04xm%02x", desc->svid, desc->mode);
-
-   mux = typec_mux_get(&port->dev, id);
+   mux = typec_mux_get(&port->dev, desc);
if (IS_ERR(mux))
return ERR_CAST(mux);
 
@@ -1593,7 +1590,7 @@ struct typec_port *typec_register_port(struct device 
*parent,
return ERR_CAST(port->sw);
}
 
-   port->mux = typec_mux_get(&port->dev, "typec-mux");
+   port->mux = typec_mux_get(&port->dev, NULL);
if (IS_ERR(port->mux)) {
put_device(&port->dev);
return ERR_CAST(port->mux);
diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index d990aa510fab..8975f58e1d60 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -48,7 +48,7 @@ struct typec_switch *typec_switch_get(struct device *dev)
struct typec_switch *sw;
 
mutex_lock(&switch_lock);
-   sw = device_connection_find_match(dev, "typec-switch", NULL,
+   sw = device_connection_find_match(dev, "orientation-switch", NULL,
  typec_switch_match);
if (!IS_ERR_OR_NULL(sw)) {
WARN_ON(!try_module_get(sw->dev->driver->owner));
@@ -128,19 +128,21 @@ static void *typec_mux_match(struct device_connection 
*con, int ep, void *data)
 /**
  * typec_mux_get - Find USB Type-C Multiplexer
  * @dev: The caller device
- * @name: Mux identifier
+ * @desc: Alt Mode description
  *
  * Finds a mux linked to the caller. This function is primarily meant for the
  * Type-C drivers. Returns a reference to the mux on success, NULL if no
  * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection
  * was found but the mux has not been enumerated yet.
  */
-struct typec_mux *typec_mux_get(struct device *dev, const char *name)
+struct typec_mux *typec_mux_get(struct device *dev,
+   const struct typec_altmode_desc *desc)
 {
struct typec_mux *mux;
 
mutex_lock(&mux_lock);
-   mux = device_connection_find_match(dev, name, NULL, typec_mux_match);
+   mux = device_connection_find_match(dev, "mode-switch", (void *)desc,
+  typec_mux_match);
if (!IS_ERR_OR_NULL(mux)) {
WARN_ON(!try_module_get(mux->dev->driver->owner));
get_device(mux->dev);
diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h
index 79293f630ee1..43f40685e53c 100644
--- a/include/linux/usb/typec_mux.h
+++ b/include/linux/usb/typec_mux.h
@@ -47,7 +47,8 @@ void typec_switch_put(struct typec_switch *sw);
 int typec_switch_register(struct typec_switch *sw);
 void typec_switch_unregister(struct typec_switch *sw);
 
-struct typec_mux *typec_mux_get(struct device *dev, const char *name);
+struct typec_mux *
+typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc);
 void typec_mux_put(struct typec_mux *mux);
 int typec_mux_register(struct typec_mux *mux);
 void typec_mux_unregister(struct typec_mux *mux);
-- 
2.20.1



[PATCH v3 4/9] device connection: Add fwnode member to struct device_connection

2019-02-12 Thread Heikki Krogerus
This will prepare the device connection API for connections
described in firmware.

Acked-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 include/linux/device.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/device.h b/include/linux/device.h
index d4e74fa42f9c..333db8c06152 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -758,11 +758,17 @@ struct device_dma_parameters {
 
 /**
  * struct device_connection - Device Connection Descriptor
+ * @fwnode: The device node of the connected device
  * @endpoint: The names of the two devices connected together
  * @id: Unique identifier for the connection
  * @list: List head, private, for internal use only
+ *
+ * NOTE: @fwnode is not used together with @endpoint. @fwnode is used when
+ * platform firmware defines the connection. When the connection is registered
+ * with device_connection_add() @endpoint is used instead.
  */
 struct device_connection {
+   struct fwnode_handle*fwnode;
const char  *endpoint[2];
const char  *id;
struct list_headlist;
-- 
2.20.1



[PATCH v3 7/9] usb: typec: Find the ports by also matching against the device node

2019-02-12 Thread Heikki Krogerus
When the connections are defined in firmware, struct
device_connection will have the fwnode member pointing to
the device node (struct fwnode_handle) of the requested
device, and the endpoint will not be used at all in that
case.

Acked-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/typec/class.c | 24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 45abe2c7e9f3..2eb623841847 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "bus.h"
@@ -204,15 +205,32 @@ static void typec_altmode_put_partner(struct altmode 
*altmode)
put_device(&adev->dev);
 }
 
-static int __typec_port_match(struct device *dev, const void *name)
+static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
+{
+   return dev_fwnode(dev) == fwnode;
+}
+
+static int typec_port_name_match(struct device *dev, const void *name)
 {
return !strcmp((const char *)name, dev_name(dev));
 }
 
 static void *typec_port_match(struct device_connection *con, int ep, void 
*data)
 {
-   return class_find_device(typec_class, NULL, con->endpoint[ep],
-__typec_port_match);
+   struct device *dev;
+
+   /*
+* FIXME: Check does the fwnode supports the requested SVID. If it does
+* we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
+*/
+   if (con->fwnode)
+   return class_find_device(typec_class, NULL, con->fwnode,
+typec_port_fwnode_match);
+
+   dev = class_find_device(typec_class, NULL, con->endpoint[ep],
+   typec_port_name_match);
+
+   return dev ? dev : ERR_PTR(-EPROBE_DEFER);
 }
 
 struct typec_altmode *
-- 
2.20.1



[PATCH v3 6/9] usb: roles: Find the muxes by also matching against the device node

2019-02-12 Thread Heikki Krogerus
When the connections are defined in firmware, struct
device_connection will have the fwnode member pointing to
the device node (struct fwnode_handle) of the requested
device, and the endpoint will not be used at all in that
case.

Acked-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Tested-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/usb/roles/class.c | 21 ++---
 include/linux/usb/role.h  |  2 ++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index 99116af07f1d..f45d8df5cfb8 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -84,7 +85,12 @@ enum usb_role usb_role_switch_get_role(struct 
usb_role_switch *sw)
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
 
-static int __switch_match(struct device *dev, const void *name)
+static int switch_fwnode_match(struct device *dev, const void *fwnode)
+{
+   return dev_fwnode(dev) == fwnode;
+}
+
+static int switch_name_match(struct device *dev, const void *name)
 {
return !strcmp((const char *)name, dev_name(dev));
 }
@@ -94,8 +100,16 @@ static void *usb_role_switch_match(struct device_connection 
*con, int ep,
 {
struct device *dev;
 
-   dev = class_find_device(role_class, NULL, con->endpoint[ep],
-   __switch_match);
+   if (con->fwnode) {
+   if (!fwnode_property_present(con->fwnode, con->id))
+   return NULL;
+
+   dev = class_find_device(role_class, NULL, con->fwnode,
+   switch_fwnode_match);
+   } else {
+   dev = class_find_device(role_class, NULL, con->endpoint[ep],
+   switch_name_match);
+   }
 
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
 }
@@ -266,6 +280,7 @@ usb_role_switch_register(struct device *parent,
sw->get = desc->get;
 
sw->dev.parent = parent;
+   sw->dev.fwnode = desc->fwnode;
sw->dev.class = role_class;
sw->dev.type = &usb_role_dev_type;
dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent));
diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h
index edc51be4a77c..c05ffa6abda9 100644
--- a/include/linux/usb/role.h
+++ b/include/linux/usb/role.h
@@ -18,6 +18,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device 
*dev);
 
 /**
  * struct usb_role_switch_desc - USB Role Switch Descriptor
+ * @fwnode: The device node to be associated with the role switch
  * @usb2_port: Optional reference to the host controller port device (USB2)
  * @usb3_port: Optional reference to the host controller port device (USB3)
  * @udc: Optional reference to the peripheral controller device
@@ -32,6 +33,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device 
*dev);
  * usb_role_switch_register() before registering the switch.
  */
 struct usb_role_switch_desc {
+   struct fwnode_handle *fwnode;
struct device *usb2_port;
struct device *usb3_port;
struct device *udc;
-- 
2.20.1



[PATCH v3 3/9] platform/x86: intel_cht_int33fe: Remove old style mux connections

2019-02-12 Thread Heikki Krogerus
The new mux connection naming scheme is now in use, so
dropping the connections still using the old names. From now
on the same connection description named "mode-switch" is
used with both the port and the alternate modes, so on CHT
the DP alt mode will use the same connection as the port to
get a handle to the mux device.

Reviewed-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/intel_cht_int33fe.c | 21 ++---
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/intel_cht_int33fe.c 
b/drivers/platform/x86/intel_cht_int33fe.c
index 295fe19ad4c2..6fa3cced6f8e 100644
--- a/drivers/platform/x86/intel_cht_int33fe.c
+++ b/drivers/platform/x86/intel_cht_int33fe.c
@@ -32,7 +32,7 @@ struct cht_int33fe_data {
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
/* Contain a list-head must be per device */
-   struct device_connection connections[7];
+   struct device_connection connections[4];
 };
 
 /*
@@ -174,22 +174,13 @@ static int cht_int33fe_probe(struct platform_device *pdev)
 
data->connections[0].endpoint[0] = "port0";
data->connections[0].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[0].id = "typec-switch";
+   data->connections[0].id = "orientation-switch";
data->connections[1].endpoint[0] = "port0";
data->connections[1].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[1].id = "typec-mux";
-   data->connections[2].endpoint[0] = "port0";
-   data->connections[2].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[2].id = "idff01m01";
-   data->connections[3].endpoint[0] = "i2c-fusb302";
-   data->connections[3].endpoint[1] = "intel_xhci_usb_sw-role-switch";
-   data->connections[3].id = "usb-role-switch";
-   data->connections[4].endpoint[0] = "port0";
-   data->connections[4].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[4].id = "orientation-switch";
-   data->connections[5].endpoint[0] = "port0";
-   data->connections[5].endpoint[1] = "i2c-pi3usb30532";
-   data->connections[5].id = "mode-switch";
+   data->connections[1].id = "mode-switch";
+   data->connections[2].endpoint[0] = "i2c-fusb302";
+   data->connections[2].endpoint[1] = "intel_xhci_usb_sw-role-switch";
+   data->connections[2].id = "usb-role-switch";
 
device_connections_add(data->connections);
 
-- 
2.20.1



[PATCH v3 1/9] platform/x86: intel_cht_int33fe: Prepare for better mux naming scheme

2019-02-12 Thread Heikki Krogerus
Adding new connections with for the muxes with new
identifiers. The old connection are left in for now.

Reviewed-by: Hans de Goede 
Reviewed-by: Andy Shevchenko 
Reviewed-by: Jun Li 
Signed-off-by: Heikki Krogerus 
---
 drivers/platform/x86/intel_cht_int33fe.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/intel_cht_int33fe.c 
b/drivers/platform/x86/intel_cht_int33fe.c
index 02bc74608cf3..295fe19ad4c2 100644
--- a/drivers/platform/x86/intel_cht_int33fe.c
+++ b/drivers/platform/x86/intel_cht_int33fe.c
@@ -32,7 +32,7 @@ struct cht_int33fe_data {
struct i2c_client *fusb302;
struct i2c_client *pi3usb30532;
/* Contain a list-head must be per device */
-   struct device_connection connections[5];
+   struct device_connection connections[7];
 };
 
 /*
@@ -184,6 +184,12 @@ static int cht_int33fe_probe(struct platform_device *pdev)
data->connections[3].endpoint[0] = "i2c-fusb302";
data->connections[3].endpoint[1] = "intel_xhci_usb_sw-role-switch";
data->connections[3].id = "usb-role-switch";
+   data->connections[4].endpoint[0] = "port0";
+   data->connections[4].endpoint[1] = "i2c-pi3usb30532";
+   data->connections[4].id = "orientation-switch";
+   data->connections[5].endpoint[0] = "port0";
+   data->connections[5].endpoint[1] = "i2c-pi3usb30532";
+   data->connections[5].id = "mode-switch";
 
device_connections_add(data->connections);
 
-- 
2.20.1



[PATCH v3 0/9] device connection: Add support for device graphs

2019-02-12 Thread Heikki Krogerus
Hi,

This is the third version of my proposal to add device graph parsing
to the device connection API. There was only one problem reported in
v2 by Jun - kernel-doc entry was missing for the new fwnode member in
struct usb_role_switch_desc - and it's now fixed.

The second version of the series:
https://lkml.org/lkml/2019/1/30/622

The commit message from v1:

This series adds support for OF and ACPI device graph parsing to the
device connection API.

Handling the graph is straightforward, but because I'm adding that
fwnode member to struct device_connection, I had to make sure all the
existing users consider it.

The plan is to only support matching with fwnode in the future, so no
more device name matching. The software fwnodes that we now have in
kernel should make that possible, once we add support for references
to them.

The original RFC:
https://lkml.org/lkml/2018/10/24/619

thanks,

Heikki Krogerus (9):
  platform/x86: intel_cht_int33fe: Prepare for better mux naming scheme
  usb: typec: Rationalize the API for the muxes
  platform/x86: intel_cht_int33fe: Remove old style mux connections
  device connection: Add fwnode member to struct device_connection
  usb: typec: mux: Find the muxes by also matching against the device
node
  usb: roles: Find the muxes by also matching against the device node
  usb: typec: Find the ports by also matching against the device node
  device connection: Prepare support for firmware described connections
  device connection: Find device connections also from device graphs

 drivers/base/devcon.c| 62 ++-
 drivers/platform/x86/intel_cht_int33fe.c | 15 ++--
 drivers/usb/roles/class.c| 21 +-
 drivers/usb/typec/class.c| 31 ++--
 drivers/usb/typec/mux.c  | 96 
 include/linux/device.h   |  6 ++
 include/linux/usb/role.h |  2 +
 include/linux/usb/typec_mux.h|  3 +-
 8 files changed, 196 insertions(+), 40 deletions(-)

-- 
2.20.1



Re: [PATCH v2 2/2] locking/rwsem: Optimize down_read_trylock()

2019-02-12 Thread Ingo Molnar


* Waiman Long  wrote:

> I looked at the assembly code in arch/x86/include/asm/rwsem.h. For both
> trylocks (read & write), the count is read first before attempting to
> lock it. We did the same for all trylock functions in other locks.
> Depending on how the trylock is used and how contended the lock is, it
> may help or hurt performance. Changing down_read_trylock to do an
> unconditional cmpxchg will change the performance profile of existing
> code. So I would prefer keeping the current code.
> 
> I do notice now that the generic down_write_trylock() code is doing an
> unconditional compxchg. So I wonder if we should change it to read the
> lock first like other trylocks or just leave it as it is.

No, I think we should instead move the other trylocks to the 
try-for-ownership model as well, like Linus suggested.

That's the general assumption we make in locking primitives, that we 
optimize for the common, expected case - which would be that the trylock 
succeeds, and I don't see why trylock primitives should be different.

In fact I can see more ways for read-for-sharing to perform suboptimally 
on larger systems.

Thanks,

Ingo


Re: [PATCH v4 1/2] tpm: Unify the send callback behaviour

2019-02-12 Thread Jarkko Sakkinen
On Mon, Feb 11, 2019 at 04:05:39PM +0100, Alexander Steffen wrote:
> Tested-by: Alexander Steffen 

Thank you!

/Jarkko


[PATCH v2] iio/gyro/bmg160: Use millidegrees for temperature scale

2019-02-12 Thread Mike Looijmans
Standard unit for temperature is millidegrees Celcius, whereas this driver
was reporting in degrees. Fix the scale factor in the driver.

Signed-off-by: Mike Looijmans 
---
v2: Don't touch val2 when returning IIO_VAL_INT
Only touch val when returning a value

 drivers/iio/gyro/bmg160_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
index 63ca316..92c07ab 100644
--- a/drivers/iio/gyro/bmg160_core.c
+++ b/drivers/iio/gyro/bmg160_core.c
@@ -582,11 +582,10 @@ static int bmg160_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
return bmg160_get_filter(data, val);
case IIO_CHAN_INFO_SCALE:
-   *val = 0;
switch (chan->type) {
case IIO_TEMP:
-   *val2 = 50;
-   return IIO_VAL_INT_PLUS_MICRO;
+   *val = 500;
+   return IIO_VAL_INT;
case IIO_ANGL_VEL:
{
int i;
@@ -594,6 +593,7 @@ static int bmg160_read_raw(struct iio_dev *indio_dev,
for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
if (bmg160_scale_table[i].dps_range ==
data->dps_range) {
+   *val = 0;
*val2 = bmg160_scale_table[i].scale;
return IIO_VAL_INT_PLUS_MICRO;
}
-- 
1.9.1



Re: [PATCH v4 6/6] RISC-V: Free-up initrd in free_initrd_mem()

2019-02-12 Thread Mike Rapoport
Hi,

On Tue, Feb 12, 2019 at 10:44:19PM -0800, Christoph Hellwig wrote:
> On Wed, Feb 13, 2019 at 06:32:24AM +, Anup Patel wrote:
> > index 9cd583b6d1cd..c22b873de856 100644
> > --- a/arch/riscv/kernel/setup.c
> > +++ b/arch/riscv/kernel/setup.c
> > @@ -97,8 +97,9 @@ static void __init setup_initrd(void)
> > initrd_end = 0;
> >  }
> >  
> > -void free_initrd_mem(unsigned long start, unsigned long end)
> > +void __init free_initrd_mem(unsigned long start, unsigned long end)
> >  {
> > +   memblock_free(__pa(start), end - start);
> 
> I'm pretty sure this should be a call to free_reserved_area instead.
> 
> All regions reserved using memblock_reserved and not freed before
> initializing the MM are marked reserved and don't have valid page
> counts, etc.
> 
> So we need the actions in free_reserved_area to actually make the
> memory useful.  Now every other architecture except for arm64
> seems to do fine without a memblock_free.  I'm not an expert on
> memblock (but I've CCed one), but I guess the reason is that once
> the kernel has booted we don't really care about freeing memblock
> area.

This late in the boot process there should be a call to
free_reserved_area() to give pages to the buddy allocator.

memblock_free() is has no real effect at this point, no idea why arm64
calls it.

-- 
Sincerely yours,
Mike.



Re: [RFC PATCH v1 3/3] regulator: bd718x7: Support SNVS low power state

2019-02-12 Thread Matti Vaittinen
Hello Mark,

On Tue, Feb 12, 2019 at 04:08:31PM +, Mark Brown wrote:
> On Tue, Feb 12, 2019 at 04:19:38PM +0200, Matti Vaittinen wrote:
> > read ROHM BD71837 / BD71847 specific device tree bindings for
> > controlling the PMIC shutdown/reset states and voltages for
> > different HW states. The PMIC was designed to be used with NXP
> > i.MX8 SoC and it supports SNVS low power state which seems to
> > be typical for NXP i.MX SoCs. However, when SNVS is used we must
> > not allow SW to control enabling/disabling those regulators which
> > are crucial for system to boot as there is a HW limitation which
> > causes SW controlled regulators to be kept shut down after SNVS
> > reset.
> > 
> > Allow setting the SNVS to be used as reset target state and allow
> > marking those regulators which are critical for boot.
> 
> The general idea seems fine but I'm wondering if we should use the
> existing bindings and just prevent any change with fixed configurations
> - that *should* just be a case of picking appropriate constraints I
> think.  Why does this need completely new properties other than
> preventing the user from shooting themselves in the foot?

The BD71847 and BD71847 have 'HW state machine' in PMIC. It has READY,
RUN, IDLE, SUSPEND, SNVS,.. states.

At RUN state, the enabling and disabling status can be either a
predefined configuration - or controlled by SW. There is one bit for
each regulator which can be used to switch the control to the SW.

By default the BD718x7 driver turns this control bit so that all of the
regulators are controlled by SW. This is done at driver probe, right
after the regulators have been registered.

Now when a reset occurs (SW reset or reset via power button press,
external WDG, ...) the PMIC disables all power outputs no matter if they
are controlled by SW or HW.

Unfortunately there is this 'feature' in PMIC so that when PMIC starts
up after reset, those regulators which were controlled by SW won't be
powered again - no matter if they were enabled before reset. This
happens only whn reset target state was SNVS state.

So with current driver design, even if constrains prevented the
regulator core from touching the regulators, the driver still changes
the control to SW. So we need to parse some attribute in the BD718x7
driver side. Besides, I did not spot a 'do not touch me' property from
the bindings :)

But after writing all this - I think you are correct. We do not need the
rohm,regulator-crucial-for-boot. I guess we can check for the
combination of:

regulator-always-on and regulator-boot-on

and interpret this as "rohm,regulator-crucial-for-boot".

I just think I need to document that those flags are required
for critical regulators if SNVS is used as reset target even if there
should be no one touching those regulators.

Thanks once again for the feedback Mark!

Br,
Matti Vaittinen

-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~


Re: [GIT PULL rcu/next] RCU commits for 5.1

2019-02-12 Thread Ingo Molnar


* Paul E. McKenney  wrote:

> Hello, Ingo,
> 
> This pull request contains the following changes:
> 
> 1.Additional cleanups after RCU flavor consolidation.
> 
>   http://lkml.kernel.org/r/20190109211830.ga30...@linux.ibm.com
> 
> 2.Grace-period forward-progress cleanups and improvements.
> 
>   http://lkml.kernel.org/r/20190109212816.ga32...@linux.ibm.com
> 
> 3.Documentation updates.
> 
>   http://lkml.kernel.org/r/20190109213302.ga1...@linux.ibm.com
> 
> 4.Miscellaneous fixes.
> 
>   http://lkml.kernel.org/r/20190109214115.ga2...@linux.ibm.com
> 
> 5.spin_is_locked() conversions to lockdep.
> 
>   http://lkml.kernel.org/r/20190109222120.ga13...@linux.ibm.com
> 
> 6.SPDX changes to RCU source and header files.
> 
>   http://lkml.kernel.org/r/20190207141700.ga11...@linux.ibm.com
> 
> 7.SRCU updates.
> 
>   http://lkml.kernel.org/r/20190109214506.ga4...@linux.ibm.com
> 
> 8.Torture-test updates, including nolibc updates and moving
>   nolibc to tools/include.
> 
>   http://lkml.kernel.org/r/20190109214944.ga5...@linux.ibm.com
> 
> All of these changes have been subjected to 0day Test Robot and -next
> testing, and are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git 
> e7ffb4eb9a6d89678e7f62461737899f88dab64e
> 
> for you to fetch changes up to e7ffb4eb9a6d89678e7f62461737899f88dab64e:
> 
>   Merge branches 'doc.2019.01.26a', 'fixes.2019.01.26a', 'sil.2019.01.26a', 
> 'spdx.2019.02.09a', 'srcu.2019.01.26a' and 'torture.2019.01.26a' into HEAD 
> (2019-02-09 08:47:52 -0800)
> 
> Note that the diffstat output omits the addition of tree_stall.h, so is
> overly optimistic.  :-/
> 
> 
> Joel Fernandes (Google) (1):
>   rcu: Add sparse check to rcu_assign_pointer()
> 
> Junchang Wang (2):
>   doc: Fix outdated links
>   RCU/torture.txt: Remove section MODULE PARAMETERS
> 
> Paul E. McKenney (59):
>   sched: Replace call_rcu_sched() with call_rcu()
>   sched: Replace synchronize_sched() with synchronize_rcu()
>   rcu: Rename and comment changes due to only one rcuo kthread per CPU
>   rcu: Make expedited IPI handler return after handling critical section
>   rcu: Inline force_quiescent_state() into rcu_force_quiescent_state()
>   rcu: Eliminate RCU_BH_FLAVOR and RCU_SCHED_FLAVOR
>   rcu: Inline rcu_kthread_do_work() into its sole remaining caller
>   rcu: Determine expedited-GP IPI handler at build time
>   rcu: Consolidate PREEMPT and !PREEMPT synchronize_rcu_expedited()
>   rcu: Consolidate PREEMPT and !PREEMPT synchronize_rcu()
>   rcu: Inline _synchronize_rcu_expedited() into 
> synchronize_rcu_expedited()
>   rcu: Discard separate per-CPU callback counts
>   rcu: Remove wrapper definitions for obsolete RCU update functions
>   rcu: Accommodate zero jiffies_till_first_fqs and kthread kicking
>   rcu: Move rcu_cpu_kthread_task to rcu_data structure
>   rcu: Move rcu_cpu_kthread_status to rcu_data structure
>   rcu: Remove unused rcu_cpu_kthread_loops per-CPU variable
>   rcu: Move rcu_cpu_has_work to rcu_data structure
>   rcu: Remove unused rcu_cpu_kthread_cpu per-CPU variable
>   rcu: Update NOCB comments
>   rcu: Improve diagnostics for failed RCU grace-period start
>   rcu: Protect rcu_check_gp_kthread_starvation() access to ->gp_flags
>   rcu: Add sysrq rcu_node-dump capability
>   Merge branches 'consolidate.2019.01.26a' and 'fwd.2019.01.26a' into HEAD
>   doc: Now jiffies_till_sched_qs solicits help from cond_resched()
>   doc: CPU-hotplug notifiers cannot invoke synchronize_srcu() or 
> srcu_barrier()
>   rcu: Docbook for rcu_head_init() and rcu_head_after_call_rcu()
>   rcu: Rename rcu_check_callbacks() to rcu_sched_clock_irq()
>   rcu: Rename rcu_process_callbacks() to rcu_core() for Tree RCU
>   rcu: Remove preemption disabling from expedited CPU selection
>   rcu: Repair rcu_nmi_exit() docbook header
>   rcu: Fix obsolete DYNTICK_IRQ_NONIDLE comment
>   include/asm-generic: Remove spin_is_locked() comment
>   virt/kvm: Replace spin_is_locked() with lockdep
>   srcu: Check for invalid idx argument in srcu_read_unlock()
>   rcutorture: Record grace periods in forward-progress histogram
>   torture: Explain and simplify odd "for" loop in mkinitrd.sh
>   rcutorture: Add grace period after CPU offline
>   rcuperf: Stop abusing IS_ENABLED()
>   rcu/rcu.h: Convert to SPDX license identifier
>   rcu/rcuperf: Convert to SPDX license identifier
>   rcu/rcu_segcblist: Convert to SPDX license identifier
>   rcu/rcutorture: Convert to SPDX license identifier
>   rcu/srcu: Convert to SPDX license identifier
>   rcu/sync: Convert to SPDX license identifier
>   rcu/tiny: Convert to SPDX license identifier
>   rcu/tree: Convert

linux-next: Tree for Feb 13

2019-02-12 Thread Stephen Rothwell
Hi all,

Changes since 20190212:

The net-next tree gained a conflict against the net tree.

The netfilter-next tree gained a build failure so I reverted a commit.

The tip tree gained conflicts against the block tree.

The vhost tree gained a conflict against the swiotlb tree.

The akpm-current tree gained a conflict against the kspp tree and a
build failure due to an interaction with the block tree for which I
applied a merge fix patch.

The akpm gained a conflict against with the tip tree.

Non-merge commits (relative to Linus' tree): 7421
 7866 files changed, 306843 insertions(+), 191459 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc, an allmodconfig for x86_64, a
multi_v7_defconfig for arm and a native build of tools/perf. After
the final fixups (if any), I do an x86_64 modules_install followed by
builds for x86_64 allnoconfig, powerpc allnoconfig (32 and 64 bit),
ppc44x_defconfig, allyesconfig and pseries_le_defconfig and i386, sparc
and sparc64 defconfig. And finally, a simple boot test of the powerpc
pseries_le_defconfig kernel in qemu (with and without kvm enabled).

Below is a summary of the state of the merge.

I am currently merging 296 trees (counting Linus' and 69 trees of bug
fix patches pending for the current merge release).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (aa0c38cf39de Merge branch 'fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal)
Merging fixes/master (0dd62c042779 x86/syscalls: Mark expected switch 
fall-throughs)
Merging kbuild-current/fixes (6db2983cd806 kallsyms: Handle too long symbols in 
kallsyms.c)
Merging arc-current/for-curr (7e9246a982a6 ARCv2: support manual regfile save 
on interrupts)
Merging arm-current/fixes (fc67e6f120a3 ARM: 8835/1: dma-mapping: Clear DMA ops 
on teardown)
Merging arm64-fixes/for-next/fixes (ea5736805190 arm64: kexec_file: handle 
empty command-line)
Merging m68k-current/for-linus (bed1369f5190 m68k: Fix memblock-related crashes)
Merging powerpc-fixes/fixes (5a3840a470c4 powerpc/papr_scm: Use the correct 
bind address)
Merging sparc/master (b71acb0e3721 Merge branch 'linus' of 
git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6)
Merging fscrypt-current/for-stable (ae64f9bd1d36 Linux 4.15-rc2)
Merging net/master (2fdeee254923 team: avoid complex list operations in 
team_nl_cmd_options_set())
Merging bpf/master (1e405c1a3f66 xsk: do not remove umem from netdevice on 
fall-back to copy-mode)
Merging ipsec/master (fc2d5cfdcfe2 af_key: unconditionally clone on broadcast)
Merging netfilter/master (8d29d16d2134 netfilter: compat: initialize all fields 
in xt_init)
Merging ipvs/master (b2e3d68d1251 netfilter: nft_compat: destroy function must 
not have side effects)
Merging wireless-drivers/master (d04ca383860b mt76x0u: fix suspend/resume)
Merging mac80211/master (6157ca0d6bfe mac80211: Fix Tx aggregation session tear 
down with ITXQs)
Merging rdma-fixes/for-rc (48396e80fb65 RDMA/srp: Rework SCSI device reset 
handling)
Merging sound-current/for-linus (00a399cad1a0 ALSA: pcm: Revert capture stream 
behavior change in blocking mode)
Merging sound-asoc-fixes/for-linus (476e1f03e36e Merge branch 'asoc-5.0' into 
asoc-linus)
Merging regmap-fixes/for-linus (f17b5f06cb92 Linux 5.0-rc4)
Merging regulator-fixes/for-linus (e03ae9fb9107 Merge branch 'regulator-5.0' 
into regulator-linus)
Merging spi-fixes/for-linus (5ff2531354af Merge branch 'spi-5.0' into spi-linus)
Merging pci-current/for-linus (f57a98e1b713 PCI: Work around Synopsys duplicate 
Device ID (HAPS USB3, NXP i.MX))
Merging driver-core.current/driver-core-linus (d13937116f1e Linux 5.0-rc6)
Merging tty.current/tty-linus (d13937116f1e Linux 5.0-rc6)
Merging usb.current/usb-linus (d13937116f1e Linux 5.0-rc6)
Merging usb-gadget-fixes/fi

[PATCH v2 1/3] spi: sprd: Add the SPI irq function for the SPI DMA mode

2019-02-12 Thread Baolin Wang
From: Lanqing Liu 

The SPI irq event will use to complete the SPI work in the SPI DMA mode,
so this patch is a preparation for the following DMA mode support.

Moreover the SPI interrupt can be fired when removing the SPI controller,
so we should make sure the SPI controller has stopped the queue in
remove function before freeing the SPI irq.

Signed-off-by: Lanqing Liu 
Signed-off-by: Baolin Wang 
---
Changes from v1:
 - Return IRQ_NONE if detecting incorrect interrupt status.
 - Add spi_controller_suspend in remove function.
---
 drivers/spi/spi-sprd.c |   51 
 1 file changed, 51 insertions(+)

diff --git a/drivers/spi/spi-sprd.c b/drivers/spi/spi-sprd.c
index fa324ce..d1ddeee 100644
--- a/drivers/spi/spi-sprd.c
+++ b/drivers/spi/spi-sprd.c
@@ -133,6 +133,7 @@ struct sprd_spi {
void __iomem *base;
struct device *dev;
struct clk *clk;
+   int irq;
u32 src_clk;
u32 hw_mode;
u32 trans_len;
@@ -141,6 +142,7 @@ struct sprd_spi {
u32 hw_speed_hz;
u32 len;
int status;
+   struct completion xfer_completion;
const void *tx_buf;
void *rx_buf;
int (*read_bufs)(struct sprd_spi *ss, u32 len);
@@ -575,6 +577,48 @@ static int sprd_spi_transfer_one(struct spi_controller 
*sctlr,
return ret;
 }
 
+static irqreturn_t sprd_spi_handle_irq(int irq, void *data)
+{
+   struct sprd_spi *ss = (struct sprd_spi *)data;
+   u32 val = readl_relaxed(ss->base + SPRD_SPI_INT_MASK_STS);
+
+   if (val & SPRD_SPI_MASK_TX_END) {
+   writel_relaxed(SPRD_SPI_TX_END_CLR, ss->base + 
SPRD_SPI_INT_CLR);
+   if (!(ss->trans_mode & SPRD_SPI_RX_MODE))
+   complete(&ss->xfer_completion);
+
+   return IRQ_HANDLED;
+   }
+
+   if (val & SPRD_SPI_MASK_RX_END) {
+   writel_relaxed(SPRD_SPI_RX_END_CLR, ss->base + 
SPRD_SPI_INT_CLR);
+   complete(&ss->xfer_completion);
+
+   return IRQ_HANDLED;
+   }
+
+   return IRQ_NONE;
+}
+
+static int sprd_spi_irq_init(struct platform_device *pdev, struct sprd_spi *ss)
+{
+   int ret;
+
+   ss->irq = platform_get_irq(pdev, 0);
+   if (ss->irq < 0) {
+   dev_err(&pdev->dev, "failed to get irq resource\n");
+   return ss->irq;
+   }
+
+   ret = devm_request_irq(&pdev->dev, ss->irq, sprd_spi_handle_irq,
+   0, pdev->name, ss);
+   if (ret)
+   dev_err(&pdev->dev, "failed to request spi irq %d, ret = %d\n",
+   ss->irq, ret);
+
+   return ret;
+}
+
 static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss)
 {
struct clk *clk_spi, *clk_parent;
@@ -635,11 +679,16 @@ static int sprd_spi_probe(struct platform_device *pdev)
sctlr->max_speed_hz = min_t(u32, ss->src_clk >> 1,
SPRD_SPI_MAX_SPEED_HZ);
 
+   init_completion(&ss->xfer_completion);
platform_set_drvdata(pdev, sctlr);
ret = sprd_spi_clk_init(pdev, ss);
if (ret)
goto free_controller;
 
+   ret = sprd_spi_irq_init(pdev, ss);
+   if (ret)
+   goto free_controller;
+
ret = clk_prepare_enable(ss->clk);
if (ret)
goto free_controller;
@@ -690,6 +739,8 @@ static int sprd_spi_remove(struct platform_device *pdev)
return ret;
}
 
+   spi_controller_suspend(sctlr);
+
clk_disable_unprepare(ss->clk);
pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
-- 
1.7.9.5



Re: [LSF/MM TOPIC] FS, MM, and stable trees

2019-02-12 Thread Greg KH
On Wed, Feb 13, 2019 at 09:20:00AM +0200, Amir Goldstein wrote:
> I never saw an email from you or Greg saying, the branch "stable-xxx" is
> in review. Please run your tests.

That is what my "Subject: [PATCH 4.9 000/137] 4.9.156-stable review"
type emails are supposed to kick off.  They are sent both to the stable
mailing list and lkml.

This message already starts the testing systems going for a number of
different groups out there, do you want to be added to the cc: list so
you get them directly?

thanks,

greg k-h


[PATCH v2 3/3] spi: sprd: spi: sprd: Add DMA mode support

2019-02-12 Thread Baolin Wang
From: Lanqing Liu 

Add DMA mode support for the Spreadtrum SPI controller, and we will enable
SPI interrupt to help to complete the SPI transfer work in DMA mode.

Signed-off-by: Lanqing Liu 
Signed-off-by: Baolin Wang 
---
Changes from v1:
 - Implement the can_dma() ops.
 - Remove DMA slave id configuration.
 - Optimize the SPI irq enable/disable.
---
 drivers/spi/spi-sprd.c |  293 +++-
 1 file changed, 290 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-sprd.c b/drivers/spi/spi-sprd.c
index d1ddeee..0c04a1d 100644
--- a/drivers/spi/spi-sprd.c
+++ b/drivers/spi/spi-sprd.c
@@ -2,6 +2,9 @@
 // Copyright (C) 2018 Spreadtrum Communications Inc.
 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -9,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -128,9 +132,25 @@
 #define SPRD_SPI_DEFAULT_SOURCE2600
 #define SPRD_SPI_MAX_SPEED_HZ  4800
 #define SPRD_SPI_AUTOSUSPEND_DELAY 100
+#define SPRD_SPI_DMA_STEP  8
+
+enum sprd_spi_dma_channel {
+   SPI_RX,
+   SPI_TX,
+   SPI_MAX,
+};
+
+struct sprd_spi_dma {
+   bool enable;
+   struct dma_chan *dma_chan[SPI_MAX];
+   enum dma_slave_buswidth width;
+   u32 fragmens_len;
+   u32 rx_len;
+};
 
 struct sprd_spi {
void __iomem *base;
+   phys_addr_t phy_base;
struct device *dev;
struct clk *clk;
int irq;
@@ -142,6 +162,7 @@ struct sprd_spi {
u32 hw_speed_hz;
u32 len;
int status;
+   struct sprd_spi_dma dma;
struct completion xfer_completion;
const void *tx_buf;
void *rx_buf;
@@ -433,6 +454,208 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, 
struct spi_transfer *t)
return ret;
 }
 
+static void sprd_spi_irq_enable(struct sprd_spi *ss)
+{
+   u32 val;
+
+   /* Clear interrupt status before enabling interrupt. */
+   writel_relaxed(SPRD_SPI_TX_END_CLR | SPRD_SPI_RX_END_CLR,
+   ss->base + SPRD_SPI_INT_CLR);
+   /* Enable SPI interrupt only in DMA mode. */
+   val = readl_relaxed(ss->base + SPRD_SPI_INT_EN);
+   writel_relaxed(val | SPRD_SPI_TX_END_INT_EN |
+  SPRD_SPI_RX_END_INT_EN,
+  ss->base + SPRD_SPI_INT_EN);
+}
+
+static void sprd_spi_irq_disable(struct sprd_spi *ss)
+{
+   writel_relaxed(0, ss->base + SPRD_SPI_INT_EN);
+}
+
+static void sprd_spi_dma_enable(struct sprd_spi *ss, bool enable)
+{
+   u32 val = readl_relaxed(ss->base + SPRD_SPI_CTL2);
+
+   if (enable)
+   val |= SPRD_SPI_DMA_EN;
+   else
+   val &= ~SPRD_SPI_DMA_EN;
+
+   writel_relaxed(val, ss->base + SPRD_SPI_CTL2);
+}
+
+static int sprd_spi_dma_submit(struct dma_chan *dma_chan,
+  struct dma_slave_config *c,
+  struct sg_table *sg,
+  enum dma_transfer_direction dir)
+{
+   struct dma_async_tx_descriptor *desc;
+   dma_cookie_t cookie;
+   unsigned long flags;
+   int ret;
+
+   ret = dmaengine_slave_config(dma_chan, c);
+   if (ret < 0)
+   return ret;
+
+   flags = SPRD_DMA_FLAGS(SPRD_DMA_CHN_MODE_NONE, SPRD_DMA_NO_TRG,
+  SPRD_DMA_FRAG_REQ, SPRD_DMA_TRANS_INT);
+   desc = dmaengine_prep_slave_sg(dma_chan, sg->sgl, sg->nents, dir, 
flags);
+   if (!desc)
+   return  -ENODEV;
+
+   cookie = dmaengine_submit(desc);
+   if (dma_submit_error(cookie))
+   return dma_submit_error(cookie);
+
+   dma_async_issue_pending(dma_chan);
+
+   return 0;
+}
+
+static int sprd_spi_dma_rx_config(struct sprd_spi *ss, struct spi_transfer *t)
+{
+   struct dma_chan *dma_chan = ss->dma.dma_chan[SPI_RX];
+   struct dma_slave_config config = {
+   .src_addr = ss->phy_base,
+   .src_addr_width = ss->dma.width,
+   .dst_addr_width = ss->dma.width,
+   .dst_maxburst = ss->dma.fragmens_len,
+   };
+   int ret;
+
+   ret = sprd_spi_dma_submit(dma_chan, &config, &t->rx_sg, DMA_DEV_TO_MEM);
+   if (ret)
+   return ret;
+
+   return ss->dma.rx_len;
+}
+
+static int sprd_spi_dma_tx_config(struct sprd_spi *ss, struct spi_transfer *t)
+{
+   struct dma_chan *dma_chan = ss->dma.dma_chan[SPI_TX];
+   struct dma_slave_config config = {
+   .dst_addr = ss->phy_base,
+   .src_addr_width = ss->dma.width,
+   .dst_addr_width = ss->dma.width,
+   .src_maxburst = ss->dma.fragmens_len,
+   };
+   int ret;
+
+   ret = sprd_spi_dma_submit(dma_chan, &config, &t->tx_sg, DMA_MEM_TO_DEV);
+   if (ret)
+   return ret;
+
+   return t->len;
+}
+
+static int sprd_spi_dma_request(struct sprd_spi *ss)
+{
+   ss->dma.dma_chan[SPI_RX] = dma_request_chan(ss-

[PATCH v2 2/3] dt-bindings: spi: Add the DMA properties for the SPI dma mode

2019-02-12 Thread Baolin Wang
From: Lanqing Liu 

Add the DMA properties for the SPI dma mode.

Signed-off-by: Lanqing Liu 
Signed-off-by: Baolin Wang 
---
Changes from v1:
 - Remove sprd,dma-slave-ids property.
---
 Documentation/devicetree/bindings/spi/spi-sprd.txt |7 +++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/devicetree/bindings/spi/spi-sprd.txt 
b/Documentation/devicetree/bindings/spi/spi-sprd.txt
index bad211a..3c7eacc 100644
--- a/Documentation/devicetree/bindings/spi/spi-sprd.txt
+++ b/Documentation/devicetree/bindings/spi/spi-sprd.txt
@@ -14,6 +14,11 @@ Required properties:
address on the SPI bus. Should be set to 1.
 - #size-cells: Should be set to 0.
 
+Optional properties:
+dma-names: Should contain names of the SPI used DMA channel.
+dmas: Should contain DMA channels and DMA slave ids which the SPI used
+   sorted in the same order as the dma-names property.
+
 Example:
 spi0: spi@70a0{
compatible = "sprd,sc9860-spi";
@@ -21,6 +26,8 @@ spi0: spi@70a0{
interrupts = ;
clock-names = "spi", "source","enable";
clocks = <&clk_spi0>, <&ext_26m>, <&clk_ap_apb_gates 5>;
+   dma-names = "rx_chn", "tx_chn";
+   dmas = <&apdma 11 11>, <&apdma 12 12>;
#address-cells = <1>;
#size-cells = <0>;
 };
-- 
1.7.9.5



Re: [tip:x86/boot] x86/boot: Early parse RSDP and save it in boot_params

2019-02-12 Thread Boris Petkov
On February 13, 2019 2:54:29 AM GMT+01:00, Chao Fan  
wrote:
>Yes, your PATCH really works well. I tried both efi32 OVMF and efi64
>OVMF, all boot.

What about the real hardware you are normally testing on? Boots there too?

Thx.

-- 
Sent from a small device: formatting sux and brevity is inevitable.


Re: [PATCH] slub: untag object before slab end

2019-02-12 Thread Pekka Enberg




On 13/02/2019 4.05, Qian Cai wrote:

get_freepointer() could return NULL if there is no more free objects in
the slab. However, it could return a tagged pointer (like
0x2200) with KASAN_SW_TAGS which would escape the NULL
object checking in check_valid_pointer() and trigger errors below, so
untag the object before checking for a NULL object there.


Reviewed-by: Pekka Enberg 


Re: [PATCH 12/13] input: max77650: add onkey support

2019-02-12 Thread Dmitry Torokhov
Hi Lee,

On Tue, Feb 12, 2019 at 12:34 PM Lee Jones  wrote:
>
> > > From: Bartosz Golaszewski 
> > >
> > > Add support for the push- and slide-button events for max77650.
> > >
> > > Signed-off-by: Bartosz Golaszewski 
> > > ---
> > >  drivers/input/misc/Kconfig  |   9 ++
> > >  drivers/input/misc/Makefile |   1 +
> > >  drivers/input/misc/max77650-onkey.c | 135 
> > >  3 files changed, 145 insertions(+)
> > >  create mode 100644 drivers/input/misc/max77650-onkey.c
>
> [...]
>
> Moving things around a bit:
>
> > > +static int max77650_onkey_probe(struct platform_device *pdev)
> > > +{
>
> > > +   irq_f = regmap_irq_get_virq(irq_data, MAX77650_INT_nEN_F);
> > > +   if (irq_f <= 0)
> > > +   return -EINVAL;
> > > +
> > > +   irq_r = regmap_irq_get_virq(irq_data, MAX77650_INT_nEN_R);
> > > +   if (irq_r <= 0)
> > > +   return -EINVAL;
> >
> > Ugh, it would be better if you handled IRQ mapping in the MFD piece and
> > passed it as resources of platform device. Then you'd simply call
> > platform_get_irq() here and did not have to reach into parent device for
> > "irq_dara".
>
> These device IRQs were defined and registered with the Regmap *set*
> (actually init()) APIs and thus should be pulled out using the
> appropriate reverse Regmap *get* APIs here in the device.
>
> Registering them with Regmap *and* pulling them back out again in the
> same (MFD in this case) driver, only to register them as platform data
> is certainly not how I see the API being designed/used.
>
> > > +   struct regmap_irq_chip_data *irq_data;
> > > +   struct device *dev, *parent;
>
> > > +   dev = &pdev->dev;
> > > +   parent = dev->parent;
> > > +   i2c = to_i2c_client(parent);
> > > +   irq_data = i2c_get_clientdata(i2c);
> > > +
> > > +   map = dev_get_regmap(parent, NULL);
> > > +   if (!map)
> > > +   return -ENODEV;
>
> However, this hoop jumping is a bit crazy and for the most part
> superfluous.  Instead, create a struct of attributes you wish to share
> with the child devices (containing both regmap (which you should call
> regmap and not map by the way) and irq_data) and pass it as either
> platform data (preferred) or as device data.
>
> If you choose the latter, you do not need to convert from 'device' to
> 'i2c' to do the look-up.  Since this function (probe()) is provided
> with a platform_device, you can just use platform_get_drvdata() to
> achieve the same as above.
>
> If you go the preferred (platform data) route, then you should use
> dev_get_platdata() instead.

By doing what you are suggesting (introducing platform data) you
introducing strong dependency between MFD and input piece for no
different reason. With the current implementation the parent can be
reworked completely without involving onkey driver.

I find such clean separation desirable. We are trying to move away
form platform data where it makes sense.

Thanks.

-- 
Dmitry


Re: [PATCH 01/12] mfd/sm501: depend on HAS_DMA

2019-02-12 Thread Lee Jones
On Mon, 11 Feb 2019, Christoph Hellwig wrote:

> Currently the sm501 mfd driver can be compiled without any dependencies,
> but through the use of dma_declare_coherent it really depends on
> having DMA and iomem support.  Normally we don't explicitly require DMA
> support as we have stubs for it if on UML, but in this case the driver
> selects support for dma_declare_coherent and thus also requires
> memmap support.  Guard this by an explicit dependency.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  drivers/mfd/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index f461460a2aeb..f15f6489803d 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1066,6 +1066,7 @@ config MFD_SI476X_CORE
>  
>  config MFD_SM501
>   tristate "Silicon Motion SM501"
> + depends on HAS_DMA
>---help---
> This is the core driver for the Silicon Motion SM501 multimedia
> companion chip. This device is a multifunction device which may

I would normally have taken this, but I fear it will conflict with
[PATCH 06/12].  For that reason, just take my:

  Acked-by: Lee Jones 

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog


Re: [PATCH 06/12] dma-mapping: improve selection of dma_declare_coherent availability

2019-02-12 Thread Lee Jones
On Mon, 11 Feb 2019, Christoph Hellwig wrote:

> This API is primarily used through DT entries, but two architectures
> and two drivers call it directly.  So instead of selecting the config
> symbol for random architectures pull it in implicitly for the actual
> users.  Also rename the Kconfig option to describe the feature better.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  arch/arc/Kconfig| 1 -
>  arch/arm/Kconfig| 2 +-
>  arch/arm64/Kconfig  | 1 -
>  arch/csky/Kconfig   | 1 -
>  arch/mips/Kconfig   | 1 -
>  arch/riscv/Kconfig  | 1 -
>  arch/sh/Kconfig | 2 +-
>  arch/unicore32/Kconfig  | 1 -
>  arch/x86/Kconfig| 1 -

>  drivers/mfd/Kconfig | 2 ++

If everyone else is happy with these changes, then so am I.

  Acked-by: Lee Jones 

>  drivers/of/Kconfig  | 3 ++-
>  include/linux/device.h  | 2 +-
>  include/linux/dma-mapping.h | 8 
>  kernel/dma/Kconfig  | 2 +-
>  kernel/dma/Makefile | 2 +-
>  15 files changed, 13 insertions(+), 17 deletions(-)

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog


Re: [PATCH] mmc: mmc: Fix HS setting in mmc_hs400_to_hs200()

2019-02-12 Thread Ulf Hansson
On Wed, 13 Feb 2019 at 04:13, Chaotian Jing  wrote:
>
> On Wed, 2019-02-13 at 08:54 +0800, Chaotian Jing wrote:
> > On Tue, 2019-02-12 at 10:04 +0200, Adrian Hunter wrote:
> > > On 12/02/19 4:04 AM, Chaotian Jing wrote:
> > > > On Tue, 2019-02-05 at 15:42 +0200, Adrian Hunter wrote:
> > > >> On 5/02/19 3:06 PM, Ulf Hansson wrote:
> > > >>> On Mon, 4 Feb 2019 at 14:42, Adrian Hunter  
> > > >>> wrote:
> > > 
> > >  On 4/02/19 12:54 PM, Ulf Hansson wrote:
> > > > On Mon, 4 Feb 2019 at 10:58, Adrian Hunter 
> > > >  wrote:
> > > >>
> > > >> On 1/02/19 10:10 AM, Ulf Hansson wrote:
> > > >>> On Fri, 1 Feb 2019 at 02:38, Chaotian Jing 
> > > >>>  wrote:
> > > 
> > >  On Thu, 2019-01-31 at 16:58 +0100, Ulf Hansson wrote:
> > > > On Thu, 31 Jan 2019 at 08:53, Chaotian Jing 
> > > >  wrote:
> > > >>
> > > >> mmc_hs400_to_hs200() begins with the card and host in HS400 
> > > >> mode.
> > > >> Therefore, any commands sent to the card should use HS400 
> > > >> timing.
> > > >> It is incorrect to reduce frequency to 50Mhz before sending 
> > > >> the switch
> > > >> command, in this case, only reduce clock frequency to 50Mhz 
> > > >> but without
> > > >> host timming change, host is still in hs400 mode but clock 
> > > >> changed from
> > > >> 200Mhz to 50Mhz, which makes the tuning result unsuitable and 
> > > >> cause
> > > >> the switch command gets response CRC error.
> > > >
> > > > According the eMMC spec there is no violation by decreasing the 
> > > > clock
> > > > frequency like this. We can use whatever value <=200MHz.
> > > >
> > > > However, perhaps in practice this becomes an issue, due to the 
> > > > tuning
> > > > for HS400 has been done on the "current" frequency.
> > > >
> > > > As as start, I think you need to clarify this in the changelog.
> > > >
> > >  Yes, reduce clock frequency to 50Mhz is no Spec violation, but 
> > >  it may
> > >  cause __mmc_switch() gets response CRC error, decreasing the 
> > >  clock but
> > >  without HOST mode change, on the host side, host driver do not 
> > >  know
> > >  what's operation the core layer want to do and can only set 
> > >  current bus
> > >  clock to 50Mhz, without tuning parameter change, it has a chance 
> > >  lead to
> > >  response CRC error. even lower clock frequency, but with the 
> > >  wrong
> > >  tuning parameter setting(the setting is of hs400 tuning @200Mhz).
> > > >>>
> > > >>> Right, makes sense.
> > > >>>
> > > >>
> > > >> this patch refers to mmc_select_hs400(), make the reduce clock 
> > > >> frequency
> > > >> after card timing change.
> > > >>
> > > >> Signed-off-by: Chaotian Jing 
> > > >> ---
> > > >>  drivers/mmc/core/mmc.c | 8 
> > > >>  1 file changed, 4 insertions(+), 4 deletions(-)
> > > >>
> > > >> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> > > >> index da892a5..21b811e 100644
> > > >> --- a/drivers/mmc/core/mmc.c
> > > >> +++ b/drivers/mmc/core/mmc.c
> > > >> @@ -1239,10 +1239,6 @@ int mmc_hs400_to_hs200(struct mmc_card 
> > > >> *card)
> > > >> int err;
> > > >> u8 val;
> > > >>
> > > >> -   /* Reduce frequency to HS */
> > > >> -   max_dtr = card->ext_csd.hs_max_dtr;
> > > >> -   mmc_set_clock(host, max_dtr);
> > > >> -
> > > >
> > > > As far as I can tell, the reason to why we change the clock 
> > > > frequency
> > > > *before* the call to __mmc_switch() below, is probably to try 
> > > > to be on
> > > > the safe side and conform to the spec.
> > > >
> > >  Agree, it Must be more safe with lower clock frequency, but the
> > >  precondition is to make the host side recognize current timing 
> > >  is not
> > >  HS400 mode. it has no method to find a safe setting to ensure no
> > >  response CRC error when reduce clock from 200Mhz to 50Mhz.
> > > > However, I think you have a point, as the call to 
> > > > __mmc_switch(),
> > > > passes the "send_status" parameter as false, no other command 
> > > > than the
> > > > CMD6 is sent to the card.
> > > >
> > >  yes, the send status command was sent only after __mmc_switch() 
> > >  done.
> > > >> /* Switch HS400 to HS DDR */
> > > >> val = EXT_CSD_TIMING_HS;
> > > >> err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 
> > > >> EXT_CSD_HS_TIMING,
> > > >>>

Re: [PATCH v2] mfd: sec: Add support for the RTC on S2MPA01

2019-02-12 Thread Lee Jones
Good morning Stuart,

It's been a while.  I hope all is well with you.

> The RTC portion of the S2MPA01 appears to have the same
> register layout as the S2MPS14.
> 
> Signed-off-by: Stuart Menefy 
> ---
>  drivers/mfd/sec-core.c | 2 ++
>  drivers/mfd/sec-irq.c  | 3 +++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
> index e0835c9df7a1..08621ef5d822 100644
> --- a/drivers/mfd/sec-core.c
> +++ b/drivers/mfd/sec-core.c
> @@ -103,6 +103,8 @@ static const struct mfd_cell s2mps15_devs[] = {
>  static const struct mfd_cell s2mpa01_devs[] = {
>   {
>   .name = "s2mpa01-pmic",
> + }, {
> + .name = "s2mps14-rtc",
>   },
>  };

Ideally one line entries should be on one line (see: s2mps13_devs).

Would you like to take a couple of minutes to make those changes
file-wide and rework this patch on top of it please?

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog


Re: [LSF/MM TOPIC] FS, MM, and stable trees

2019-02-12 Thread Amir Goldstein
On Tue, Feb 12, 2019 at 11:56 PM Steve French  wrote:
>
> Makes sense - e.g. I would like to have a process to make automation
> of the xfstests for proposed patches for stable for cifs.ko easier and
> part of the process (as we already do for cifs/smb3 related checkins
> to for-next ie linux next before sending to mainline for cifs.ko).
> Each filesystem has a different set of xfstests (and perhaps other
> mechanisms) to run so might be very specific to each file system, but
> would be helpful to discuss
>

Agreed.

Perhaps it is just a matter of communicating the stable tree workflow.
I currently only see notice emails from Greg about patches being queued
for stable.

I never saw an email from you or Greg saying, the branch "stable-xxx" is
in review. Please run your tests.

I have seen reports from LTP about stable kernels, so I know it is
being run regularly and I recently saw the set of xfstests configurations
that Sasha and Luis posted.

Is there any publicly available information about which tests are being run
on stable candidate branches?

Thanks,
Amir.


Re: [PATCH v1] clk: qcom: lpass: Add CLK_IGNORE_UNUSED for lpass clocks

2019-02-12 Thread Bjorn Andersson
On Thu 20 Dec 03:46 PST 2018, Taniya Das wrote:

> The LPASS clocks has a dependency on the GCC lpass clocks to be enabled
> before accessing them and that was the reason to mark the gcc lpass clocks
> as critical.

I have the same problem with the TuringCC in QCS404, that in order to
disable the unused clocks GCC_CDSP_CFG_AHB_CLK must be on. But rather
than marking either side as critical or ignore-unused I think a better
solution is to describe this dependency by using the fact that the clock
framework wraps any accesses in pm_runtime_get()/put() calls. So we can
use this to link the clock controller to some resources that needs to be
turned on whenever we communicate with it.

> But in the case where the lpass subsystem would require a
> restart, toggling the lpass reset would from HW clear the SW enable bits
> of the GCC lpass clocks. Thus the next time bringing up the lpass subsystem
> out of reset would fail.

Are you saying that when we toggle AOSS_CC_LPASS_RESTART the enable bit
is cleared on all these clocks and we might get out of sync between the
clock framework and the hardware?

Can you please elaborate a little bit on this? Afaict in the remoteproc
driver at least, we first disable the clock then we issue the reset.

Regards,
Bjorn

> 
> Allow the lpass clock driver to enable/disable the gcc lpass clocks and
> mark the lpass clocks not be accessed during late_init if no client vote.
> 
> Signed-off-by: Taniya Das 
> ---
>  drivers/clk/qcom/gcc-sdm845.c | 2 --
>  drivers/clk/qcom/lpasscc-sdm845.c | 5 +
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/qcom/gcc-sdm845.c b/drivers/clk/qcom/gcc-sdm845.c
> index c782e62..8365c97 100644
> --- a/drivers/clk/qcom/gcc-sdm845.c
> +++ b/drivers/clk/qcom/gcc-sdm845.c
> @@ -3163,7 +3163,6 @@ enum {
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "gcc_lpass_q6_axi_clk",
> - .flags = CLK_IS_CRITICAL,
>   .ops = &clk_branch2_ops,
>   },
>   },
> @@ -3177,7 +3176,6 @@ enum {
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "gcc_lpass_sway_clk",
> - .flags = CLK_IS_CRITICAL,
>   .ops = &clk_branch2_ops,
>   },
>   },
> diff --git a/drivers/clk/qcom/lpasscc-sdm845.c 
> b/drivers/clk/qcom/lpasscc-sdm845.c
> index e246b99..1acc741 100644
> --- a/drivers/clk/qcom/lpasscc-sdm845.c
> +++ b/drivers/clk/qcom/lpasscc-sdm845.c
> @@ -22,6 +22,7 @@
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "lpass_q6ss_ahbm_aon_clk",
> + .flags = CLK_IGNORE_UNUSED,
>   .ops = &clk_branch2_ops,
>   },
>   },
> @@ -35,6 +36,7 @@
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "lpass_q6ss_ahbs_aon_clk",
> + .flags = CLK_IGNORE_UNUSED,
>   .ops = &clk_branch2_ops,
>   },
>   },
> @@ -49,6 +51,7 @@
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "lpass_qdsp6ss_core_clk",
> + .flags = CLK_IGNORE_UNUSED,
>   .ops = &clk_branch2_ops,
>   },
>   },
> @@ -63,6 +66,7 @@
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "lpass_qdsp6ss_xo_clk",
> + .flags = CLK_IGNORE_UNUSED,
>   .ops = &clk_branch2_ops,
>   },
>   },
> @@ -77,6 +81,7 @@
>   .enable_mask = BIT(0),
>   .hw.init = &(struct clk_init_data){
>   .name = "lpass_qdsp6ss_sleep_clk",
> + .flags = CLK_IGNORE_UNUSED,
>   .ops = &clk_branch2_ops,
>   },
>   },
> --
> Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member
> of the Code Aurora Forum, hosted by the  Linux Foundation.
> 


Re: [PATCH -tip v3 05/10] kprobes: Search non-suffixed symbol in blacklist

2019-02-12 Thread Ingo Molnar


* Ingo Molnar  wrote:

> 
> * Masami Hiramatsu  wrote:
> 
> > Newer gcc can generate some different instances of a function
> > with suffixed symbols if the function is optimized and only
> > has a part of that. (e.g. .constprop, .part etc.)
> > 
> > In this case, it is not enough to check the entry of kprobe
> > blacklist because it only records non-suffixed symbol address.
> > 
> > To fix this issue, search non-suffixed symbol in blacklist if
> > given address is within a symbol which has a suffix.
> > 
> > Note that this can cause false positive cases if a kprobe-safe
> > function is optimized to suffixed instance and has same name
> > symbol which is blacklisted.
> > But I would like to chose a fail-safe design for this issue.
> > 
> > Signed-off-by: Masami Hiramatsu 
> 
> Why did you not add Steven's Reviewed-by tag?

The series looks fine otherwise, so I applied it with Steve's reviewed-by 
tag added.

Thanks,

Ingo


Re: [PATCH] printk: add KERN_NOTIME to skip the timestamp

2019-02-12 Thread xiang xiao
But how can I precisely control timestamp on/off per message through sysfs node?

On Wed, Feb 13, 2019 at 2:38 PM Sergey Senozhatsky
 wrote:
>
> On (02/13/19 15:29), Sergey Senozhatsky wrote:
> >
> > cat /sys/module/printk/parameters/time ?
>  ^
> cat / echo
>
> Works both ways.
>
> -ss


Re: [PATCH -tip v3 05/10] kprobes: Search non-suffixed symbol in blacklist

2019-02-12 Thread Ingo Molnar


* Masami Hiramatsu  wrote:

> Newer gcc can generate some different instances of a function
> with suffixed symbols if the function is optimized and only
> has a part of that. (e.g. .constprop, .part etc.)
> 
> In this case, it is not enough to check the entry of kprobe
> blacklist because it only records non-suffixed symbol address.
> 
> To fix this issue, search non-suffixed symbol in blacklist if
> given address is within a symbol which has a suffix.
> 
> Note that this can cause false positive cases if a kprobe-safe
> function is optimized to suffixed instance and has same name
> symbol which is blacklisted.
> But I would like to chose a fail-safe design for this issue.
> 
> Signed-off-by: Masami Hiramatsu 

Why did you not add Steven's Reviewed-by tag?

Thanks,

Ingo


[PATCH] arm/mach-socfpga/pm: fix possible object reference leak

2019-02-12 Thread Peng Hao
of_find_device_by_node() takes a reference to the struct device
when it finds a match via get_device. When returning error we should
call put_device.

Signed-off-by: Peng Hao 
---
 arch/arm/mach-socfpga/pm.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-socfpga/pm.c b/arch/arm/mach-socfpga/pm.c
index d486678..b782294 100644
--- a/arch/arm/mach-socfpga/pm.c
+++ b/arch/arm/mach-socfpga/pm.c
@@ -60,14 +60,14 @@ static int socfpga_setup_ocram_self_refresh(void)
if (!ocram_pool) {
pr_warn("%s: ocram pool unavailable!\n", __func__);
ret = -ENODEV;
-   goto put_node;
+   goto put_device;
}
 
ocram_base = gen_pool_alloc(ocram_pool, socfpga_sdram_self_refresh_sz);
if (!ocram_base) {
pr_warn("%s: unable to alloc ocram!\n", __func__);
ret = -ENOMEM;
-   goto put_node;
+   goto put_device;
}
 
ocram_pbase = gen_pool_virt_to_phys(ocram_pool, ocram_base);
@@ -78,7 +78,7 @@ static int socfpga_setup_ocram_self_refresh(void)
if (!suspend_ocram_base) {
pr_warn("%s: __arm_ioremap_exec failed!\n", __func__);
ret = -ENOMEM;
-   goto put_node;
+   goto put_device;
}
 
/* Copy the code that puts DDR in self refresh to ocram */
@@ -92,6 +92,8 @@ static int socfpga_setup_ocram_self_refresh(void)
if (!socfpga_sdram_self_refresh_in_ocram)
ret = -EFAULT;
 
+put_device:
+   put_device(&pdev->dev);
 put_node:
of_node_put(np);
 
-- 
1.8.3.1



[PATCH] arm/mach-omap2/display: fix possible object reference leak

2019-02-12 Thread Peng Hao
of_find_device_by_node() takes a reference to the struct device
when it finds a match via get_device.When returning error we should
call put_device.

Signed-off-by: Peng Hao 
---
 arch/arm/mach-omap2/display.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-omap2/display.c b/arch/arm/mach-omap2/display.c
index f86b72d..c6aa9ed 100644
--- a/arch/arm/mach-omap2/display.c
+++ b/arch/arm/mach-omap2/display.c
@@ -258,6 +258,7 @@ static int __init omapdss_init_of(void)
r = of_platform_populate(node, NULL, NULL, &pdev->dev);
if (r) {
pr_err("Unable to populate DSS submodule devices\n");
+   put_device(&pdev->dev);
return r;
}
 
-- 
1.8.3.1



Re: [PATCH 3/4] clk: samsung: exynos5410: Add gate clock for ADC

2019-02-12 Thread Chanwoo Choi
Hi,

On 19. 2. 13. 오전 2:50, Krzysztof Kozlowski wrote:
> Add the gate clock for ADC block on Exynos5410.
> 
> Signed-off-by: Krzysztof Kozlowski 
> ---
>  drivers/clk/samsung/clk-exynos5410.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/clk/samsung/clk-exynos5410.c 
> b/drivers/clk/samsung/clk-exynos5410.c
> index 0a0b09591e6f..b2da2c8fa0c7 100644
> --- a/drivers/clk/samsung/clk-exynos5410.c
> +++ b/drivers/clk/samsung/clk-exynos5410.c
> @@ -209,6 +209,7 @@ static const struct samsung_gate_clock 
> exynos5410_gate_clks[] __initconst = {
>   GATE(CLK_USI1, "usi1", "aclk66", GATE_IP_PERIC, 11, 0, 0),
>   GATE(CLK_USI2, "usi2", "aclk66", GATE_IP_PERIC, 12, 0, 0),
>   GATE(CLK_USI3, "usi3", "aclk66", GATE_IP_PERIC, 13, 0, 0),
> + GATE(CLK_TSADC, "tsadc", "aclk66", GATE_IP_PERIC, 15, 0, 0),
>   GATE(CLK_PWM, "pwm", "aclk66", GATE_IP_PERIC, 24, 0, 0),
>  
>   GATE(CLK_SCLK_UART0, "sclk_uart0", "div_uart0",
> 

I checked it on Exynos5410 TRM. Looks good to me.
Acked-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [PATCH 3/3] cpufreq: imx-sc: add i.mx system controller cpufreq support

2019-02-12 Thread Viresh Kumar
On 13-02-19, 03:09, Anson Huang wrote:
> On NXP's i.MX SoCs with system controller inside, CPU frequency
> scaling can ONLY be done by system controller firmware, and it
> can ONLY be requested from secure mode, so Linux cpufreq driver has
> to call ARM SMC to trap to ARM-Trusted-Firmware to request system
> controller firmware to do CPU frequency scaling.
> 
> This patch adds i.MX system controller cpufreq driver support,
> when doing CPU frequency scaling, cpufreq driver will do ARM SMC
> call and trap to ARM-Trusted-Firmware, then SIP(silicon provider)
> service will communicate with system controller for CPU frequenct
> scaling.
> 
> Signed-off-by: Anson Huang 
> ---
>  drivers/cpufreq/Kconfig.arm  |   9 ++
>  drivers/cpufreq/Makefile |   1 +
>  drivers/cpufreq/imx-sc-cpufreq.c | 183 
> +++
>  3 files changed, 193 insertions(+)
>  create mode 100644 drivers/cpufreq/imx-sc-cpufreq.c

Why can't you use cpufreq-dt driver like everyone else ?

-- 
viresh


Re: [PATCH 2/4] dt-bindings: clock: exynos: Add ADC clock ID to Exynos5410

2019-02-12 Thread Chanwoo Choi
Hi,

On 19. 2. 13. 오전 2:50, Krzysztof Kozlowski wrote:
> Add ID for TSADC clock to Exynos5410.  Choose the same value of ID as in
> Exynos5420 to make it simpler/compatible in future (although clock
> driver code is not shared).
> 
> Signed-off-by: Krzysztof Kozlowski 
> ---
>  include/dt-bindings/clock/exynos5410.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/dt-bindings/clock/exynos5410.h 
> b/include/dt-bindings/clock/exynos5410.h
> index 5b911ede0534..86c2ad56c5ef 100644
> --- a/include/dt-bindings/clock/exynos5410.h
> +++ b/include/dt-bindings/clock/exynos5410.h
> @@ -45,6 +45,7 @@
>  #define CLK_USI1 266
>  #define CLK_USI2 267
>  #define CLK_USI3 268
> +#define CLK_TSADC270
>  #define CLK_PWM  279
>  #define CLK_MCT  315
>  #define CLK_WDT  316
> 

Acked-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


[GIT PULL V3] csky fixes for v5.0-rc6

2019-02-12 Thread guoren
Hi Linus,

This is third version of pull-request from csky, we removed all patches of 
drivers.

Best Regards
 Guo Ren

The following changes since commit d13937116f1e82bf508a6325111b322c30c85eb9:

  Linux 5.0-rc6 (2019-02-10 14:42:20 -0800)

are available in the git repository at:

  g...@github.com:c-sky/csky-linux.git tags/csky-for-linus-5.0-rc6

for you to fetch changes up to 131aee8b9807bc98379fa5a0270389dbc7dcec90:

  csky: Fixup dead loop in show_stack (2019-02-13 09:48:14 +0800)


arch/csky patches for 5.0-rc6

Here is some fixup patches for 5.0-rc6:

Guo Ren (5):
  csky: Fixup _PAGE_GLOBAL bit for 610 tlb entry
  csky: Fixup wrong pt_regs size
  csky: coding convention: Use task_stack_page
  csky: Fixup io-range page attribute for mmap("/dev/mem")
  csky: Fixup dead loop in show_stack


Guo Ren (5):
  csky: Fixup _PAGE_GLOBAL bit for 610 tlb entry
  csky: Fixup wrong pt_regs size
  csky: coding convention: Use task_stack_page
  csky: Fixup io-range page attribute for mmap("/dev/mem")
  csky: Fixup dead loop in show_stack

 arch/csky/include/asm/pgtable.h   |  9 +++--
 arch/csky/include/asm/processor.h |  4 ++--
 arch/csky/kernel/dumpstack.c  |  4 
 arch/csky/kernel/ptrace.c |  3 ++-
 arch/csky/kernel/smp.c|  3 ++-
 arch/csky/mm/ioremap.c| 14 ++
 6 files changed, 31 insertions(+), 6 deletions(-)


[PATCH 2/2] arm64: dts: allwinner: a64: Rename hpvcc-supply to cpvdd-supply

2019-02-12 Thread Chen-Yu Tsai
The A64 datasheet lists the supply rail for the headphone amp's charge
pump as "CPVDD". cpvdd-supply is the name of the property for this power
rail specified in the device tree bindings. "HPVCC" was the name used in
the A33 datasheet for the same function.

Rename the supply so it matches the datasheet and bindings.

Fixes: c56689e6f2fb ("arm64: dts: allwinner: a64: bananapi-m64: Enable audio 
codec")
Fixes: 6de8e717848f ("arm64: dts: allwinner: a64: enable sound on Pinebook")
Fixes: 498c21f233ed ("arm64: dts: allwinner: a64: enable sound on Pine64 and 
SoPine")
Signed-off-by: Chen-Yu Tsai 
---
 arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts | 2 +-
 arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts   | 2 +-
 arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts | 2 +-
 arch/arm64/boot/dts/allwinner/sun50i-a64-sopine.dtsi  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
index 7793ebb5d2b8..0a56c0c23ba1 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts
@@ -104,7 +104,7 @@
 };
 
 &codec_analog {
-   hpvcc-supply = <®_eldo1>;
+   cpvdd-supply = <®_eldo1>;
status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts
index c0b9cc7a6b3a..b7ac6374b178 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts
@@ -80,7 +80,7 @@
 };
 
 &codec_analog {
-   hpvcc-supply = <®_eldo1>;
+   cpvdd-supply = <®_eldo1>;
status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts
index d22736a62481..78c82a665c84 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts
@@ -94,7 +94,7 @@
 };
 
 &codec_analog {
-   hpvcc-supply = <®_eldo1>;
+   cpvdd-supply = <®_eldo1>;
status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-sopine.dtsi 
b/arch/arm64/boot/dts/allwinner/sun50i-a64-sopine.dtsi
index d2651f284aa0..9d20e13f0c02 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-sopine.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-sopine.dtsi
@@ -48,7 +48,7 @@
 #include 
 
 &codec_analog {
-   hpvcc-supply = <®_eldo1>;
+   cpvdd-supply = <®_eldo1>;
 };
 
 &mmc0 {
-- 
2.20.1



[PATCH 0/2] arm64: allwinner: a64: Rename hpvcc-supply to cpvdd-supply

2019-02-12 Thread Chen-Yu Tsai
Hi everyone,

This is a small series to fix the CPVDD regulator supply name for the
A64 codec. The datasheet specifies the name "CPVDD" for the supply rail
for the audio codec's internal headphone amp charge pump.

Somehow I managed to write "CPVDD" in the commit message and the device
tree binding, but used "HPVCC" (which is the name used by the A33) in
the device tree files and the device driver. (facepalm)

This feature was just introduced in v5.0-rc1, so if we could merge this
as fixes for v5.0 that would be great.

Thanks, and sorry for the blunder on my part.


Regards
ChenYu


Chen-Yu Tsai (2):
  ASoC: sunxi: sun50i-codec-analog: Rename hpvcc regulator supply to
cpvdd
  arm64: dts: allwinner: a64: Rename hpvcc-supply to cpvdd-supply

 arch/arm64/boot/dts/allwinner/sun50i-a64-bananapi-m64.dts | 2 +-
 arch/arm64/boot/dts/allwinner/sun50i-a64-pine64.dts   | 2 +-
 arch/arm64/boot/dts/allwinner/sun50i-a64-pinebook.dts | 2 +-
 arch/arm64/boot/dts/allwinner/sun50i-a64-sopine.dtsi  | 2 +-
 sound/soc/sunxi/sun50i-codec-analog.c | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.20.1



[PATCH 03/32] powerpc/dma: untangle vio_dma_mapping_ops from dma_iommu_ops

2019-02-12 Thread Christoph Hellwig
vio_dma_mapping_ops currently does a lot of indirect calls through
dma_iommu_ops, which not only make the code harder to follow but are
also expensive in the post-spectre world.  Unwind the indirect calls
by calling the ppc_iommu_* or iommu_* APIs directly applicable, or
just use the dma_iommu_* methods directly where we can.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/include/asm/iommu.h |  1 +
 arch/powerpc/kernel/dma-iommu.c  |  2 +-
 arch/powerpc/platforms/pseries/vio.c | 87 
 3 files changed, 38 insertions(+), 52 deletions(-)

diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index 17524d222a7b..bd069a6542ab 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -237,6 +237,7 @@ static inline void iommu_del_device(struct device *dev)
 }
 #endif /* !CONFIG_IOMMU_API */
 
+u64 dma_iommu_get_required_mask(struct device *dev);
 #else
 
 static inline void *get_iommu_table_base(struct device *dev)
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index 9c9bcaae2f75..dd8601cd20df 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -92,7 +92,7 @@ int dma_iommu_dma_supported(struct device *dev, u64 mask)
return 1;
 }
 
-static u64 dma_iommu_get_required_mask(struct device *dev)
+u64 dma_iommu_get_required_mask(struct device *dev)
 {
struct iommu_table *tbl = get_iommu_table_base(dev);
u64 mask;
diff --git a/arch/powerpc/platforms/pseries/vio.c 
b/arch/powerpc/platforms/pseries/vio.c
index 1fad4649735b..7870bf99168c 100644
--- a/arch/powerpc/platforms/pseries/vio.c
+++ b/arch/powerpc/platforms/pseries/vio.c
@@ -492,7 +492,9 @@ static void *vio_dma_iommu_alloc_coherent(struct device 
*dev, size_t size,
return NULL;
}
 
-   ret = dma_iommu_ops.alloc(dev, size, dma_handle, flag, attrs);
+   ret = iommu_alloc_coherent(dev, get_iommu_table_base(dev), size,
+   dma_handle, dev->coherent_dma_mask, flag,
+   dev_to_node(dev));
if (unlikely(ret == NULL)) {
vio_cmo_dealloc(viodev, roundup(size, PAGE_SIZE));
atomic_inc(&viodev->cmo.allocs_failed);
@@ -507,8 +509,7 @@ static void vio_dma_iommu_free_coherent(struct device *dev, 
size_t size,
 {
struct vio_dev *viodev = to_vio_dev(dev);
 
-   dma_iommu_ops.free(dev, size, vaddr, dma_handle, attrs);
-
+   iommu_free_coherent(get_iommu_table_base(dev), size, vaddr, dma_handle);
vio_cmo_dealloc(viodev, roundup(size, PAGE_SIZE));
 }
 
@@ -518,22 +519,22 @@ static dma_addr_t vio_dma_iommu_map_page(struct device 
*dev, struct page *page,
  unsigned long attrs)
 {
struct vio_dev *viodev = to_vio_dev(dev);
-   struct iommu_table *tbl;
+   struct iommu_table *tbl = get_iommu_table_base(dev);
dma_addr_t ret = DMA_MAPPING_ERROR;
 
-   tbl = get_iommu_table_base(dev);
-   if (vio_cmo_alloc(viodev, roundup(size, IOMMU_PAGE_SIZE(tbl {
-   atomic_inc(&viodev->cmo.allocs_failed);
-   return ret;
-   }
-
-   ret = dma_iommu_ops.map_page(dev, page, offset, size, direction, attrs);
-   if (unlikely(dma_mapping_error(dev, ret))) {
-   vio_cmo_dealloc(viodev, roundup(size, IOMMU_PAGE_SIZE(tbl)));
-   atomic_inc(&viodev->cmo.allocs_failed);
-   }
-
+   if (vio_cmo_alloc(viodev, roundup(size, IOMMU_PAGE_SIZE(tbl
+   goto out_fail;
+   ret = iommu_map_page(dev, tbl, page, offset, size, device_to_mask(dev),
+   direction, attrs);
+   if (unlikely(ret == DMA_MAPPING_ERROR))
+   goto out_deallocate;
return ret;
+
+out_deallocate:
+   vio_cmo_dealloc(viodev, roundup(size, IOMMU_PAGE_SIZE(tbl)));
+out_fail:
+   atomic_inc(&viodev->cmo.allocs_failed);
+   return DMA_MAPPING_ERROR;
 }
 
 static void vio_dma_iommu_unmap_page(struct device *dev, dma_addr_t dma_handle,
@@ -542,11 +543,9 @@ static void vio_dma_iommu_unmap_page(struct device *dev, 
dma_addr_t dma_handle,
 unsigned long attrs)
 {
struct vio_dev *viodev = to_vio_dev(dev);
-   struct iommu_table *tbl;
-
-   tbl = get_iommu_table_base(dev);
-   dma_iommu_ops.unmap_page(dev, dma_handle, size, direction, attrs);
+   struct iommu_table *tbl = get_iommu_table_base(dev);
 
+   iommu_unmap_page(tbl, dma_handle, size, direction, attrs);
vio_cmo_dealloc(viodev, roundup(size, IOMMU_PAGE_SIZE(tbl)));
 }
 
@@ -555,34 +554,32 @@ static int vio_dma_iommu_map_sg(struct device *dev, 
struct scatterlist *sglist,
 unsigned long attrs)
 {
struct vio_dev *viodev = to_vio_dev(dev);
-   struct iommu_table *tbl;
+   struct iommu_table *tbl = get_iommu_table_base(dev);
s

[PATCH 1/2] ASoC: sunxi: sun50i-codec-analog: Rename hpvcc regulator supply to cpvdd

2019-02-12 Thread Chen-Yu Tsai
The A64 datasheet lists the supply rail for the headphone amp's charge
pump as "CPVDD". cpvdd-supply is the name of the property for this power
rail specified in the device tree bindings. "HPVCC" was the name used in
the A33 datasheet for the same function.

Rename the supply so it matches the datasheet, bindings, and the subject
from the original commit.

Fixes: ca0412a05756 ("ASoC: sunxi: sun50i-codec-analog: Add support for cpvdd 
regulator supply")
Signed-off-by: Chen-Yu Tsai 
---
 sound/soc/sunxi/sun50i-codec-analog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sunxi/sun50i-codec-analog.c 
b/sound/soc/sunxi/sun50i-codec-analog.c
index df1fed0aa001..d105c90c3706 100644
--- a/sound/soc/sunxi/sun50i-codec-analog.c
+++ b/sound/soc/sunxi/sun50i-codec-analog.c
@@ -274,7 +274,7 @@ static const struct snd_soc_dapm_widget 
sun50i_a64_codec_widgets[] = {
 * stream widgets at the card level.
 */
 
-   SND_SOC_DAPM_REGULATOR_SUPPLY("hpvcc", 0, 0),
+   SND_SOC_DAPM_REGULATOR_SUPPLY("cpvdd", 0, 0),
SND_SOC_DAPM_MUX("Headphone Source Playback Route",
 SND_SOC_NOPM, 0, 0, sun50i_codec_hp_src),
SND_SOC_DAPM_OUT_DRV("Headphone Amp", SUN50I_ADDA_HP_CTRL,
@@ -362,7 +362,7 @@ static const struct snd_soc_dapm_route 
sun50i_a64_codec_routes[] = {
{ "Headphone Source Playback Route", "Mixer", "Left Mixer" },
{ "Headphone Source Playback Route", "Mixer", "Right Mixer" },
{ "Headphone Amp", NULL, "Headphone Source Playback Route" },
-   { "Headphone Amp", NULL, "hpvcc" },
+   { "Headphone Amp", NULL, "cpvdd" },
{ "HP", NULL, "Headphone Amp" },
 
/* Microphone Routes */
-- 
2.20.1



use generic DMA mapping code in powerpc V7

2019-02-12 Thread Christoph Hellwig
Hi all,

this series switches the powerpc port to use the generic swiotlb and
noncoherent dma ops, and to use more generic code for the coherent
direct mapping, as well as removing a lot of dead code.

As this series is very large and depends on the dma-mapping tree I've
also published a git tree:

git://git.infradead.org/users/hch/misc.git powerpc-dma.7

Gitweb:


http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/powerpc-dma.7

Thanks a lot to Christian Zigotzky who spent a lot of time testing
iterations on pasemi and FSL boards!


Changes since v4:
 - rebased on top of the latests powerpc/next tree
 - fix the DART IOMMU bypass selection
 - remove the return value from arch_dma_set_mask, which was done
   incorrectly and isn't actually needed.
 - add a new patch to remove swiotlb_dma_supported
 - add a new patch to set a dma mask in the pasemi ethernet driver,
   given that we now validate it
 - add a new patch to fix a ZONE_DMA32 assumption in the dma-direct
   patch
 - split up a few patches to improve bisectability
 (v5 and v6 were never posted)

Changes since v3:
 - rebase on the powerpc fixes tree
 - add a new patch to actually make the baseline amigaone config
   configure without warnings
 - only use ZONE_DMA for 64-bit embedded CPUs, on pseries an IOMMU is
   always present
 - fix compile in mem.c for one configuration
 - drop the full npu removal for now, will be resent separately
 - a few git bisection fixes

The changes since v1 are to big to list and v2 was not posted in public.

 arch/powerpc/kernel/dma.c   |  362 
 b/arch/powerpc/Kconfig  |5 
 b/arch/powerpc/include/asm/device.h |   10 
 b/arch/powerpc/include/asm/dma-direct.h |   18 -
 b/arch/powerpc/include/asm/dma-mapping.h|   92 --
 b/arch/powerpc/include/asm/iommu.h  |   17 +
 b/arch/powerpc/include/asm/machdep.h|4 
 b/arch/powerpc/include/asm/pci-bridge.h |5 
 b/arch/powerpc/include/asm/pci.h|2 
 b/arch/powerpc/include/asm/pgtable.h|1 
 b/arch/powerpc/include/asm/swiotlb.h|5 
 b/arch/powerpc/kernel/Makefile  |3 
 b/arch/powerpc/kernel/dma-iommu.c   |   75 
 b/arch/powerpc/kernel/dma-mask.c|   12 
 b/arch/powerpc/kernel/dma-swiotlb.c |   89 -
 b/arch/powerpc/kernel/pci-common.c  |   10 
 b/arch/powerpc/kernel/setup-common.c|1 
 b/arch/powerpc/mm/dma-noncoherent.c |   40 +-
 b/arch/powerpc/mm/mem.c |   22 -
 b/arch/powerpc/platforms/44x/ppc476.c   |1 
 b/arch/powerpc/platforms/44x/warp.c |2 
 b/arch/powerpc/platforms/85xx/corenet_generic.c |5 
 b/arch/powerpc/platforms/85xx/ge_imp3a.c|2 
 b/arch/powerpc/platforms/85xx/mpc8536_ds.c  |2 
 b/arch/powerpc/platforms/85xx/mpc85xx_ds.c  |4 
 b/arch/powerpc/platforms/85xx/mpc85xx_mds.c |4 
 b/arch/powerpc/platforms/85xx/p1010rdb.c|1 
 b/arch/powerpc/platforms/85xx/p1022_ds.c|2 
 b/arch/powerpc/platforms/85xx/p1022_rdk.c   |2 
 b/arch/powerpc/platforms/85xx/qemu_e500.c   |1 
 b/arch/powerpc/platforms/86xx/mpc86xx_hpcn.c|1 
 b/arch/powerpc/platforms/Kconfig.cputype|3 
 b/arch/powerpc/platforms/cell/iommu.c   |  172 +--
 b/arch/powerpc/platforms/pasemi/iommu.c |2 
 b/arch/powerpc/platforms/pasemi/setup.c |   51 ---
 b/arch/powerpc/platforms/powernv/npu-dma.c  |2 
 b/arch/powerpc/platforms/powernv/pci-ioda.c |  132 +---
 b/arch/powerpc/platforms/pseries/iommu.c|   99 +-
 b/arch/powerpc/platforms/pseries/vio.c  |   95 ++
 b/arch/powerpc/sysdev/dart_iommu.c  |   58 +--
 b/arch/powerpc/sysdev/fsl_pci.c |   25 -
 b/drivers/misc/cxl/vphb.c   |3 
 b/drivers/net/ethernet/pasemi/pasemi_mac.c  |1 
 b/include/linux/swiotlb.h   |3 
 b/kernel/dma/Kconfig|3 
 b/kernel/dma/direct.c   |3 
 b/kernel/dma/mapping.c  |   11 
 b/kernel/dma/swiotlb.c  |   12 
 48 files changed, 317 insertions(+), 1158 deletions(-)


[PATCH 02/32] dma-direct: we might need GFP_DMA for 32-bit dma masks

2019-02-12 Thread Christoph Hellwig
If there is no ZONE_DMA32 we might need GFP_DMA to be able to
allocate memory that satisfies a 32-bit DMA mask.

Reported-by: Christian Zigotzky 
Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 kernel/dma/direct.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 355d16acee6d..d5bb51cf27c6 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -132,8 +132,7 @@ struct page *__dma_direct_alloc_pages(struct device *dev, 
size_t size,
goto again;
}
 
-   if (IS_ENABLED(CONFIG_ZONE_DMA) &&
-   phys_mask < DMA_BIT_MASK(32) && !(gfp & GFP_DMA)) {
+   if (IS_ENABLED(CONFIG_ZONE_DMA) && !(gfp & GFP_DMA)) {
gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
goto again;
}
-- 
2.20.1



[PATCH 23/32] powerpc/dma: remove dma_nommu_mmap_coherent

2019-02-12 Thread Christoph Hellwig
The coherent cache version of this function already is functionally
identicall to the default version, and by defining the
arch_dma_coherent_to_pfn hook the same is ture for the noncoherent
version as well.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h |  4 
 arch/powerpc/kernel/dma-iommu.c|  1 -
 arch/powerpc/kernel/dma-swiotlb.c  |  1 -
 arch/powerpc/kernel/dma.c  | 19 ---
 arch/powerpc/mm/dma-noncoherent.c  |  7 +--
 arch/powerpc/platforms/Kconfig.cputype |  1 +
 arch/powerpc/platforms/pseries/vio.c   |  1 -
 7 files changed, 6 insertions(+), 28 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 16d45518d9bb..f19c486e7b3f 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -25,10 +25,6 @@ extern void *__dma_nommu_alloc_coherent(struct device *dev, 
size_t size,
 extern void __dma_nommu_free_coherent(struct device *dev, size_t size,
   void *vaddr, dma_addr_t dma_handle,
   unsigned long attrs);
-extern int dma_nommu_mmap_coherent(struct device *dev,
-   struct vm_area_struct *vma,
-   void *cpu_addr, dma_addr_t handle,
-   size_t size, unsigned long attrs);
 int dma_nommu_map_sg(struct device *dev, struct scatterlist *sgl,
int nents, enum dma_data_direction direction,
unsigned long attrs);
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index 5a0b5e863b08..ed8b60829a90 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -167,7 +167,6 @@ u64 dma_iommu_get_required_mask(struct device *dev)
 const struct dma_map_ops dma_iommu_ops = {
.alloc  = dma_iommu_alloc_coherent,
.free   = dma_iommu_free_coherent,
-   .mmap   = dma_nommu_mmap_coherent,
.map_sg = dma_iommu_map_sg,
.unmap_sg   = dma_iommu_unmap_sg,
.dma_supported  = dma_iommu_dma_supported,
diff --git a/arch/powerpc/kernel/dma-swiotlb.c 
b/arch/powerpc/kernel/dma-swiotlb.c
index 0e21c318300e..d5950a0cb758 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -34,7 +34,6 @@ unsigned int ppc_swiotlb_enable;
 const struct dma_map_ops powerpc_swiotlb_dma_ops = {
.alloc = __dma_nommu_alloc_coherent,
.free = __dma_nommu_free_coherent,
-   .mmap = dma_nommu_mmap_coherent,
.map_sg = dma_direct_map_sg,
.unmap_sg = dma_direct_unmap_sg,
.dma_supported = swiotlb_dma_supported,
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 10fa4e18b4e9..841c43355a7e 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -114,24 +114,6 @@ void __dma_nommu_free_coherent(struct device *dev, size_t 
size,
 }
 #endif /* !CONFIG_NOT_COHERENT_CACHE */
 
-int dma_nommu_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
-void *cpu_addr, dma_addr_t handle, size_t size,
-unsigned long attrs)
-{
-   unsigned long pfn;
-
-#ifdef CONFIG_NOT_COHERENT_CACHE
-   vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-   pfn = __dma_get_coherent_pfn((unsigned long)cpu_addr);
-#else
-   pfn = page_to_pfn(virt_to_page(cpu_addr));
-#endif
-   return remap_pfn_range(vma, vma->vm_start,
-  pfn + vma->vm_pgoff,
-  vma->vm_end - vma->vm_start,
-  vma->vm_page_prot);
-}
-
 int dma_nommu_map_sg(struct device *dev, struct scatterlist *sgl,
int nents, enum dma_data_direction direction,
unsigned long attrs)
@@ -218,7 +200,6 @@ static inline void dma_nommu_sync_single(struct device *dev,
 const struct dma_map_ops dma_nommu_ops = {
.alloc  = __dma_nommu_alloc_coherent,
.free   = __dma_nommu_free_coherent,
-   .mmap   = dma_nommu_mmap_coherent,
.map_sg = dma_nommu_map_sg,
.unmap_sg   = dma_nommu_unmap_sg,
.dma_supported  = dma_nommu_dma_supported,
diff --git a/arch/powerpc/mm/dma-noncoherent.c 
b/arch/powerpc/mm/dma-noncoherent.c
index e955539686a4..ee95da19c82d 100644
--- a/arch/powerpc/mm/dma-noncoherent.c
+++ b/arch/powerpc/mm/dma-noncoherent.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -400,14 +401,16 @@ EXPORT_SYMBOL(__dma_sync_page);
 
 /*
  * Return the PFN for a given cpu virtual address returned by
- * __dma_nommu_alloc_coherent. This is used by dma_mmap_

[PATCH 19/32] powerpc/dma: remove max_direct_dma_addr

2019-02-12 Thread Christoph Hellwig
The max_direct_dma_addr duplicates the bus_dma_mask field in struct
device.  Use the generic field instead.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/device.h |  3 ---
 arch/powerpc/include/asm/dma-direct.h |  4 +---
 arch/powerpc/kernel/dma-swiotlb.c | 21 +
 arch/powerpc/kernel/dma.c |  5 ++---
 arch/powerpc/sysdev/fsl_pci.c |  4 ++--
 5 files changed, 6 insertions(+), 31 deletions(-)

diff --git a/arch/powerpc/include/asm/device.h 
b/arch/powerpc/include/asm/device.h
index 3814e1c2d4bc..a130be13ee83 100644
--- a/arch/powerpc/include/asm/device.h
+++ b/arch/powerpc/include/asm/device.h
@@ -38,9 +38,6 @@ struct dev_archdata {
 #ifdef CONFIG_IOMMU_API
void*iommu_domain;
 #endif
-#ifdef CONFIG_SWIOTLB
-   dma_addr_t  max_direct_dma_addr;
-#endif
 #ifdef CONFIG_PPC64
struct pci_dn   *pci_data;
 #endif
diff --git a/arch/powerpc/include/asm/dma-direct.h 
b/arch/powerpc/include/asm/dma-direct.h
index 7702875aabb7..e00ab5d0612d 100644
--- a/arch/powerpc/include/asm/dma-direct.h
+++ b/arch/powerpc/include/asm/dma-direct.h
@@ -5,9 +5,7 @@
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t 
size)
 {
 #ifdef CONFIG_SWIOTLB
-   struct dev_archdata *sd = &dev->archdata;
-
-   if (sd->max_direct_dma_addr && addr + size > sd->max_direct_dma_addr)
+   if (dev->bus_dma_mask && addr + size > dev->bus_dma_mask)
return false;
 #endif
 
diff --git a/arch/powerpc/kernel/dma-swiotlb.c 
b/arch/powerpc/kernel/dma-swiotlb.c
index 42badc4bf536..0e21c318300e 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -24,21 +24,6 @@
 
 unsigned int ppc_swiotlb_enable;
 
-static u64 swiotlb_powerpc_get_required(struct device *dev)
-{
-   u64 end, mask, max_direct_dma_addr = dev->archdata.max_direct_dma_addr;
-
-   end = memblock_end_of_DRAM();
-   if (max_direct_dma_addr && end > max_direct_dma_addr)
-   end = max_direct_dma_addr;
-   end += get_dma_offset(dev);
-
-   mask = 1ULL << (fls64(end) - 1);
-   mask += mask - 1;
-
-   return mask;
-}
-
 /*
  * At the moment, all platforms that use this code only require
  * swiotlb to be used if we're operating on HIGHMEM.  Since
@@ -59,22 +44,18 @@ const struct dma_map_ops powerpc_swiotlb_dma_ops = {
.sync_single_for_device = dma_direct_sync_single_for_device,
.sync_sg_for_cpu = dma_direct_sync_sg_for_cpu,
.sync_sg_for_device = dma_direct_sync_sg_for_device,
-   .get_required_mask = swiotlb_powerpc_get_required,
+   .get_required_mask = dma_direct_get_required_mask,
 };
 
 static int ppc_swiotlb_bus_notify(struct notifier_block *nb,
  unsigned long action, void *data)
 {
struct device *dev = data;
-   struct dev_archdata *sd;
 
/* We are only intereted in device addition */
if (action != BUS_NOTIFY_ADD_DEVICE)
return 0;
 
-   sd = &dev->archdata;
-   sd->max_direct_dma_addr = 0;
-
/* May need to bounce if the device can't address all of DRAM */
if ((dma_get_mask(dev) + 1) < memblock_end_of_DRAM())
set_dma_ops(dev, &powerpc_swiotlb_dma_ops);
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 9def69c8f602..1e191eb3f0ec 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -30,11 +30,10 @@
 static u64 __maybe_unused get_pfn_limit(struct device *dev)
 {
u64 pfn = (dev->coherent_dma_mask >> PAGE_SHIFT) + 1;
-   struct dev_archdata __maybe_unused *sd = &dev->archdata;
 
 #ifdef CONFIG_SWIOTLB
-   if (sd->max_direct_dma_addr && dev->dma_ops == &powerpc_swiotlb_dma_ops)
-   pfn = min_t(u64, pfn, sd->max_direct_dma_addr >> PAGE_SHIFT);
+   if (dev->bus_dma_mask && dev->dma_ops == &powerpc_swiotlb_dma_ops)
+   pfn = min_t(u64, pfn, dev->bus_dma_mask >> PAGE_SHIFT);
 #endif
 
return pfn;
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index 561f97d698cc..b710cee023a2 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -117,9 +117,8 @@ static u64 pci64_dma_offset;
 static void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
 {
struct pci_controller *hose = pci_bus_to_host(pdev->bus);
-   struct dev_archdata *sd = &pdev->dev.archdata;
 
-   sd->max_direct_dma_addr =
+   pdev->dev.bus_dma_mask =
hose->dma_window_base_cur + hose->dma_window_size;
 }
 
@@ -144,6 +143,7 @@ static int fsl_pci_dma_set_mask(struct device *dev, u64 
dma_mask)
 * mapping that allows addressing any RAM address from across PCI.
 */
if (dev_is_pci(dev) && dma_mask >= pci64_dma_offset * 2 - 1) {
+   dev->bus_dma_mask = 0;
set_dma_ops(dev, &dma_nommu_ops);
se

[PATCH 21/32] dma-mapping, powerpc: simplify the arch dma_set_mask override

2019-02-12 Thread Christoph Hellwig
Instead of letting the architecture supply all of dma_set_mask just
give it an additional hook selected by Kconfig.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/Kconfig   |  1 +
 arch/powerpc/include/asm/dma-mapping.h |  2 --
 arch/powerpc/include/asm/machdep.h |  2 +-
 arch/powerpc/kernel/Makefile   |  1 +
 arch/powerpc/kernel/dma-mask.c | 12 
 arch/powerpc/kernel/dma.c  | 12 
 arch/powerpc/sysdev/fsl_pci.c  |  8 +---
 kernel/dma/Kconfig |  3 +++
 kernel/dma/mapping.c   |  9 +++--
 9 files changed, 26 insertions(+), 24 deletions(-)
 create mode 100644 arch/powerpc/kernel/dma-mask.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8a4ae675c9ba..8af6a7d93148 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -883,6 +883,7 @@ config FSL_SOC
 
 config FSL_PCI
bool
+   select ARCH_HAS_DMA_SET_MASK
select PPC_INDIRECT_PCI
select PCI_QUIRKS
 
diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index dc7f7bcdf65d..16d45518d9bb 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -110,7 +110,5 @@ static inline void set_dma_offset(struct device *dev, 
dma_addr_t off)
dev->archdata.dma_offset = off;
 }
 
-#define HAVE_ARCH_DMA_SET_MASK 1
-
 #endif /* __KERNEL__ */
 #endif /* _ASM_DMA_MAPPING_H */
diff --git a/arch/powerpc/include/asm/machdep.h 
b/arch/powerpc/include/asm/machdep.h
index 7b70dcbce1b9..2f0ca6560e47 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -47,7 +47,7 @@ struct machdep_calls {
 #endif
 #endif /* CONFIG_PPC64 */
 
-   int (*dma_set_mask)(struct device *dev, u64 dma_mask);
+   void(*dma_set_mask)(struct device *dev, u64 dma_mask);
 
int (*probe)(void);
void(*setup_arch)(void); /* Optional, may be NULL */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index cb7f0bb9ee71..9bb12cd642ef 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_UPROBES)   += uprobes.o
 obj-$(CONFIG_PPC_UDBG_16550)   += legacy_serial.o udbg_16550.o
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_SWIOTLB)  += dma-swiotlb.o
+obj-$(CONFIG_ARCH_HAS_DMA_SET_MASK) += dma-mask.o
 
 pci64-$(CONFIG_PPC64)  += pci_dn.o pci-hotplug.o isa-bridge.o
 obj-$(CONFIG_PCI)  += pci_$(BITS).o $(pci64-y) \
diff --git a/arch/powerpc/kernel/dma-mask.c b/arch/powerpc/kernel/dma-mask.c
new file mode 100644
index ..ffbbbc432612
--- /dev/null
+++ b/arch/powerpc/kernel/dma-mask.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+#include 
+#include 
+
+void arch_dma_set_mask(struct device *dev, u64 dma_mask)
+{
+   if (ppc_md.dma_set_mask)
+   ppc_md.dma_set_mask(dev, dma_mask);
+}
+EXPORT_SYMBOL(arch_dma_set_mask);
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 1e191eb3f0ec..e422ca65d1cf 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -234,18 +234,6 @@ const struct dma_map_ops dma_nommu_ops = {
 };
 EXPORT_SYMBOL(dma_nommu_ops);
 
-int dma_set_mask(struct device *dev, u64 dma_mask)
-{
-   if (ppc_md.dma_set_mask)
-   return ppc_md.dma_set_mask(dev, dma_mask);
-
-   if (!dev->dma_mask || !dma_supported(dev, dma_mask))
-   return -EIO;
-   *dev->dma_mask = dma_mask;
-   return 0;
-}
-EXPORT_SYMBOL(dma_set_mask);
-
 static int __init dma_init(void)
 {
 #ifdef CONFIG_IBMVIO
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index b710cee023a2..0c6510f340cb 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -133,11 +133,8 @@ static void setup_swiotlb_ops(struct pci_controller *hose)
 static inline void setup_swiotlb_ops(struct pci_controller *hose) {}
 #endif
 
-static int fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask)
+static void fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask)
 {
-   if (!dev->dma_mask || !dma_supported(dev, dma_mask))
-   return -EIO;
-
/*
 * Fix up PCI devices that are able to DMA to the large inbound
 * mapping that allows addressing any RAM address from across PCI.
@@ -147,9 +144,6 @@ static int fsl_pci_dma_set_mask(struct device *dev, u64 
dma_mask)
set_dma_ops(dev, &dma_nommu_ops);
set_dma_offset(dev, pci64_dma_offset);
}
-
-   *dev->dma_mask = dma_mask;
-   return 0;
 }
 
 static int setup_one_atmu(struct ccsr_pci __iomem *pci,
diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig
index ca88b867e7fe..0711d18645de 100644
--- a/kernel/dma/Kconfig
+++ b/kernel/dma/Kconfig
@@ -16,

[PATCH 08/32] powerpc/cell: use the generic iommu bypass code

2019-02-12 Thread Christoph Hellwig
This gets rid of a lot of clumsy code and finally allows us to mark
dma_iommu_ops const.

Includes fixes from Michael Ellerman.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/include/asm/dma-mapping.h |   2 +-
 arch/powerpc/include/asm/iommu.h   |   6 ++
 arch/powerpc/kernel/dma-iommu.c|   7 +-
 arch/powerpc/platforms/cell/iommu.c| 140 ++---
 4 files changed, 20 insertions(+), 135 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index ff86b863eceb..1d80174db8a4 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -74,7 +74,7 @@ static inline unsigned long device_to_mask(struct device *dev)
  * Available generic sets of operations
  */
 #ifdef CONFIG_PPC64
-extern struct dma_map_ops dma_iommu_ops;
+extern const struct dma_map_ops dma_iommu_ops;
 #endif
 extern const struct dma_map_ops dma_nommu_ops;
 
diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index bd069a6542ab..6f00a892ebdf 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -319,5 +319,11 @@ extern void iommu_release_ownership(struct iommu_table 
*tbl);
 extern enum dma_data_direction iommu_tce_direction(unsigned long tce);
 extern unsigned long iommu_direction_to_tce_perm(enum dma_data_direction dir);
 
+#ifdef CONFIG_PPC_CELL_NATIVE
+extern bool iommu_fixed_is_weak;
+#else
+#define iommu_fixed_is_weak false
+#endif
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_IOMMU_H */
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index fda92156b194..5a0b5e863b08 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -20,14 +20,15 @@
  */
 static inline bool dma_iommu_alloc_bypass(struct device *dev)
 {
-   return dev->archdata.iommu_bypass &&
+   return dev->archdata.iommu_bypass && !iommu_fixed_is_weak &&
dma_nommu_dma_supported(dev, dev->coherent_dma_mask);
 }
 
 static inline bool dma_iommu_map_bypass(struct device *dev,
unsigned long attrs)
 {
-   return dev->archdata.iommu_bypass;
+   return dev->archdata.iommu_bypass &&
+   (!iommu_fixed_is_weak || (attrs & DMA_ATTR_WEAK_ORDERING));
 }
 
 /* Allocates a contiguous real buffer and creates mappings over it.
@@ -163,7 +164,7 @@ u64 dma_iommu_get_required_mask(struct device *dev)
return mask;
 }
 
-struct dma_map_ops dma_iommu_ops = {
+const struct dma_map_ops dma_iommu_ops = {
.alloc  = dma_iommu_alloc_coherent,
.free   = dma_iommu_free_coherent,
.mmap   = dma_nommu_mmap_coherent,
diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 4c609c0db5af..6663cd3e6bb6 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -546,7 +546,7 @@ static unsigned long cell_dma_nommu_offset;
 static unsigned long dma_iommu_fixed_base;
 
 /* iommu_fixed_is_weak is set if booted with iommu_fixed=weak */
-static int iommu_fixed_is_weak;
+bool iommu_fixed_is_weak;
 
 static struct iommu_table *cell_get_iommu_table(struct device *dev)
 {
@@ -568,94 +568,6 @@ static struct iommu_table *cell_get_iommu_table(struct 
device *dev)
return &window->table;
 }
 
-/* A coherent allocation implies strong ordering */
-
-static void *dma_fixed_alloc_coherent(struct device *dev, size_t size,
- dma_addr_t *dma_handle, gfp_t flag,
- unsigned long attrs)
-{
-   if (iommu_fixed_is_weak)
-   return iommu_alloc_coherent(dev, cell_get_iommu_table(dev),
-   size, dma_handle,
-   device_to_mask(dev), flag,
-   dev_to_node(dev));
-   else
-   return dma_nommu_ops.alloc(dev, size, dma_handle, flag,
-   attrs);
-}
-
-static void dma_fixed_free_coherent(struct device *dev, size_t size,
-   void *vaddr, dma_addr_t dma_handle,
-   unsigned long attrs)
-{
-   if (iommu_fixed_is_weak)
-   iommu_free_coherent(cell_get_iommu_table(dev), size, vaddr,
-   dma_handle);
-   else
-   dma_nommu_ops.free(dev, size, vaddr, dma_handle, attrs);
-}
-
-static dma_addr_t dma_fixed_map_page(struct device *dev, struct page *page,
-unsigned long offset, size_t size,
-enum dma_data_direction direction,
-unsigned long attrs)
-{
-   if (iommu_fixed_is_weak == (attrs & DMA_ATTR_WEAK_ORDERING))
-   return dma_nommu_ops.map_page(dev, page, offset, size,
- 

[PATCH 25/32] powerpc/dma: remove dma_nommu_dma_supported

2019-02-12 Thread Christoph Hellwig
This function is largely identical to the generic version used
everywhere else.  Replace it with the generic version.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h |  1 -
 arch/powerpc/kernel/dma-iommu.c|  2 +-
 arch/powerpc/kernel/dma.c  | 25 +
 3 files changed, 2 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index af9a32d4fcf8..cdf70aaeafeb 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -31,7 +31,6 @@ int dma_nommu_map_sg(struct device *dev, struct scatterlist 
*sgl,
 dma_addr_t dma_nommu_map_page(struct device *dev, struct page *page,
unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs);
-int dma_nommu_dma_supported(struct device *dev, u64 mask);
 
 #ifdef CONFIG_NOT_COHERENT_CACHE
 /*
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index 4377b69a9d42..67fbfaa4e3b2 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -21,7 +21,7 @@
 static inline bool dma_iommu_alloc_bypass(struct device *dev)
 {
return dev->archdata.iommu_bypass && !iommu_fixed_is_weak &&
-   dma_nommu_dma_supported(dev, dev->coherent_dma_mask);
+   dma_direct_supported(dev, dev->coherent_dma_mask);
 }
 
 static inline bool dma_iommu_map_bypass(struct device *dev,
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 46afc66cc271..a3546a82f6d7 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -39,29 +39,6 @@ static u64 __maybe_unused get_pfn_limit(struct device *dev)
return pfn;
 }
 
-int dma_nommu_dma_supported(struct device *dev, u64 mask)
-{
-#ifdef CONFIG_PPC64
-   u64 limit = phys_to_dma(dev, (memblock_end_of_DRAM() - 1));
-
-   /* Limit fits in the mask, we are good */
-   if (mask >= limit)
-   return 1;
-
-#ifdef CONFIG_FSL_SOC
-   /*
-* Freescale gets another chance via ZONE_DMA, however
-* that will have to be refined if/when they support iommus
-*/
-   return 1;
-#endif
-   /* Sorry ... */
-   return 0;
-#else
-   return 1;
-#endif
-}
-
 #ifndef CONFIG_NOT_COHERENT_CACHE
 void *__dma_nommu_alloc_coherent(struct device *dev, size_t size,
  dma_addr_t *dma_handle, gfp_t flag,
@@ -190,7 +167,7 @@ const struct dma_map_ops dma_nommu_ops = {
.free   = __dma_nommu_free_coherent,
.map_sg = dma_nommu_map_sg,
.unmap_sg   = dma_nommu_unmap_sg,
-   .dma_supported  = dma_nommu_dma_supported,
+   .dma_supported  = dma_direct_supported,
.map_page   = dma_nommu_map_page,
.unmap_page = dma_nommu_unmap_page,
.get_required_mask  = dma_direct_get_required_mask,
-- 
2.20.1



[PATCH 13/32] powerpc/powernv: use the generic iommu bypass code

2019-02-12 Thread Christoph Hellwig
Use the generic iommu bypass code instead of overriding set_dma_mask.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 95 ++-
 1 file changed, 25 insertions(+), 70 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 23ffbc71589a..9a1db2de9605 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1825,89 +1825,45 @@ static int pnv_pci_ioda_dma_64bit_bypass(struct 
pnv_ioda_pe *pe)
return -EIO;
 }
 
-static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
+static bool pnv_pci_ioda_iommu_bypass_supported(struct pci_dev *pdev,
+   u64 dma_mask)
 {
struct pci_controller *hose = pci_bus_to_host(pdev->bus);
struct pnv_phb *phb = hose->private_data;
struct pci_dn *pdn = pci_get_pdn(pdev);
struct pnv_ioda_pe *pe;
-   uint64_t top;
-   bool bypass = false;
-   s64 rc;
 
if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
return -ENODEV;
 
pe = &phb->ioda.pe_array[pdn->pe_number];
if (pe->tce_bypass_enabled) {
-   top = pe->tce_bypass_base + memblock_end_of_DRAM() - 1;
-   bypass = (dma_mask >= top);
+   u64 top = pe->tce_bypass_base + memblock_end_of_DRAM() - 1;
+   if (dma_mask >= top)
+   return true;
}
 
-   if (bypass) {
-   dev_info(&pdev->dev, "Using 64-bit DMA iommu bypass\n");
-   set_dma_ops(&pdev->dev, &dma_nommu_ops);
-   } else {
-   /*
-* If the device can't set the TCE bypass bit but still wants
-* to access 4GB or more, on PHB3 we can reconfigure TVE#0 to
-* bypass the 32-bit region and be usable for 64-bit DMAs.
-* The device needs to be able to address all of this space.
-*/
-   if (dma_mask >> 32 &&
-   dma_mask > (memory_hotplug_max() + (1ULL << 32)) &&
-   /* pe->pdev should be set if it's a single device, pe->pbus 
if not */
-   (pe->device_count == 1 || !pe->pbus) &&
-   phb->model == PNV_PHB_MODEL_PHB3) {
-   /* Configure the bypass mode */
-   rc = pnv_pci_ioda_dma_64bit_bypass(pe);
-   if (rc)
-   return rc;
-   /* 4GB offset bypasses 32-bit space */
-   set_dma_offset(&pdev->dev, (1ULL << 32));
-   set_dma_ops(&pdev->dev, &dma_nommu_ops);
-   } else if (dma_mask >> 32 && dma_mask != DMA_BIT_MASK(64)) {
-   /*
-* Fail the request if a DMA mask between 32 and 64 bits
-* was requested but couldn't be fulfilled. Ideally we
-* would do this for 64-bits but historically we have
-* always fallen back to 32-bits.
-*/
-   return -ENOMEM;
-   } else {
-   dev_info(&pdev->dev, "Using 32-bit DMA via iommu\n");
-   set_dma_ops(&pdev->dev, &dma_iommu_ops);
-   }
+   /*
+* If the device can't set the TCE bypass bit but still wants
+* to access 4GB or more, on PHB3 we can reconfigure TVE#0 to
+* bypass the 32-bit region and be usable for 64-bit DMAs.
+* The device needs to be able to address all of this space.
+*/
+   if (dma_mask >> 32 &&
+   dma_mask > (memory_hotplug_max() + (1ULL << 32)) &&
+   /* pe->pdev should be set if it's a single device, pe->pbus if not 
*/
+   (pe->device_count == 1 || !pe->pbus) &&
+   phb->model == PNV_PHB_MODEL_PHB3) {
+   /* Configure the bypass mode */
+   s64 rc = pnv_pci_ioda_dma_64bit_bypass(pe);
+   if (rc)
+   return rc;
+   /* 4GB offset bypasses 32-bit space */
+   set_dma_offset(&pdev->dev, (1ULL << 32));
+   return true;
}
-   *pdev->dev.dma_mask = dma_mask;
-
-   /* Update peer npu devices */
-   pnv_npu_try_dma_set_bypass(pdev, bypass);
-
-   return 0;
-}
-
-static u64 pnv_pci_ioda_dma_get_required_mask(struct pci_dev *pdev)
-{
-   struct pci_controller *hose = pci_bus_to_host(pdev->bus);
-   struct pnv_phb *phb = hose->private_data;
-   struct pci_dn *pdn = pci_get_pdn(pdev);
-   struct pnv_ioda_pe *pe;
-   u64 end, mask;
 
-   if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
-   return 0;
-
-   pe = &phb->ioda.pe_array[pdn->pe_number];
-   if (!pe->tce_bypass_enabled)
-   return __dma_get_required_mask(&pdev->dev);
-
-
-   end = pe->tce_bypass_base + memblock_

[PATCH 04/32] powerpc/dma: handle iommu bypass in dma_iommu_ops

2019-02-12 Thread Christoph Hellwig
Add a new iommu_bypass flag to struct dev_archdata so that the dma_iommu
implementation can handle the direct mapping transparently instead of
switiching ops around.  Setting of this flag is controlled by new
pci_controller_ops method.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/device.h  |  5 ++
 arch/powerpc/include/asm/dma-mapping.h |  8 +++
 arch/powerpc/include/asm/pci-bridge.h  |  2 +
 arch/powerpc/kernel/dma-iommu.c| 70 +++---
 arch/powerpc/kernel/dma.c  | 19 +++
 5 files changed, 87 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/device.h 
b/arch/powerpc/include/asm/device.h
index 0245bfcaac32..1aa53318b4bc 100644
--- a/arch/powerpc/include/asm/device.h
+++ b/arch/powerpc/include/asm/device.h
@@ -19,6 +19,11 @@ struct iommu_table;
  * drivers/macintosh/macio_asic.c
  */
 struct dev_archdata {
+   /*
+* Set to %true if the dma_iommu_ops are requested to use a direct
+* window instead of dynamically mapping memory.
+*/
+   booliommu_bypass : 1;
/*
 * These two used to be a union. However, with the hybrid ops we need
 * both so here we store both a DMA offset for direct mappings and
diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index ebf66809f2d3..ff86b863eceb 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -29,6 +29,14 @@ extern int dma_nommu_mmap_coherent(struct device *dev,
struct vm_area_struct *vma,
void *cpu_addr, dma_addr_t handle,
size_t size, unsigned long attrs);
+int dma_nommu_map_sg(struct device *dev, struct scatterlist *sgl,
+   int nents, enum dma_data_direction direction,
+   unsigned long attrs);
+dma_addr_t dma_nommu_map_page(struct device *dev, struct page *page,
+   unsigned long offset, size_t size,
+   enum dma_data_direction dir, unsigned long attrs);
+int dma_nommu_dma_supported(struct device *dev, u64 mask);
+u64 dma_nommu_get_required_mask(struct device *dev);
 
 #ifdef CONFIG_NOT_COHERENT_CACHE
 /*
diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index aee4fcc24990..d7492dca6599 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -19,6 +19,8 @@ struct device_node;
 struct pci_controller_ops {
void(*dma_dev_setup)(struct pci_dev *pdev);
void(*dma_bus_setup)(struct pci_bus *bus);
+   bool(*iommu_bypass_supported)(struct pci_dev *pdev,
+   u64 mask);
 
int (*probe_mode)(struct pci_bus *bus);
 
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index dd8601cd20df..fda92156b194 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -6,12 +6,30 @@
  * busses using the iommu infrastructure
  */
 
+#include 
+#include 
 #include 
 
 /*
  * Generic iommu implementation
  */
 
+/*
+ * The coherent mask may be smaller than the real mask, check if we can
+ * really use a direct window.
+ */
+static inline bool dma_iommu_alloc_bypass(struct device *dev)
+{
+   return dev->archdata.iommu_bypass &&
+   dma_nommu_dma_supported(dev, dev->coherent_dma_mask);
+}
+
+static inline bool dma_iommu_map_bypass(struct device *dev,
+   unsigned long attrs)
+{
+   return dev->archdata.iommu_bypass;
+}
+
 /* Allocates a contiguous real buffer and creates mappings over it.
  * Returns the virtual address of the buffer and sets dma_handle
  * to the dma address (mapping) of the first page.
@@ -20,6 +38,9 @@ static void *dma_iommu_alloc_coherent(struct device *dev, 
size_t size,
  dma_addr_t *dma_handle, gfp_t flag,
  unsigned long attrs)
 {
+   if (dma_iommu_alloc_bypass(dev))
+   return __dma_nommu_alloc_coherent(dev, size, dma_handle, flag,
+   attrs);
return iommu_alloc_coherent(dev, get_iommu_table_base(dev), size,
dma_handle, dev->coherent_dma_mask, flag,
dev_to_node(dev));
@@ -29,7 +50,11 @@ static void dma_iommu_free_coherent(struct device *dev, 
size_t size,
void *vaddr, dma_addr_t dma_handle,
unsigned long attrs)
 {
-   iommu_free_coherent(get_iommu_table_base(dev), size, vaddr, dma_handle);
+   if (dma_iommu_alloc_bypass(dev))
+   __dma_nommu_free_coherent(dev, size, vaddr, dma_handle, attrs);
+   else
+   iommu_free_coherent(get_iommu_table_base(dev), size, vaddr,
+   

Re: [PATCH 1/4] dt-bindings: clock: exynos: Put CLK_UART3 in order

2019-02-12 Thread Chanwoo Choi
Hi,

On 19. 2. 13. 오전 2:50, Krzysztof Kozlowski wrote:
> Order the CLK_UART3 by ID.  No change in functionality.
> 
> Signed-off-by: Krzysztof Kozlowski 
> ---
>  include/dt-bindings/clock/exynos5410.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/dt-bindings/clock/exynos5410.h 
> b/include/dt-bindings/clock/exynos5410.h
> index f179eabbcdb7..5b911ede0534 100644
> --- a/include/dt-bindings/clock/exynos5410.h
> +++ b/include/dt-bindings/clock/exynos5410.h
> @@ -36,6 +36,7 @@
>  #define CLK_UART0257
>  #define CLK_UART1258
>  #define CLK_UART2259
> +#define CLK_UART3260
>  #define CLK_I2C0 261
>  #define CLK_I2C1 262
>  #define CLK_I2C2 263
> @@ -44,7 +45,6 @@
>  #define CLK_USI1 266
>  #define CLK_USI2 267
>  #define CLK_USI3 268
> -#define CLK_UART3260
>  #define CLK_PWM  279
>  #define CLK_MCT  315
>  #define CLK_WDT  316
> 

Acked-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


[PATCH 17/32] powerpc/dma: remove get_pci_dma_ops

2019-02-12 Thread Christoph Hellwig
This function is only used by the Cell iommu code, which can keep track
if it is using the iommu internally just as good.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/pci.h  |  2 --
 arch/powerpc/kernel/pci-common.c|  6 --
 arch/powerpc/platforms/cell/iommu.c | 17 -
 3 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
index 0c72f1897063..6a1861a6301e 100644
--- a/arch/powerpc/include/asm/pci.h
+++ b/arch/powerpc/include/asm/pci.h
@@ -52,10 +52,8 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev 
*dev, int channel)
 
 #ifdef CONFIG_PCI
 extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
-extern const struct dma_map_ops *get_pci_dma_ops(void);
 #else  /* CONFIG_PCI */
 #define set_pci_dma_ops(d)
-#define get_pci_dma_ops()  NULL
 #endif
 
 #ifdef CONFIG_PPC64
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 88e4f69a09e5..a84707680525 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -69,12 +69,6 @@ void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
pci_dma_ops = dma_ops;
 }
 
-const struct dma_map_ops *get_pci_dma_ops(void)
-{
-   return pci_dma_ops;
-}
-EXPORT_SYMBOL(get_pci_dma_ops);
-
 /*
  * This function should run under locking protection, specifically
  * hose_spinlock.
diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 6663cd3e6bb6..a3c4057a8f65 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -544,6 +544,7 @@ static struct cbe_iommu *cell_iommu_for_node(int nid)
 static unsigned long cell_dma_nommu_offset;
 
 static unsigned long dma_iommu_fixed_base;
+static bool cell_iommu_enabled;
 
 /* iommu_fixed_is_weak is set if booted with iommu_fixed=weak */
 bool iommu_fixed_is_weak;
@@ -572,16 +573,14 @@ static u64 cell_iommu_get_fixed_address(struct device 
*dev);
 
 static void cell_dma_dev_setup(struct device *dev)
 {
-   if (get_pci_dma_ops() == &dma_iommu_ops) {
+   if (cell_iommu_enabled) {
u64 addr = cell_iommu_get_fixed_address(dev);
 
if (addr != OF_BAD_ADDR)
set_dma_offset(dev, addr + dma_iommu_fixed_base);
set_iommu_table_base(dev, cell_get_iommu_table(dev));
-   } else if (get_pci_dma_ops() == &dma_nommu_ops) {
-   set_dma_offset(dev, cell_dma_nommu_offset);
} else {
-   BUG();
+   set_dma_offset(dev, cell_dma_nommu_offset);
}
 }
 
@@ -599,11 +598,11 @@ static int cell_of_bus_notify(struct notifier_block *nb, 
unsigned long action,
if (action != BUS_NOTIFY_ADD_DEVICE)
return 0;
 
-   /* We use the PCI DMA ops */
-   dev->dma_ops = get_pci_dma_ops();
-
+   if (cell_iommu_enabled)
+   dev->dma_ops = &dma_iommu_ops;
+   else
+   dev->dma_ops = &dma_nommu_ops;
cell_dma_dev_setup(dev);
-
return 0;
 }
 
@@ -1093,7 +1092,7 @@ static int __init cell_iommu_init(void)
  done:
/* Setup default PCI iommu ops */
set_pci_dma_ops(&dma_iommu_ops);
-
+   cell_iommu_enabled = true;
  bail:
/* Register callbacks on OF platform device addition/removal
 * to handle linking them to the right DMA operations
-- 
2.20.1



[PATCH 11/32] powerpc/powernv: remove pnv_pci_ioda_pe_single_vendor

2019-02-12 Thread Christoph Hellwig
This function is completely bogus - the fact that two PCIe devices come
from the same vendor has absolutely nothing to say about the DMA
capabilities and characteristics.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 28 ++-
 1 file changed, 2 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 53982f887a7f..d9060a0f4c8e 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1756,31 +1756,6 @@ static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb 
*phb, struct pci_dev *pdev
 */
 }
 
-static bool pnv_pci_ioda_pe_single_vendor(struct pnv_ioda_pe *pe)
-{
-   unsigned short vendor = 0;
-   struct pci_dev *pdev;
-
-   if (pe->device_count == 1)
-   return true;
-
-   /* pe->pdev should be set if it's a single device, pe->pbus if not */
-   if (!pe->pbus)
-   return true;
-
-   list_for_each_entry(pdev, &pe->pbus->devices, bus_list) {
-   if (!vendor) {
-   vendor = pdev->vendor;
-   continue;
-   }
-
-   if (pdev->vendor != vendor)
-   return false;
-   }
-
-   return true;
-}
-
 /*
  * Reconfigure TVE#0 to be usable as 64-bit DMA space.
  *
@@ -1881,7 +1856,8 @@ static int pnv_pci_ioda_dma_set_mask(struct pci_dev 
*pdev, u64 dma_mask)
 */
if (dma_mask >> 32 &&
dma_mask > (memory_hotplug_max() + (1ULL << 32)) &&
-   pnv_pci_ioda_pe_single_vendor(pe) &&
+   /* pe->pdev should be set if it's a single device, pe->pbus 
if not */
+   (pe->device_count == 1 || !pe->pbus) &&
phb->model == PNV_PHB_MODEL_PHB3) {
/* Configure the bypass mode */
rc = pnv_pci_ioda_dma_64bit_bypass(pe);
-- 
2.20.1



[PATCH 12/32] powerpc/powernv: remove pnv_npu_dma_set_mask

2019-02-12 Thread Christoph Hellwig
These devices are not PCIe devices and do not have associated dma map
ops, so this is just dead code.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index d9060a0f4c8e..23ffbc71589a 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -3646,14 +3646,6 @@ static const struct pci_controller_ops 
pnv_pci_ioda_controller_ops = {
.shutdown   = pnv_pci_ioda_shutdown,
 };
 
-static int pnv_npu_dma_set_mask(struct pci_dev *npdev, u64 dma_mask)
-{
-   dev_err_once(&npdev->dev,
-   "%s operation unsupported for NVLink devices\n",
-   __func__);
-   return -EPERM;
-}
-
 static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
.dma_dev_setup  = pnv_pci_dma_dev_setup,
.setup_msi_irqs = pnv_setup_msi_irqs,
@@ -3661,7 +3653,6 @@ static const struct pci_controller_ops 
pnv_npu_ioda_controller_ops = {
.enable_device_hook = pnv_pci_enable_device_hook,
.window_alignment   = pnv_pci_window_alignment,
.reset_secondary_bus= pnv_pci_reset_secondary_bus,
-   .dma_set_mask   = pnv_npu_dma_set_mask,
.shutdown   = pnv_pci_ioda_shutdown,
.disable_device = pnv_npu_disable_device,
 };
-- 
2.20.1



[PATCH 18/32] powerpc/dma: move pci_dma_dev_setup_swiotlb to fsl_pci.c

2019-02-12 Thread Christoph Hellwig
pci_dma_dev_setup_swiotlb is only used by the fsl_pci code, and closely
related to it, so fsl_pci.c seems like a better place for it.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/swiotlb.h |  2 --
 arch/powerpc/kernel/dma-swiotlb.c  | 11 ---
 arch/powerpc/sysdev/fsl_pci.c  |  9 +
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/swiotlb.h 
b/arch/powerpc/include/asm/swiotlb.h
index f65ecf57b66c..26a0f12b835b 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -18,8 +18,6 @@ extern const struct dma_map_ops powerpc_swiotlb_dma_ops;
 extern unsigned int ppc_swiotlb_enable;
 int __init swiotlb_setup_bus_notifier(void);
 
-extern void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev);
-
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
 #else
diff --git a/arch/powerpc/kernel/dma-swiotlb.c 
b/arch/powerpc/kernel/dma-swiotlb.c
index 7d5fc9751622..42badc4bf536 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -62,17 +62,6 @@ const struct dma_map_ops powerpc_swiotlb_dma_ops = {
.get_required_mask = swiotlb_powerpc_get_required,
 };
 
-void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
-{
-   struct pci_controller *hose;
-   struct dev_archdata *sd;
-
-   hose = pci_bus_to_host(pdev->bus);
-   sd = &pdev->dev.archdata;
-   sd->max_direct_dma_addr =
-   hose->dma_window_base_cur + hose->dma_window_size;
-}
-
 static int ppc_swiotlb_bus_notify(struct notifier_block *nb,
  unsigned long action, void *data)
 {
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index 918be816b097..561f97d698cc 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -114,6 +114,15 @@ static struct pci_ops fsl_indirect_pcie_ops =
 static u64 pci64_dma_offset;
 
 #ifdef CONFIG_SWIOTLB
+static void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev)
+{
+   struct pci_controller *hose = pci_bus_to_host(pdev->bus);
+   struct dev_archdata *sd = &pdev->dev.archdata;
+
+   sd->max_direct_dma_addr =
+   hose->dma_window_base_cur + hose->dma_window_size;
+}
+
 static void setup_swiotlb_ops(struct pci_controller *hose)
 {
if (ppc_swiotlb_enable) {
-- 
2.20.1



[PATCH 26/32] swiotlb: remove swiotlb_dma_supported

2019-02-12 Thread Christoph Hellwig
The only user left is powerpc, but even there the generic dma-direct
version works just as well, given that we guarantee that the swiotlb
buffer must always be addressable.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/kernel/dma-swiotlb.c |  2 +-
 include/linux/swiotlb.h   |  3 ---
 kernel/dma/swiotlb.c  | 12 
 3 files changed, 1 insertion(+), 16 deletions(-)

diff --git a/arch/powerpc/kernel/dma-swiotlb.c 
b/arch/powerpc/kernel/dma-swiotlb.c
index d5950a0cb758..6d2677b2daa6 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -36,7 +36,7 @@ const struct dma_map_ops powerpc_swiotlb_dma_ops = {
.free = __dma_nommu_free_coherent,
.map_sg = dma_direct_map_sg,
.unmap_sg = dma_direct_unmap_sg,
-   .dma_supported = swiotlb_dma_supported,
+   .dma_supported = dma_direct_supported,
.map_page = dma_direct_map_page,
.unmap_page = dma_direct_unmap_page,
.sync_single_for_cpu = dma_direct_sync_single_for_cpu,
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 7c007ed7505f..54254388899e 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -60,9 +60,6 @@ extern void swiotlb_tbl_sync_single(struct device *hwdev,
size_t size, enum dma_data_direction dir,
enum dma_sync_target target);
 
-extern int
-swiotlb_dma_supported(struct device *hwdev, u64 mask);
-
 #ifdef CONFIG_SWIOTLB
 extern enum swiotlb_force swiotlb_force;
 extern phys_addr_t io_tlb_start, io_tlb_end;
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index d6361776dc5c..cbf3498a46f9 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -648,15 +648,3 @@ bool swiotlb_map(struct device *dev, phys_addr_t *phys, 
dma_addr_t *dma_addr,
 
return true;
 }
-
-/*
- * Return whether the given device DMA address mask can be supported
- * properly.  For example, if your device can only drive the low 24-bits
- * during bus mastering, then you would pass 0x00ff as the mask to
- * this function.
- */
-int
-swiotlb_dma_supported(struct device *hwdev, u64 mask)
-{
-   return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask;
-}
-- 
2.20.1



[PATCH 20/32] powerpc/dma: fix an off-by-one in dma_capable

2019-02-12 Thread Christoph Hellwig
We need to compare the last byte in the dma range and not the one after it
for the bus_dma_mask, just like we do for the regular dma_mask.  Fix this
cleanly by merging the two comparisms into one.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-direct.h | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-direct.h 
b/arch/powerpc/include/asm/dma-direct.h
index e00ab5d0612d..92d8aed86422 100644
--- a/arch/powerpc/include/asm/dma-direct.h
+++ b/arch/powerpc/include/asm/dma-direct.h
@@ -4,15 +4,11 @@
 
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t 
size)
 {
-#ifdef CONFIG_SWIOTLB
-   if (dev->bus_dma_mask && addr + size > dev->bus_dma_mask)
-   return false;
-#endif
-
if (!dev->dma_mask)
return false;
 
-   return addr + size - 1 <= *dev->dma_mask;
+   return addr + size - 1 <=
+   min_not_zero(*dev->dma_mask, dev->bus_dma_mask);
 }
 
 static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
-- 
2.20.1



[PATCH 28/32] powerpc/dma: use the dma_direct mapping routines

2019-02-12 Thread Christoph Hellwig
Switch the streaming DMA mapping and ownership transfer methods to the
functionally identical dma_direct_ versions.  Factor the cache
maintainance helpers into the form expected by the common code for that.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h | 30 -
 arch/powerpc/kernel/dma-iommu.c|  4 +-
 arch/powerpc/kernel/dma.c  | 87 +++---
 arch/powerpc/mm/dma-noncoherent.c  | 29 ++---
 arch/powerpc/platforms/Kconfig.cputype |  2 +
 5 files changed, 32 insertions(+), 120 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index cdf70aaeafeb..4de9d4ee23c1 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -25,36 +25,6 @@ extern void *__dma_nommu_alloc_coherent(struct device *dev, 
size_t size,
 extern void __dma_nommu_free_coherent(struct device *dev, size_t size,
   void *vaddr, dma_addr_t dma_handle,
   unsigned long attrs);
-int dma_nommu_map_sg(struct device *dev, struct scatterlist *sgl,
-   int nents, enum dma_data_direction direction,
-   unsigned long attrs);
-dma_addr_t dma_nommu_map_page(struct device *dev, struct page *page,
-   unsigned long offset, size_t size,
-   enum dma_data_direction dir, unsigned long attrs);
-
-#ifdef CONFIG_NOT_COHERENT_CACHE
-/*
- * DMA-consistent mapping functions for PowerPCs that don't support
- * cache snooping.  These allocate/free a region of uncached mapped
- * memory space for use with DMA devices.  Alternatively, you could
- * allocate the space "normally" and use the cache management functions
- * to ensure it is consistent.
- */
-struct device;
-extern void __dma_sync(void *vaddr, size_t size, int direction);
-extern void __dma_sync_page(struct page *page, unsigned long offset,
-size_t size, int direction);
-extern unsigned long __dma_get_coherent_pfn(unsigned long cpu_addr);
-
-#else /* ! CONFIG_NOT_COHERENT_CACHE */
-/*
- * Cache coherent cores.
- */
-
-#define __dma_sync(addr, size, rw) ((void)0)
-#define __dma_sync_page(pg, off, sz, rw)   ((void)0)
-
-#endif /* ! CONFIG_NOT_COHERENT_CACHE */
 
 static inline unsigned long device_to_mask(struct device *dev)
 {
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index c75ba4e3a50c..09231ef06d01 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -68,7 +68,7 @@ static dma_addr_t dma_iommu_map_page(struct device *dev, 
struct page *page,
 unsigned long attrs)
 {
if (dma_iommu_map_bypass(dev, attrs))
-   return dma_nommu_map_page(dev, page, offset, size, direction,
+   return dma_direct_map_page(dev, page, offset, size, direction,
attrs);
return iommu_map_page(dev, get_iommu_table_base(dev), page, offset,
  size, device_to_mask(dev), direction, attrs);
@@ -90,7 +90,7 @@ static int dma_iommu_map_sg(struct device *dev, struct 
scatterlist *sglist,
unsigned long attrs)
 {
if (dma_iommu_map_bypass(dev, attrs))
-   return dma_nommu_map_sg(dev, sglist, nelems, direction, attrs);
+   return dma_direct_map_sg(dev, sglist, nelems, direction, attrs);
return ppc_iommu_map_sg(dev, get_iommu_table_base(dev), sglist, nelems,
device_to_mask(dev), direction, attrs);
 }
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index f983f8d435a6..b9f7283e7224 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -27,77 +27,6 @@
  * default the offset is PCI_DRAM_OFFSET.
  */
 
-int dma_nommu_map_sg(struct device *dev, struct scatterlist *sgl,
-   int nents, enum dma_data_direction direction,
-   unsigned long attrs)
-{
-   struct scatterlist *sg;
-   int i;
-
-   for_each_sg(sgl, sg, nents, i) {
-   sg->dma_address = phys_to_dma(dev, sg_phys(sg));
-   sg->dma_length = sg->length;
-
-   if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
-   continue;
-
-   __dma_sync_page(sg_page(sg), sg->offset, sg->length, direction);
-   }
-
-   return nents;
-}
-
-static void dma_nommu_unmap_sg(struct device *dev, struct scatterlist *sgl,
-   int nents, enum dma_data_direction direction,
-   unsigned long attrs)
-{
-   struct scatterlist *sg;
-   int i;
-
-   for_each_sg(sgl, sg, nents, i)
-   __dma_sync_page(sg_page(sg), sg->offset, sg->length, direction);
-}
-
-dma_addr_t dma_nommu_map_page(struct device *dev, struct page *page,
-   unsigned long of

[PATCH 24/32] powerpc/dma: remove dma_nommu_get_required_mask

2019-02-12 Thread Christoph Hellwig
This function is identical to the generic dma_direct_get_required_mask,
except that the generic version also takes the bus_dma_mask account,
which could lead to incorrect results in the powerpc version.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h |  1 -
 arch/powerpc/kernel/dma-iommu.c|  2 +-
 arch/powerpc/kernel/dma.c  | 14 +-
 3 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index f19c486e7b3f..af9a32d4fcf8 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -32,7 +32,6 @@ dma_addr_t dma_nommu_map_page(struct device *dev, struct page 
*page,
unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs);
 int dma_nommu_dma_supported(struct device *dev, u64 mask);
-u64 dma_nommu_get_required_mask(struct device *dev);
 
 #ifdef CONFIG_NOT_COHERENT_CACHE
 /*
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index ed8b60829a90..4377b69a9d42 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -152,7 +152,7 @@ u64 dma_iommu_get_required_mask(struct device *dev)
return 0;
 
if (dev_is_pci(dev)) {
-   u64 bypass_mask = dma_nommu_get_required_mask(dev);
+   u64 bypass_mask = dma_direct_get_required_mask(dev);
 
if (dma_iommu_bypass_supported(dev, bypass_mask))
return bypass_mask;
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 841c43355a7e..46afc66cc271 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -145,18 +145,6 @@ static void dma_nommu_unmap_sg(struct device *dev, struct 
scatterlist *sgl,
__dma_sync_page(sg_page(sg), sg->offset, sg->length, direction);
 }
 
-u64 dma_nommu_get_required_mask(struct device *dev)
-{
-   u64 end, mask;
-
-   end = memblock_end_of_DRAM() + get_dma_offset(dev);
-
-   mask = 1ULL << (fls64(end) - 1);
-   mask += mask - 1;
-
-   return mask;
-}
-
 dma_addr_t dma_nommu_map_page(struct device *dev, struct page *page,
unsigned long offset, size_t size,
enum dma_data_direction dir, unsigned long attrs)
@@ -205,7 +193,7 @@ const struct dma_map_ops dma_nommu_ops = {
.dma_supported  = dma_nommu_dma_supported,
.map_page   = dma_nommu_map_page,
.unmap_page = dma_nommu_unmap_page,
-   .get_required_mask  = dma_nommu_get_required_mask,
+   .get_required_mask  = dma_direct_get_required_mask,
 #ifdef CONFIG_NOT_COHERENT_CACHE
.sync_single_for_cpu= dma_nommu_sync_single,
.sync_single_for_device = dma_nommu_sync_single,
-- 
2.20.1



[PATCH 27/32] powerpc/dma: use the dma-direct allocator for coherent platforms

2019-02-12 Thread Christoph Hellwig
The generic code allows a few nice things such as node local allocations
and dipping into the CMA area.  The lookup of the right zone for a given
dma mask works a little different, but the results should be the same.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/pgtable.h |  1 -
 arch/powerpc/kernel/dma-iommu.c|  5 +--
 arch/powerpc/kernel/dma-swiotlb.c  |  4 +-
 arch/powerpc/kernel/dma.c  | 69 +++---
 arch/powerpc/mm/mem.c  | 22 --
 5 files changed, 9 insertions(+), 92 deletions(-)

diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index dad1d27e196d..505550fb2935 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -66,7 +66,6 @@ extern unsigned long empty_zero_page[];
 
 extern pgd_t swapper_pg_dir[];
 
-int dma_pfn_limit_to_zone(u64 pfn_limit);
 extern void paging_init(void);
 
 /*
diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
index 67fbfaa4e3b2..c75ba4e3a50c 100644
--- a/arch/powerpc/kernel/dma-iommu.c
+++ b/arch/powerpc/kernel/dma-iommu.c
@@ -40,8 +40,7 @@ static void *dma_iommu_alloc_coherent(struct device *dev, 
size_t size,
  unsigned long attrs)
 {
if (dma_iommu_alloc_bypass(dev))
-   return __dma_nommu_alloc_coherent(dev, size, dma_handle, flag,
-   attrs);
+   return dma_direct_alloc(dev, size, dma_handle, flag, attrs);
return iommu_alloc_coherent(dev, get_iommu_table_base(dev), size,
dma_handle, dev->coherent_dma_mask, flag,
dev_to_node(dev));
@@ -52,7 +51,7 @@ static void dma_iommu_free_coherent(struct device *dev, 
size_t size,
unsigned long attrs)
 {
if (dma_iommu_alloc_bypass(dev))
-   __dma_nommu_free_coherent(dev, size, vaddr, dma_handle, attrs);
+   dma_direct_free(dev, size, vaddr, dma_handle, attrs);
else
iommu_free_coherent(get_iommu_table_base(dev), size, vaddr,
dma_handle);
diff --git a/arch/powerpc/kernel/dma-swiotlb.c 
b/arch/powerpc/kernel/dma-swiotlb.c
index 6d2677b2daa6..3a15a7d945e9 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -32,8 +32,8 @@ unsigned int ppc_swiotlb_enable;
  * for everything else.
  */
 const struct dma_map_ops powerpc_swiotlb_dma_ops = {
-   .alloc = __dma_nommu_alloc_coherent,
-   .free = __dma_nommu_free_coherent,
+   .alloc = dma_direct_alloc,
+   .free = dma_direct_free,
.map_sg = dma_direct_map_sg,
.unmap_sg = dma_direct_unmap_sg,
.dma_supported = dma_direct_supported,
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index a3546a82f6d7..f983f8d435a6 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -27,70 +27,6 @@
  * default the offset is PCI_DRAM_OFFSET.
  */
 
-static u64 __maybe_unused get_pfn_limit(struct device *dev)
-{
-   u64 pfn = (dev->coherent_dma_mask >> PAGE_SHIFT) + 1;
-
-#ifdef CONFIG_SWIOTLB
-   if (dev->bus_dma_mask && dev->dma_ops == &powerpc_swiotlb_dma_ops)
-   pfn = min_t(u64, pfn, dev->bus_dma_mask >> PAGE_SHIFT);
-#endif
-
-   return pfn;
-}
-
-#ifndef CONFIG_NOT_COHERENT_CACHE
-void *__dma_nommu_alloc_coherent(struct device *dev, size_t size,
- dma_addr_t *dma_handle, gfp_t flag,
- unsigned long attrs)
-{
-   void *ret;
-   struct page *page;
-   int node = dev_to_node(dev);
-#ifdef CONFIG_FSL_SOC
-   u64 pfn = get_pfn_limit(dev);
-   int zone;
-
-   /*
-* This code should be OK on other platforms, but we have drivers that
-* don't set coherent_dma_mask. As a workaround we just ifdef it. This
-* whole routine needs some serious cleanup.
-*/
-
-   zone = dma_pfn_limit_to_zone(pfn);
-   if (zone < 0) {
-   dev_err(dev, "%s: No suitable zone for pfn %#llx\n",
-   __func__, pfn);
-   return NULL;
-   }
-
-   switch (zone) {
-#ifdef CONFIG_ZONE_DMA
-   case ZONE_DMA:
-   flag |= GFP_DMA;
-   break;
-#endif
-   };
-#endif /* CONFIG_FSL_SOC */
-
-   page = alloc_pages_node(node, flag, get_order(size));
-   if (page == NULL)
-   return NULL;
-   ret = page_address(page);
-   memset(ret, 0, size);
-   *dma_handle = phys_to_dma(dev,__pa(ret));
-
-   return ret;
-}
-
-void __dma_nommu_free_coherent(struct device *dev, size_t size,
-   void *vaddr, dma_addr_t dma_handle,
-   unsigned long attrs)
-{
-   free_pages((unsigned long)vaddr, get_order(size));
-}
-#endif /* !CONFIG_NOT_COHERENT

[PATCH 14/32] powerpc/dma: stop overriding dma_get_required_mask

2019-02-12 Thread Christoph Hellwig
The ppc_md and pci_controller_ops methods are unused now and can be
removed.  The dma_nommu implementation is generic to the generic one
except for using max_pfn instead of calling into the memblock API,
and all other dma_map_ops instances implement a method of their own.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/device.h  |  2 --
 arch/powerpc/include/asm/dma-mapping.h |  2 --
 arch/powerpc/include/asm/machdep.h |  2 --
 arch/powerpc/include/asm/pci-bridge.h  |  1 -
 arch/powerpc/kernel/dma.c  | 29 --
 kernel/dma/mapping.c   |  2 --
 6 files changed, 38 deletions(-)

diff --git a/arch/powerpc/include/asm/device.h 
b/arch/powerpc/include/asm/device.h
index 1aa53318b4bc..3814e1c2d4bc 100644
--- a/arch/powerpc/include/asm/device.h
+++ b/arch/powerpc/include/asm/device.h
@@ -59,6 +59,4 @@ struct pdev_archdata {
u64 dma_mask;
 };
 
-#define ARCH_HAS_DMA_GET_REQUIRED_MASK
-
 #endif /* _ASM_POWERPC_DEVICE_H */
diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 1d80174db8a4..dc7f7bcdf65d 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -112,7 +112,5 @@ static inline void set_dma_offset(struct device *dev, 
dma_addr_t off)
 
 #define HAVE_ARCH_DMA_SET_MASK 1
 
-extern u64 __dma_get_required_mask(struct device *dev);
-
 #endif /* __KERNEL__ */
 #endif /* _ASM_DMA_MAPPING_H */
diff --git a/arch/powerpc/include/asm/machdep.h 
b/arch/powerpc/include/asm/machdep.h
index 8311869005fa..7b70dcbce1b9 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -47,9 +47,7 @@ struct machdep_calls {
 #endif
 #endif /* CONFIG_PPC64 */
 
-   /* Platform set_dma_mask and dma_get_required_mask overrides */
int (*dma_set_mask)(struct device *dev, u64 dma_mask);
-   u64 (*dma_get_required_mask)(struct device *dev);
 
int (*probe)(void);
void(*setup_arch)(void); /* Optional, may be NULL */
diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index d7492dca6599..236a7460b6ec 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -46,7 +46,6 @@ struct pci_controller_ops {
 #endif
 
int (*dma_set_mask)(struct pci_dev *pdev, u64 dma_mask);
-   u64 (*dma_get_required_mask)(struct pci_dev *pdev);
 
void(*shutdown)(struct pci_controller *hose);
 };
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index e5db4d3f8bea..0d52107b90f0 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -318,35 +318,6 @@ int dma_set_mask(struct device *dev, u64 dma_mask)
 }
 EXPORT_SYMBOL(dma_set_mask);
 
-u64 __dma_get_required_mask(struct device *dev)
-{
-   const struct dma_map_ops *dma_ops = get_dma_ops(dev);
-
-   if (unlikely(dma_ops == NULL))
-   return 0;
-
-   if (dma_ops->get_required_mask)
-   return dma_ops->get_required_mask(dev);
-
-   return DMA_BIT_MASK(8 * sizeof(dma_addr_t));
-}
-
-u64 dma_get_required_mask(struct device *dev)
-{
-   if (ppc_md.dma_get_required_mask)
-   return ppc_md.dma_get_required_mask(dev);
-
-   if (dev_is_pci(dev)) {
-   struct pci_dev *pdev = to_pci_dev(dev);
-   struct pci_controller *phb = pci_bus_to_host(pdev->bus);
-   if (phb->controller_ops.dma_get_required_mask)
-   return phb->controller_ops.dma_get_required_mask(pdev);
-   }
-
-   return __dma_get_required_mask(dev);
-}
-EXPORT_SYMBOL_GPL(dma_get_required_mask);
-
 static int __init dma_init(void)
 {
 #ifdef CONFIG_IBMVIO
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index a11006b6d8e8..40c0af744692 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -207,7 +207,6 @@ int dma_mmap_attrs(struct device *dev, struct 
vm_area_struct *vma,
 }
 EXPORT_SYMBOL(dma_mmap_attrs);
 
-#ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
 static u64 dma_default_get_required_mask(struct device *dev)
 {
u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
@@ -238,7 +237,6 @@ u64 dma_get_required_mask(struct device *dev)
return dma_default_get_required_mask(dev);
 }
 EXPORT_SYMBOL_GPL(dma_get_required_mask);
-#endif
 
 #ifndef arch_dma_alloc_attrs
 #define arch_dma_alloc_attrs(dev)  (true)
-- 
2.20.1



[PATCH 09/32] powerpc/dart: remove dead cleanup code in iommu_init_early_dart

2019-02-12 Thread Christoph Hellwig
If dart_init failed we didn't have a chance to setup dma or controller
ops yet, so there is no point in resetting them.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/sysdev/dart_iommu.c | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/arch/powerpc/sysdev/dart_iommu.c b/arch/powerpc/sysdev/dart_iommu.c
index a5b40d1460f1..283ce04c5844 100644
--- a/arch/powerpc/sysdev/dart_iommu.c
+++ b/arch/powerpc/sysdev/dart_iommu.c
@@ -428,7 +428,7 @@ void __init iommu_init_early_dart(struct pci_controller_ops 
*controller_ops)
 
/* Initialize the DART HW */
if (dart_init(dn) != 0)
-   goto bail;
+   return;
 
/* Setup bypass if supported */
if (dart_is_u4)
@@ -439,15 +439,6 @@ void __init iommu_init_early_dart(struct 
pci_controller_ops *controller_ops)
 
/* Setup pci_dma ops */
set_pci_dma_ops(&dma_iommu_ops);
-   return;
-
- bail:
-   /* If init failed, use direct iommu and null setup functions */
-   controller_ops->dma_dev_setup = NULL;
-   controller_ops->dma_bus_setup = NULL;
-
-   /* Setup pci_dma ops */
-   set_pci_dma_ops(&dma_nommu_ops);
 }
 
 #ifdef CONFIG_PM
-- 
2.20.1



[PATCH 22/32] powerpc/dma: use phys_to_dma instead of get_dma_offset

2019-02-12 Thread Christoph Hellwig
Use the standard portable helper instead of the powerpc specific one,
which is about to go away.

Signed-off-by: Christoph Hellwig 
Acked-by: Benjamin Herrenschmidt 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/kernel/dma.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index e422ca65d1cf..10fa4e18b4e9 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -6,7 +6,7 @@
  */
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -42,7 +42,7 @@ static u64 __maybe_unused get_pfn_limit(struct device *dev)
 int dma_nommu_dma_supported(struct device *dev, u64 mask)
 {
 #ifdef CONFIG_PPC64
-   u64 limit = get_dma_offset(dev) + (memblock_end_of_DRAM() - 1);
+   u64 limit = phys_to_dma(dev, (memblock_end_of_DRAM() - 1));
 
/* Limit fits in the mask, we are good */
if (mask >= limit)
@@ -101,7 +101,7 @@ void *__dma_nommu_alloc_coherent(struct device *dev, size_t 
size,
return NULL;
ret = page_address(page);
memset(ret, 0, size);
-   *dma_handle = __pa(ret) + get_dma_offset(dev);
+   *dma_handle = phys_to_dma(dev,__pa(ret));
 
return ret;
 }
@@ -140,7 +140,7 @@ int dma_nommu_map_sg(struct device *dev, struct scatterlist 
*sgl,
int i;
 
for_each_sg(sgl, sg, nents, i) {
-   sg->dma_address = sg_phys(sg) + get_dma_offset(dev);
+   sg->dma_address = phys_to_dma(dev, sg_phys(sg));
sg->dma_length = sg->length;
 
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
@@ -182,7 +182,7 @@ dma_addr_t dma_nommu_map_page(struct device *dev, struct 
page *page,
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
__dma_sync_page(page, offset, size, dir);
 
-   return page_to_phys(page) + offset + get_dma_offset(dev);
+   return phys_to_dma(dev, page_to_phys(page)) + offset;
 }
 
 static inline void dma_nommu_unmap_page(struct device *dev,
-- 
2.20.1



[PATCH 07/32] powerpc/cell: move dma direct window setup out of dma_configure

2019-02-12 Thread Christoph Hellwig
Configure the dma settings at device setup time, and stop playing games
with get_pci_dma_ops.  This prepares for using the common dma_configure
code later on.

Includes fixes from Michael Ellerman.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/platforms/cell/iommu.c | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index af2a3c15e0ec..4c609c0db5af 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -656,14 +656,21 @@ static const struct dma_map_ops dma_iommu_fixed_ops = {
.unmap_page = dma_fixed_unmap_page,
 };
 
+static u64 cell_iommu_get_fixed_address(struct device *dev);
+
 static void cell_dma_dev_setup(struct device *dev)
 {
-   if (get_pci_dma_ops() == &dma_iommu_ops)
+   if (get_pci_dma_ops() == &dma_iommu_ops) {
+   u64 addr = cell_iommu_get_fixed_address(dev);
+
+   if (addr != OF_BAD_ADDR)
+   set_dma_offset(dev, addr + dma_iommu_fixed_base);
set_iommu_table_base(dev, cell_get_iommu_table(dev));
-   else if (get_pci_dma_ops() == &dma_nommu_ops)
+   } else if (get_pci_dma_ops() == &dma_nommu_ops) {
set_dma_offset(dev, cell_dma_nommu_offset);
-   else
+   } else {
BUG();
+   }
 }
 
 static void cell_pci_dma_dev_setup(struct pci_dev *dev)
@@ -894,7 +901,11 @@ static u64 cell_iommu_get_fixed_address(struct device *dev)
const u32 *ranges = NULL;
int i, len, best, naddr, nsize, pna, range_size;
 
+   /* We can be called for platform devices that have no of_node */
np = of_node_get(dev->of_node);
+   if (!np)
+   goto out;
+
while (1) {
naddr = of_n_addr_cells(np);
nsize = of_n_size_cells(np);
@@ -949,19 +960,14 @@ static int dma_suported_and_switch(struct device *dev, 
u64 dma_mask)
 {
if (dma_mask == DMA_BIT_MASK(64) &&
cell_iommu_get_fixed_address(dev) != OF_BAD_ADDR) {
-   u64 addr = cell_iommu_get_fixed_address(dev) +
-   dma_iommu_fixed_base;
dev_dbg(dev, "iommu: 64-bit OK, using fixed ops\n");
-   dev_dbg(dev, "iommu: fixed addr = %llx\n", addr);
set_dma_ops(dev, &dma_iommu_fixed_ops);
-   set_dma_offset(dev, addr);
return 1;
}
 
if (dma_iommu_dma_supported(dev, dma_mask)) {
dev_dbg(dev, "iommu: not 64-bit, using default ops\n");
-   set_dma_ops(dev, get_pci_dma_ops());
-   cell_dma_dev_setup(dev);
+   set_dma_ops(dev, &dma_iommu_ops);
return 1;
}
 
-- 
2.20.1



[PATCH 32/32] powerpc/dma: trim the fat from

2019-02-12 Thread Christoph Hellwig
There is no need to provide anything but get_arch_dma_ops to
.  More the remaining declarations to 
and drop all the includes.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h| 29 ---
 arch/powerpc/include/asm/iommu.h  | 10 +++
 arch/powerpc/platforms/44x/ppc476.c   |  1 +
 arch/powerpc/platforms/85xx/corenet_generic.c |  1 +
 arch/powerpc/platforms/85xx/qemu_e500.c   |  1 +
 arch/powerpc/sysdev/fsl_pci.c |  1 +
 6 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index a59c42879194..565d6f74b189 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -1,37 +1,9 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Copyright (C) 2004 IBM
- *
- * Implements the generic device dma API for powerpc.
- * the pci and vio busses
  */
 #ifndef _ASM_DMA_MAPPING_H
 #define _ASM_DMA_MAPPING_H
-#ifdef __KERNEL__
-
-#include 
-#include 
-/* need struct page definitions */
-#include 
-#include 
-#include 
-#include 
-#include 
-
-static inline unsigned long device_to_mask(struct device *dev)
-{
-   if (dev->dma_mask && *dev->dma_mask)
-   return *dev->dma_mask;
-   /* Assume devices without mask can take 32 bit addresses */
-   return 0xul;
-}
-
-/*
- * Available generic sets of operations
- */
-#ifdef CONFIG_PPC64
-extern const struct dma_map_ops dma_iommu_ops;
-#endif
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
 {
@@ -43,5 +15,4 @@ static inline const struct dma_map_ops 
*get_arch_dma_ops(struct bus_type *bus)
return NULL;
 }
 
-#endif /* __KERNEL__ */
 #endif /* _ASM_DMA_MAPPING_H */
diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
index 6f00a892ebdf..0ac52392ed99 100644
--- a/arch/powerpc/include/asm/iommu.h
+++ b/arch/powerpc/include/asm/iommu.h
@@ -325,5 +325,15 @@ extern bool iommu_fixed_is_weak;
 #define iommu_fixed_is_weak false
 #endif
 
+extern const struct dma_map_ops dma_iommu_ops;
+
+static inline unsigned long device_to_mask(struct device *dev)
+{
+   if (dev->dma_mask && *dev->dma_mask)
+   return *dev->dma_mask;
+   /* Assume devices without mask can take 32 bit addresses */
+   return 0xul;
+}
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_IOMMU_H */
diff --git a/arch/powerpc/platforms/44x/ppc476.c 
b/arch/powerpc/platforms/44x/ppc476.c
index e55933f9cd55..a5e61e5c16e2 100644
--- a/arch/powerpc/platforms/44x/ppc476.c
+++ b/arch/powerpc/platforms/44x/ppc476.c
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c 
b/arch/powerpc/platforms/85xx/corenet_generic.c
index 808da1e9c0a7..785e9641220d 100644
--- a/arch/powerpc/platforms/85xx/corenet_generic.c
+++ b/arch/powerpc/platforms/85xx/corenet_generic.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
diff --git a/arch/powerpc/platforms/85xx/qemu_e500.c 
b/arch/powerpc/platforms/85xx/qemu_e500.c
index 27631c607f3d..c52c8f9e8385 100644
--- a/arch/powerpc/platforms/85xx/qemu_e500.c
+++ b/arch/powerpc/platforms/85xx/qemu_e500.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "smp.h"
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index a04c6dde6ed0..f49aec251a5a 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
-- 
2.20.1



[PATCH 31/32] powerpc/dma: remove set_dma_offset

2019-02-12 Thread Christoph Hellwig
There is no good reason for this helper, just opencode it.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h| 6 --
 arch/powerpc/kernel/pci-common.c  | 2 +-
 arch/powerpc/platforms/cell/iommu.c   | 4 ++--
 arch/powerpc/platforms/powernv/pci-ioda.c | 6 +++---
 arch/powerpc/platforms/pseries/iommu.c| 7 ++-
 arch/powerpc/sysdev/dart_iommu.c  | 2 +-
 arch/powerpc/sysdev/fsl_pci.c | 2 +-
 drivers/misc/cxl/vphb.c   | 2 +-
 8 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index c70f55d2f5e0..a59c42879194 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -43,11 +43,5 @@ static inline const struct dma_map_ops 
*get_arch_dma_ops(struct bus_type *bus)
return NULL;
 }
 
-static inline void set_dma_offset(struct device *dev, dma_addr_t off)
-{
-   if (dev)
-   dev->archdata.dma_offset = off;
-}
-
 #endif /* __KERNEL__ */
 #endif /* _ASM_DMA_MAPPING_H */
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index 23989175349c..cbdf13d86227 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -966,7 +966,7 @@ static void pcibios_setup_device(struct pci_dev *dev)
 
/* Hook up default DMA ops */
set_dma_ops(&dev->dev, pci_dma_ops);
-   set_dma_offset(&dev->dev, PCI_DRAM_OFFSET);
+   dev->dev.archdata.dma_offset = PCI_DRAM_OFFSET;
 
/* Additional platform DMA/iommu setup */
phb = pci_bus_to_host(dev->bus);
diff --git a/arch/powerpc/platforms/cell/iommu.c 
b/arch/powerpc/platforms/cell/iommu.c
index 06abd432b830..54e012e1f720 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -577,10 +577,10 @@ static void cell_dma_dev_setup(struct device *dev)
u64 addr = cell_iommu_get_fixed_address(dev);
 
if (addr != OF_BAD_ADDR)
-   set_dma_offset(dev, addr + dma_iommu_fixed_base);
+   dev->archdata.dma_offset = addr + dma_iommu_fixed_base;
set_iommu_table_base(dev, cell_get_iommu_table(dev));
} else {
-   set_dma_offset(dev, cell_dma_nommu_offset);
+   dev->archdata.dma_offset = cell_dma_nommu_offset;
}
 }
 
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 9a1db2de9605..b56bf65e1bb6 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1746,7 +1746,7 @@ static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb 
*phb, struct pci_dev *pdev
 
pe = &phb->ioda.pe_array[pdn->pe_number];
WARN_ON(get_dma_ops(&pdev->dev) != &dma_iommu_ops);
-   set_dma_offset(&pdev->dev, pe->tce_bypass_base);
+   pdev->dev.archdata.dma_offset = pe->tce_bypass_base;
set_iommu_table_base(&pdev->dev, pe->table_group.tables[0]);
/*
 * Note: iommu_add_device() will fail here as
@@ -1859,7 +1859,7 @@ static bool pnv_pci_ioda_iommu_bypass_supported(struct 
pci_dev *pdev,
if (rc)
return rc;
/* 4GB offset bypasses 32-bit space */
-   set_dma_offset(&pdev->dev, (1ULL << 32));
+   pdev->dev.archdata.dma_offset = (1ULL << 32);
return true;
}
 
@@ -1872,7 +1872,7 @@ static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe 
*pe, struct pci_bus *bus)
 
list_for_each_entry(dev, &bus->devices, bus_list) {
set_iommu_table_base(&dev->dev, pe->table_group.tables[0]);
-   set_dma_offset(&dev->dev, pe->tce_bypass_base);
+   dev->dev.archdata.dma_offset = pe->tce_bypass_base;
 
if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate)
pnv_ioda_setup_bus_dma(pe, dev->subordinate);
diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index 37d2ce3f55a3..36eb1ddbac69 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1202,7 +1202,6 @@ static bool iommu_bypass_supported_pSeriesLP(struct 
pci_dev *pdev, u64 dma_mask)
 {
struct device_node *dn = pci_device_to_OF_node(pdev), *pdn;
const __be32 *dma_window = NULL;
-   u64 dma_offset;
 
/* only attempt to use a new window if 64-bit DMA is requested */
if (dma_mask < DMA_BIT_MASK(64))
@@ -1224,11 +1223,9 @@ static bool iommu_bypass_supported_pSeriesLP(struct 
pci_dev *pdev, u64 dma_mask)
}
 
if (pdn && PCI_DN(pdn)) {
-   dma_offset = enable_ddw(pdev, pdn);
-   if (dma_offset != 0) {
-   set_dma_offset(&pdev->dev, dma_offset);
+   pdev->dev.archdata.dma_of

[PATCH 29/32] powerpc/dma: use the generic direct mapping bypass

2019-02-12 Thread Christoph Hellwig
Now that we've switched all the powerpc nommu and swiotlb methods to
use the generic dma_direct_* calls we can remove these ops vectors
entirely and rely on the common direct mapping bypass that avoids
indirect function calls entirely.  This also allows to remove a whole
lot of boilerplate code related to setting up these operations.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-mapping.h|  9 ---
 arch/powerpc/include/asm/swiotlb.h|  3 -
 arch/powerpc/kernel/Makefile  |  2 +-
 arch/powerpc/kernel/dma-swiotlb.c | 58 -
 arch/powerpc/kernel/dma.c | 62 ---
 arch/powerpc/kernel/pci-common.c  |  2 +-
 arch/powerpc/kernel/setup-common.c|  1 -
 arch/powerpc/mm/dma-noncoherent.c |  6 +-
 arch/powerpc/platforms/44x/warp.c |  2 +-
 arch/powerpc/platforms/85xx/corenet_generic.c |  4 --
 arch/powerpc/platforms/85xx/ge_imp3a.c|  2 -
 arch/powerpc/platforms/85xx/mpc8536_ds.c  |  2 -
 arch/powerpc/platforms/85xx/mpc85xx_ds.c  |  4 --
 arch/powerpc/platforms/85xx/mpc85xx_mds.c |  4 --
 arch/powerpc/platforms/85xx/p1010rdb.c|  1 -
 arch/powerpc/platforms/85xx/p1022_ds.c|  2 -
 arch/powerpc/platforms/85xx/p1022_rdk.c   |  2 -
 arch/powerpc/platforms/86xx/mpc86xx_hpcn.c|  1 -
 arch/powerpc/platforms/cell/iommu.c   |  3 -
 arch/powerpc/platforms/pasemi/iommu.c |  2 +-
 arch/powerpc/platforms/pasemi/setup.c | 51 ---
 arch/powerpc/platforms/powernv/npu-dma.c  |  2 +-
 arch/powerpc/platforms/pseries/vio.c  |  7 +++
 arch/powerpc/sysdev/fsl_pci.c |  5 +-
 drivers/misc/cxl/vphb.c   |  1 -
 25 files changed, 16 insertions(+), 222 deletions(-)
 delete mode 100644 arch/powerpc/kernel/dma.c

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 4de9d4ee23c1..93e57e28be28 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -18,14 +18,6 @@
 #include 
 #include 
 
-/* Some dma direct funcs must be visible for use in other dma_ops */
-extern void *__dma_nommu_alloc_coherent(struct device *dev, size_t size,
-dma_addr_t *dma_handle, gfp_t flag,
-unsigned long attrs);
-extern void __dma_nommu_free_coherent(struct device *dev, size_t size,
-  void *vaddr, dma_addr_t dma_handle,
-  unsigned long attrs);
-
 static inline unsigned long device_to_mask(struct device *dev)
 {
if (dev->dma_mask && *dev->dma_mask)
@@ -40,7 +32,6 @@ static inline unsigned long device_to_mask(struct device *dev)
 #ifdef CONFIG_PPC64
 extern const struct dma_map_ops dma_iommu_ops;
 #endif
-extern const struct dma_map_ops dma_nommu_ops;
 
 static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
 {
diff --git a/arch/powerpc/include/asm/swiotlb.h 
b/arch/powerpc/include/asm/swiotlb.h
index 26a0f12b835b..b7d082c0ec25 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -13,10 +13,7 @@
 
 #include 
 
-extern const struct dma_map_ops powerpc_swiotlb_dma_ops;
-
 extern unsigned int ppc_swiotlb_enable;
-int __init swiotlb_setup_bus_notifier(void);
 
 #ifdef CONFIG_SWIOTLB
 void swiotlb_detect_4g(void);
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 9bb12cd642ef..8809e287b80d 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -36,7 +36,7 @@ obj-y := cputable.o ptrace.o 
syscalls.o \
   process.o systbl.o idle.o \
   signal.o sysfs.o cacheinfo.o time.o \
   prom.o traps.o setup-common.o \
-  udbg.o misc.o io.o dma.o misc_$(BITS).o \
+  udbg.o misc.o io.o misc_$(BITS).o \
   of_platform.o prom_parse.o
 obj-$(CONFIG_PPC64)+= setup_64.o sys_ppc32.o \
   signal_64.o ptrace32.o \
diff --git a/arch/powerpc/kernel/dma-swiotlb.c 
b/arch/powerpc/kernel/dma-swiotlb.c
index 3a15a7d945e9..132d61c91629 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -10,70 +10,12 @@
  * option) any later version.
  *
  */
-
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
-
 #include 
 #include 
-#include 
 
 unsigned int ppc_swiotlb_enable;
 
-/*
- * At the moment, all platforms that use this code only require
- * swiotlb to be used if we're operating on HIGHMEM.  Since
- * we don't ever call anything other than map_sg, unmap_sg,
- * map_page, and unmap_page on highmem, use normal dma_ops
- * for everyt

[PATCH 30/32] powerpc/dma: remove get_dma_offset

2019-02-12 Thread Christoph Hellwig
Just fold the calculation into __phys_to_dma/__dma_to_phys as those are
the only places that should know about it.

Signed-off-by: Christoph Hellwig 
Acked-by: Benjamin Herrenschmidt 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/include/asm/dma-direct.h  |  8 ++--
 arch/powerpc/include/asm/dma-mapping.h | 16 
 2 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-direct.h 
b/arch/powerpc/include/asm/dma-direct.h
index 92d8aed86422..a2912b47102c 100644
--- a/arch/powerpc/include/asm/dma-direct.h
+++ b/arch/powerpc/include/asm/dma-direct.h
@@ -13,11 +13,15 @@ static inline bool dma_capable(struct device *dev, 
dma_addr_t addr, size_t size)
 
 static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
-   return paddr + get_dma_offset(dev);
+   if (!dev)
+   return paddr + PCI_DRAM_OFFSET;
+   return paddr + dev->archdata.dma_offset;
 }
 
 static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
 {
-   return daddr - get_dma_offset(dev);
+   if (!dev)
+   return daddr - PCI_DRAM_OFFSET;
+   return daddr - dev->archdata.dma_offset;
 }
 #endif /* ASM_POWERPC_DMA_DIRECT_H */
diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 93e57e28be28..c70f55d2f5e0 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -43,22 +43,6 @@ static inline const struct dma_map_ops 
*get_arch_dma_ops(struct bus_type *bus)
return NULL;
 }
 
-/*
- * get_dma_offset()
- *
- * Get the dma offset on configurations where the dma address can be determined
- * from the physical address by looking at a simple offset.  Direct dma and
- * swiotlb use this function, but it is typically not used by implementations
- * with an iommu.
- */
-static inline dma_addr_t get_dma_offset(struct device *dev)
-{
-   if (dev)
-   return dev->archdata.dma_offset;
-
-   return PCI_DRAM_OFFSET;
-}
-
 static inline void set_dma_offset(struct device *dev, dma_addr_t off)
 {
if (dev)
-- 
2.20.1



[PATCH 10/32] powerpc/dart: use the generic iommu bypass code

2019-02-12 Thread Christoph Hellwig
Use the generic iommu bypass code instead of overriding set_dma_mask.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/sysdev/dart_iommu.c | 47 
 1 file changed, 17 insertions(+), 30 deletions(-)

diff --git a/arch/powerpc/sysdev/dart_iommu.c b/arch/powerpc/sysdev/dart_iommu.c
index 283ce04c5844..d42ba645d51d 100644
--- a/arch/powerpc/sysdev/dart_iommu.c
+++ b/arch/powerpc/sysdev/dart_iommu.c
@@ -360,13 +360,6 @@ static void iommu_table_dart_setup(void)
set_bit(iommu_table_dart.it_size - 1, iommu_table_dart.it_map);
 }
 
-static void pci_dma_dev_setup_dart(struct pci_dev *dev)
-{
-   if (dart_is_u4)
-   set_dma_offset(&dev->dev, DART_U4_BYPASS_BASE);
-   set_iommu_table_base(&dev->dev, &iommu_table_dart);
-}
-
 static void pci_dma_bus_setup_dart(struct pci_bus *bus)
 {
if (!iommu_table_dart_inited) {
@@ -390,27 +383,18 @@ static bool dart_device_on_pcie(struct device *dev)
return false;
 }
 
-static int dart_dma_set_mask(struct device *dev, u64 dma_mask)
+static void pci_dma_dev_setup_dart(struct pci_dev *dev)
 {
-   if (!dev->dma_mask || !dma_supported(dev, dma_mask))
-   return -EIO;
-
-   /* U4 supports a DART bypass, we use it for 64-bit capable
-* devices to improve performances. However, that only works
-* for devices connected to U4 own PCIe interface, not bridged
-* through hypertransport. We need the device to support at
-* least 40 bits of addresses.
-*/
-   if (dart_device_on_pcie(dev) && dma_mask >= DMA_BIT_MASK(40)) {
-   dev_info(dev, "Using 64-bit DMA iommu bypass\n");
-   set_dma_ops(dev, &dma_nommu_ops);
-   } else {
-   dev_info(dev, "Using 32-bit DMA via iommu\n");
-   set_dma_ops(dev, &dma_iommu_ops);
-   }
+   if (dart_is_u4 && dart_device_on_pcie(&dev->dev))
+   set_dma_offset(&dev->dev, DART_U4_BYPASS_BASE);
+   set_iommu_table_base(&dev->dev, &iommu_table_dart);
+}
 
-   *dev->dma_mask = dma_mask;
-   return 0;
+static bool iommu_bypass_supported_dart(struct pci_dev *dev, u64 mask)
+{
+   return dart_is_u4 &&
+   dart_device_on_pcie(&dev->dev) &&
+   mask >= DMA_BIT_MASK(40);
 }
 
 void __init iommu_init_early_dart(struct pci_controller_ops *controller_ops)
@@ -430,12 +414,15 @@ void __init iommu_init_early_dart(struct 
pci_controller_ops *controller_ops)
if (dart_init(dn) != 0)
return;
 
-   /* Setup bypass if supported */
-   if (dart_is_u4)
-   ppc_md.dma_set_mask = dart_dma_set_mask;
-
+   /*
+* U4 supports a DART bypass, we use it for 64-bit capable devices to
+* improve performance.  However, that only works for devices connected
+* to the U4 own PCIe interface, not bridged through hypertransport.
+* We need the device to support at least 40 bits of addresses.
+*/
controller_ops->dma_dev_setup = pci_dma_dev_setup_dart;
controller_ops->dma_bus_setup = pci_dma_bus_setup_dart;
+   controller_ops->iommu_bypass_supported = iommu_bypass_supported_dart;
 
/* Setup pci_dma ops */
set_pci_dma_ops(&dma_iommu_ops);
-- 
2.20.1



[PATCH 16/32] powerpc/dma: remove the iommu fallback for coherent allocations

2019-02-12 Thread Christoph Hellwig
All iommu capable platforms now always use the iommu code with the
internal bypass, so there is not need for this magic anymore.

Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 arch/powerpc/Kconfig  |  4 ---
 arch/powerpc/kernel/dma.c | 68 ++-
 2 files changed, 2 insertions(+), 70 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 08908219fba9..8a4ae675c9ba 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -119,9 +119,6 @@ config GENERIC_HWEIGHT
bool
default y
 
-config ARCH_HAS_DMA_SET_COHERENT_MASK
-bool
-
 config PPC
bool
default y
@@ -130,7 +127,6 @@ config PPC
#
select ARCH_HAS_DEBUG_VIRTUAL
select ARCH_HAS_DEVMEM_IS_ALLOWED
-   select ARCH_HAS_DMA_SET_COHERENT_MASK
select ARCH_HAS_ELF_RANDOMIZE
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_GCOV_PROFILE_ALL
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 5eca02315b2e..9def69c8f602 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -115,51 +115,6 @@ void __dma_nommu_free_coherent(struct device *dev, size_t 
size,
 }
 #endif /* !CONFIG_NOT_COHERENT_CACHE */
 
-static void *dma_nommu_alloc_coherent(struct device *dev, size_t size,
-  dma_addr_t *dma_handle, gfp_t flag,
-  unsigned long attrs)
-{
-   struct iommu_table *iommu;
-
-   /* The coherent mask may be smaller than the real mask, check if
-* we can really use the direct ops
-*/
-   if (dma_nommu_dma_supported(dev, dev->coherent_dma_mask))
-   return __dma_nommu_alloc_coherent(dev, size, dma_handle,
-  flag, attrs);
-
-   /* Ok we can't ... do we have an iommu ? If not, fail */
-   iommu = get_iommu_table_base(dev);
-   if (!iommu)
-   return NULL;
-
-   /* Try to use the iommu */
-   return iommu_alloc_coherent(dev, iommu, size, dma_handle,
-   dev->coherent_dma_mask, flag,
-   dev_to_node(dev));
-}
-
-static void dma_nommu_free_coherent(struct device *dev, size_t size,
-void *vaddr, dma_addr_t dma_handle,
-unsigned long attrs)
-{
-   struct iommu_table *iommu;
-
-   /* See comments in dma_nommu_alloc_coherent() */
-   if (dma_nommu_dma_supported(dev, dev->coherent_dma_mask))
-   return __dma_nommu_free_coherent(dev, size, vaddr, dma_handle,
- attrs);
-   /* Maybe we used an iommu ... */
-   iommu = get_iommu_table_base(dev);
-
-   /* If we hit that we should have never allocated in the first
-* place so how come we are freeing ?
-*/
-   if (WARN_ON(!iommu))
-   return;
-   iommu_free_coherent(iommu, size, vaddr, dma_handle);
-}
-
 int dma_nommu_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
 void *cpu_addr, dma_addr_t handle, size_t size,
 unsigned long attrs)
@@ -262,8 +217,8 @@ static inline void dma_nommu_sync_single(struct device *dev,
 #endif
 
 const struct dma_map_ops dma_nommu_ops = {
-   .alloc  = dma_nommu_alloc_coherent,
-   .free   = dma_nommu_free_coherent,
+   .alloc  = __dma_nommu_alloc_coherent,
+   .free   = __dma_nommu_free_coherent,
.mmap   = dma_nommu_mmap_coherent,
.map_sg = dma_nommu_map_sg,
.unmap_sg   = dma_nommu_unmap_sg,
@@ -280,25 +235,6 @@ const struct dma_map_ops dma_nommu_ops = {
 };
 EXPORT_SYMBOL(dma_nommu_ops);
 
-int dma_set_coherent_mask(struct device *dev, u64 mask)
-{
-   if (!dma_supported(dev, mask)) {
-   /*
-* We need to special case the direct DMA ops which can
-* support a fallback for coherent allocations. There
-* is no dma_op->set_coherent_mask() so we have to do
-* things the hard way:
-*/
-   if (get_dma_ops(dev) != &dma_nommu_ops ||
-   get_iommu_table_base(dev) == NULL ||
-   !dma_iommu_dma_supported(dev, mask))
-   return -EIO;
-   }
-   dev->coherent_dma_mask = mask;
-   return 0;
-}
-EXPORT_SYMBOL(dma_set_coherent_mask);
-
 int dma_set_mask(struct device *dev, u64 dma_mask)
 {
if (ppc_md.dma_set_mask)
-- 
2.20.1



[PATCH 15/32] powerpc/pci: remove the dma_set_mask pci_controller ops methods

2019-02-12 Thread Christoph Hellwig
Unused now.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/include/asm/pci-bridge.h | 2 --
 arch/powerpc/kernel/dma.c | 7 ---
 2 files changed, 9 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index 236a7460b6ec..98e8b46aff97 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -45,8 +45,6 @@ struct pci_controller_ops {
void(*teardown_msi_irqs)(struct pci_dev *pdev);
 #endif
 
-   int (*dma_set_mask)(struct pci_dev *pdev, u64 dma_mask);
-
void(*shutdown)(struct pci_controller *hose);
 };
 
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 0d52107b90f0..5eca02315b2e 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -304,13 +304,6 @@ int dma_set_mask(struct device *dev, u64 dma_mask)
if (ppc_md.dma_set_mask)
return ppc_md.dma_set_mask(dev, dma_mask);
 
-   if (dev_is_pci(dev)) {
-   struct pci_dev *pdev = to_pci_dev(dev);
-   struct pci_controller *phb = pci_bus_to_host(pdev->bus);
-   if (phb->controller_ops.dma_set_mask)
-   return phb->controller_ops.dma_set_mask(pdev, dma_mask);
-   }
-
if (!dev->dma_mask || !dma_supported(dev, dma_mask))
return -EIO;
*dev->dma_mask = dma_mask;
-- 
2.20.1



[PATCH 01/32] net: pasemi: set a 64-bit DMA mask on the DMA device

2019-02-12 Thread Christoph Hellwig
The pasemi driver never set a DMA mask, and given that the powerpc
DMA mapping routines never check it this worked ok so far.  But the
generic dma-direct code which I plan to switch on for powerpc checks
the DMA mask and fails unsupported mapping requests, so we need to
make sure the proper 64-bit mask is set.

Reported-by: Christian Zigotzky 
Signed-off-by: Christoph Hellwig 
Tested-by: Christian Zigotzky 
---
 drivers/net/ethernet/pasemi/pasemi_mac.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/pasemi/pasemi_mac.c 
b/drivers/net/ethernet/pasemi/pasemi_mac.c
index d21041554507..a5bf46310f60 100644
--- a/drivers/net/ethernet/pasemi/pasemi_mac.c
+++ b/drivers/net/ethernet/pasemi/pasemi_mac.c
@@ -1716,6 +1716,7 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
err = -ENODEV;
goto out;
}
+   dma_set_mask(&mac->dma_pdev->dev, DMA_BIT_MASK(64));
 
mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
if (!mac->iob_pdev) {
-- 
2.20.1



[PATCH 05/32] powerpc/pseries: unwind dma_get_required_mask_pSeriesLP a bit

2019-02-12 Thread Christoph Hellwig
Call dma_get_required_mask_pSeriesLP directly instead of dma_iommu_ops
to simply the code a bit.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/platforms/pseries/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index 8fc8fe0b9848..9f7ac75c5687 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1278,7 +1278,7 @@ static u64 dma_get_required_mask_pSeriesLP(struct device 
*dev)
return DMA_BIT_MASK(64);
}
 
-   return dma_iommu_ops.get_required_mask(dev);
+   return dma_iommu_get_required_mask(dev);
 }
 
 static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,
-- 
2.20.1



[PATCH 06/32] powerpc/pseries: use the generic iommu bypass code

2019-02-12 Thread Christoph Hellwig
Use the generic iommu bypass code instead of overriding set_dma_mask.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/platforms/pseries/iommu.c | 100 +++--
 1 file changed, 27 insertions(+), 73 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/iommu.c 
b/arch/powerpc/platforms/pseries/iommu.c
index 9f7ac75c5687..37d2ce3f55a3 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -978,7 +978,7 @@ static phys_addr_t ddw_memory_hotplug_max(void)
  * pdn: the parent pe node with the ibm,dma_window property
  * Future: also check if we can remap the base window for our base page size
  *
- * returns the dma offset for use by dma_set_mask
+ * returns the dma offset for use by the direct mapped DMA code.
  */
 static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
 {
@@ -1198,87 +1198,40 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev 
*dev)
iommu_add_device(pci->table_group, &dev->dev);
 }
 
-static int dma_set_mask_pSeriesLP(struct device *dev, u64 dma_mask)
+static bool iommu_bypass_supported_pSeriesLP(struct pci_dev *pdev, u64 
dma_mask)
 {
-   bool ddw_enabled = false;
-   struct device_node *pdn, *dn;
-   struct pci_dev *pdev;
+   struct device_node *dn = pci_device_to_OF_node(pdev), *pdn;
const __be32 *dma_window = NULL;
u64 dma_offset;
 
-   if (!dev->dma_mask)
-   return -EIO;
-
-   if (!dev_is_pci(dev))
-   goto check_mask;
-
-   pdev = to_pci_dev(dev);
-
/* only attempt to use a new window if 64-bit DMA is requested */
-   if (!disable_ddw && dma_mask == DMA_BIT_MASK(64)) {
-   dn = pci_device_to_OF_node(pdev);
-   dev_dbg(dev, "node is %pOF\n", dn);
+   if (dma_mask < DMA_BIT_MASK(64))
+   return false;
 
-   /*
-* the device tree might contain the dma-window properties
-* per-device and not necessarily for the bus. So we need to
-* search upwards in the tree until we either hit a dma-window
-* property, OR find a parent with a table already allocated.
-*/
-   for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->table_group;
-   pdn = pdn->parent) {
-   dma_window = of_get_property(pdn, "ibm,dma-window", 
NULL);
-   if (dma_window)
-   break;
-   }
-   if (pdn && PCI_DN(pdn)) {
-   dma_offset = enable_ddw(pdev, pdn);
-   if (dma_offset != 0) {
-   dev_info(dev, "Using 64-bit direct DMA at 
offset %llx\n", dma_offset);
-   set_dma_offset(dev, dma_offset);
-   set_dma_ops(dev, &dma_nommu_ops);
-   ddw_enabled = true;
-   }
-   }
-   }
+   dev_dbg(&pdev->dev, "node is %pOF\n", dn);
 
-   /* fall back on iommu ops */
-   if (!ddw_enabled && get_dma_ops(dev) != &dma_iommu_ops) {
-   dev_info(dev, "Restoring 32-bit DMA via iommu\n");
-   set_dma_ops(dev, &dma_iommu_ops);
+   /*
+* the device tree might contain the dma-window properties
+* per-device and not necessarily for the bus. So we need to
+* search upwards in the tree until we either hit a dma-window
+* property, OR find a parent with a table already allocated.
+*/
+   for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->table_group;
+   pdn = pdn->parent) {
+   dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
+   if (dma_window)
+   break;
}
 
-check_mask:
-   if (!dma_supported(dev, dma_mask))
-   return -EIO;
-
-   *dev->dma_mask = dma_mask;
-   return 0;
-}
-
-static u64 dma_get_required_mask_pSeriesLP(struct device *dev)
-{
-   if (!dev->dma_mask)
-   return 0;
-
-   if (!disable_ddw && dev_is_pci(dev)) {
-   struct pci_dev *pdev = to_pci_dev(dev);
-   struct device_node *dn;
-
-   dn = pci_device_to_OF_node(pdev);
-
-   /* search upwards for ibm,dma-window */
-   for (; dn && PCI_DN(dn) && !PCI_DN(dn)->table_group;
-   dn = dn->parent)
-   if (of_get_property(dn, "ibm,dma-window", NULL))
-   break;
-   /* if there is a ibm,ddw-applicable property require 64 bits */
-   if (dn && PCI_DN(dn) &&
-   of_get_property(dn, "ibm,ddw-applicable", NULL))
-   return DMA_BIT_MASK(64);
+   if (pdn && PCI_DN(pdn)) {
+   dma_offset = enable_ddw(pdev, pdn);
+   if (dma_offset != 0) {
+ 

Re: [PATCH] iio/gyro/bmg160: Use millidegrees for temperature scale

2019-02-12 Thread Mike Looijmans
On 12-02-19 18:00, Tomasz Duszynski wrote:
> On Tue, Feb 12, 2019 at 03:25:49PM +0100, Mike Looijmans wrote:
>> Standard unit for temperature is millidegrees Celcius, whereas this driver
>> was reporting in degrees. Fix the scale factor in the driver.
>>
>> Signed-off-by: Mike Looijmans 
>> ---
>>   drivers/iio/gyro/bmg160_core.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
>> index 63ca316..ad7f8cb 100644
>> --- a/drivers/iio/gyro/bmg160_core.c
>> +++ b/drivers/iio/gyro/bmg160_core.c
>> @@ -585,8 +585,9 @@ static int bmg160_read_raw(struct iio_dev *indio_dev,
>>  *val = 0;
>>  switch (chan->type) {
>>  case IIO_TEMP:
>> -*val2 = 50;
>> -return IIO_VAL_INT_PLUS_MICRO;
>> +*val = 500;
>> +*val2 = 0;
>> +return IIO_VAL_INT;
> 
> You are returning integer type to iio so there's no point in touching
> val2. iio will ignore it anyway.

Indeed, I'll post a v2 for that.

> 
>>  case IIO_ANGL_VEL:
>>  {
>>  int i;
>> --
>> 1.9.1
>>



Re: [RESEND PATCH v2] of: fix kmemleak crash caused by imbalance in early memory reservation

2019-02-12 Thread Mike Rapoport
On Tue, Feb 12, 2019 at 04:12:24PM -0600, Rob Herring wrote:
> On Tue, Feb 12, 2019 at 3:50 PM Stephen Rothwell  
> wrote:
> >
> > Hi all,
> >
> > On Tue, 12 Feb 2019 10:03:09 -0600 Rob Herring  wrote:
> > >
> > > On Mon, Feb 11, 2019 at 10:47 AM Marc Gonzalez  
> > > wrote:
> > > >
> > > > On 04/02/2019 15:37, Marc Gonzalez wrote:
> > > >
> > > > > Cc: sta...@vger.kernel.org # 3.15+
> > > > > Fixes: 3f0c820664483 ("drivers: of: add initialization code for 
> > > > > dynamic reserved memory")
> > > > > Acked-by: Marek Szyprowski 
> > > > > Acked-by: Prateek Patel 
> > > > > Tested-by: Marc Gonzalez 
> > > > > Signed-off-by: Mike Rapoport 
> > > > > ---
> > > > > Resend with DT CCed to reach robh's patch queue
> > > > > I added CC: stable, Fixes, and Prateek's ack
> > > > > Trim recipients list to minimize inconvenience
> > > >
> > > > I'm confused over commit 3532b3b554a216f30edb841d29eef48521bdc592 in 
> > > > linux-next
> > > > "memblock: drop __memblock_alloc_base()"
> > > >
> > > > It's definitely going to conflict with the proposed patch
> > > > over drivers/of/of_reserved_mem.c
> > > >
> > > > Rob, what's the next step then?
> > >
> > > Rebase it on top of what's in linux-next and apply it to the tree
> > > which has the above dependency. I'm guessing that is Andrew Morton's
> > > tree.
> >
> > Yeah, that is in Andrew's "post linux-next" patch series, so if you
> > rebase it on top of linux-next and then send it to Andrew with some
> > explanation.
> >
> > ...
> >
> > Actually, if it is intended for the stable trees, then presumably it is
> > intended to go to Linus for the current release?  In which case, the
> > patch in Andrew's tree will have to be changed to cope after your patch
> > appears in Linus' tree (and therefore, linux-next).
> 
> At this point in the cycle, I wasn't planning to send this for 5.0.
> It's not fixing something introduced in 5.0 and it is a debug feature.
 
Below is the version vs. current mmotm.

>From 9ea6dceb46067d4f1cbbdbec1189c8496aa0a4bc Mon Sep 17 00:00:00 2001
From: Mike Rapoport 
Date: Mon, 4 Feb 2019 15:37:21 +0100
Subject: [PATCH] of: fix kmemleak crash caused by imbalance in early memory
 reservation

Marc Gonzalez reported the following kmemleak crash:

Unable to handle kernel paging request at virtual address ffc021e0
Mem abort info:
  ESR = 0x9606
  Exception class = DABT (current EL), IL = 32 bits
  SET = 0, FnV = 0
  EA = 0, S1PTW = 0
Data abort info:
  ISV = 0, ISS = 0x0006
  CM = 0, WnR = 0
swapper pgtable: 4k pages, 39-bit VAs, pgdp = (ptrval)
[ffc021e0] pgd=00017e3ba803, pud=00017e3ba803,
pmd=
Internal error: Oops: 9606 [#1] PREEMPT SMP
Modules linked in:
CPU: 6 PID: 523 Comm: kmemleak Tainted: G S  W 5.0.0-rc1 #13
Hardware name: Qualcomm Technologies, Inc. MSM8998 v1 MTP (DT)
pstate: 8085 (Nzcv daIf -PAN -UAO)
pc : scan_block+0x70/0x190
lr : scan_block+0x6c/0x190
sp : ff8012e8bd20
x29: ff8012e8bd20 x28: ffc0fdbaf018
x27: ffc02200 x26: 0080
x25: ff8011aadf70 x24: ffc0f8cc8000
x23: ff8010dc8000 x22: ff8010dc8830
x21: ffc021e00ff9 x20: ffc0f8cc8050
x19: ffc021e0 x18: 2409
x17: 0200 x16: 
x15: ff8010e14dd8 x14: 2406
x13: 4c4dd0c6 x12: ffc0f77dad58
x11: 0001 x10: ff8010d9e688
x9 : ff8010d9f000 x8 : ff8010d9e688
x7 : 0002 x6 : 
x5 : ff8011511c20 x4 : 26d1
x3 : ff8010e14d88 x2 : 5b36396f4e7d4000
x1 : 00208040 x0 : 
Process kmemleak (pid: 523, stack limit = 0x(ptrval))
Call trace:
 scan_block+0x70/0x190
 scan_gray_list+0x108/0x1c0
 kmemleak_scan+0x33c/0x7c0
 kmemleak_scan_thread+0x98/0xf0
 kthread+0x11c/0x120
 ret_from_fork+0x10/0x1c
Code: f9000fb4 d503201f 97d2 35000580 (f9400260)
---[ end trace 176d6ed9d86a0c33 ]---
note: kmemleak[523] exited with preempt_count 2

The crash happens when a no-map area is allocated in
early_init_dt_alloc_reserved_memory_arch(). The allocated region is
registered with kmemleak, but it is then removed from memblock using
memblock_remove() that is not kmemleak-aware.

Replacing __memblock_alloc_base() with memblock_find_in_range() makes sure
that the allocated memory is not added to kmemleak and then
memblock_remove()'ing this memory is safe.

As a bonus, since memblock_find_in_range() ensures the allocation in the
specified range, the bounds check can be removed.

Cc: sta...@vger.kernel.org # 3.15+
Fixes: 3f0c820664483 ("drivers: of: add initialization code for dynamic 
reserved memory")
Acked-by: Marek Szyprowski 
Acked-by: Prateek Patel 
Tested-by: Marc Gonzalez 
Signed-off-by: Mike Rapoport 
---
 drivers/of/of_reserved_mem.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 78aa9eb..47971ab 100644
--- a/drivers/of/of_r

Re: [PATCH] fat: enable .splice_write to support splice on O_DIRECT file

2019-02-12 Thread Hou Tao
ping ?

On 2019/2/10 17:47, Hou Tao wrote:
> Now splice() on O_DIRECT-opened fat file will return -EFAULT, that is
> because the default .splice_write, namely default_file_splice_write(),
> will construct an ITER_KVEC iov_iter and dio_refill_pages() in dio path
> can not handle it.
> 
> Fix it by implementing .splice_write through iter_file_splice_write().
> 
> Spotted by xfs-tests generic/091.
> 
> Signed-off-by: Hou Tao 
> ---
>  fs/fat/file.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/fat/file.c b/fs/fat/file.c
> index 13935ee99e1e..b3bed32946b1 100644
> --- a/fs/fat/file.c
> +++ b/fs/fat/file.c
> @@ -214,6 +214,7 @@ const struct file_operations fat_file_operations = {
>  #endif
>   .fsync  = fat_file_fsync,
>   .splice_read= generic_file_splice_read,
> + .splice_write   = iter_file_splice_write,
>   .fallocate  = fat_fallocate,
>  };
>  
> 



Re: [PATCH 1/1] tracing: Fix event_trace_printk loss on printk_format.

2019-02-12 Thread Mars Cheng
Hi Steve

On Wed, 2019-02-13 at 12:54 +0800, Mars Cheng wrote:
> Hi Steve
> 
> On Tue, 2019-02-12 at 20:41 -0500, Steven Rostedt wrote:
> > On Tue, 12 Feb 2019 19:41:57 +0800
> > Mars Cheng  wrote:
> > 
> > > From: Andress Kuo 
> > > 
> > > If fmt on event_trace_printk is not a constant, It means that something 
> > > not
> > > guaranteed, so the compiler optimizes the fmt out, and then the
> > > __trace_printk_fmt section is not filled. if __trace_printk_fmt is not
> > > filled, the kernel will not allocate the special buffers needed for the
> > > event_trace_printk() and then not shown in the file output
> > > sys/kernel/debug/tracing/print_formats.
> > > 
> > > Adding a "__used" to the variable in the __trace_printk_fmt section on
> > > event_trace_printk() will keep it around, even though it is set to NULL.
> > > This will keep the string from being printed in the
> > > sys/kernel/debug/tracing/printk_formats section.
> > > 
> > > We can also refer to commit 3debb0a9ddb1 ("tracing: Fix trace_printk()
> > > to print when not using bprintk()")that it had similar issue on path of
> > > trace_printk().
> > 
> > Honestly, I don't even remember why that macro was created. I think
> > it's a remnant from the creation of the trace events. I think the best
> > solution is just to nuke it. It shouldn't be used anymore.
> > 
> > I'll dig a bit deeper into the history of that macro, but I'm thinking
> > it shouldn't exist anymore.
> > 
> > [ /me returns from walking down memory lane ]
> > 
> > Wow, that brings back some wild memories. Yes, that macro must die, and
> > I wish the history of it could die along with it ;-) The horror of the
> > old ways I tell you. The event_trace_printk() was the original way we
> > displayed events! No real formatting, no parsing my userspace tools. It
> > was just a glamorized printk. It was called TRACE_FORMAT() which was
> > deprecated by today's TRACE_EVENT().
> > 
> > That macro should have been removed by commit b8e65554d80b4.
> > 
> > Please just send a patch to delete that macro. Let's not be maintaining
> > it. It gives me nightmares.
> > 
> > -- Steve
> 
> Got it, I will send another patch to remove the nightmares. :-)
> 
> Thanks.

After some grep, I found event_trace_printk() not used in 5.0-rc*. But
trace_printk() is still used in several places.

kernel/trace/ring_buffer_benchmark.c:415: trace_printk("Sleeping for 10
secs\n");
...
drivers/gpu/drm/i915/i915_gem.h:66:#define GEM_TRACE(...)
trace_printk(__VA_ARGS__)
drivers/hwtracing/stm/dummy_stm.c:30:   trace_printk("[%u:%u] [pkt: %x/%
x] (%llx)\n", master, channel,
...

since they are similar functions, do you prefer remove both of them or
just remove event_trace_printk()? the former approach might affect some
modules, and the latter approach keeps nightmares, right?

Thanks.
> 




linux-next: manual merge of the akpm tree with the tip tree

2019-02-12 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the akpm tree got a conflict in:

  scripts/atomic/check-atomics.sh

between commit:

  4ad119545d78 ("locking/atomics: Check atomic headers with sha1sum")

from the tip tree and patch:

  "scripts/atomic/check-atomics.sh: don't assume that scripts are executable"

from the akpm tree.

I fixed it up (this latter patch is now needed against the new
scripts/atomic/gen-atomics.sh instead) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell


pgp7RiDYvKdIH.pgp
Description: OpenPGP digital signature


Re: [PATCH -next] ASoC: cros_ec_codec: Make symbol 'cros_ec_dai' static

2019-02-12 Thread Cheng-yi Chiang
On Wed, Feb 13, 2019 at 2:16 PM Wei Yongjun  wrote:
>
> Fixes the following sparse warning:
>
> sound/soc/codecs/cros_ec_codec.c:209:27: warning:
>  symbol 'cros_ec_dai' was not declared. Should it be static?
>
> Fixes: b291f42a3718 ("ASoC: cros_ec_codec: Add codec driver for Cros EC")
> Signed-off-by: Wei Yongjun 
> ---
>  sound/soc/codecs/cros_ec_codec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/soc/codecs/cros_ec_codec.c 
> b/sound/soc/codecs/cros_ec_codec.c
> index b14100b6a939..99a3af8a15ff 100644
> --- a/sound/soc/codecs/cros_ec_codec.c
> +++ b/sound/soc/codecs/cros_ec_codec.c
> @@ -206,7 +206,7 @@ static const struct snd_soc_dai_ops cros_ec_i2s_dai_ops = 
> {
> .set_fmt = cros_ec_i2s_set_dai_fmt,
>  };
>
> -struct snd_soc_dai_driver cros_ec_dai[] = {
> +static struct snd_soc_dai_driver cros_ec_dai[] = {
> {
> .name = "cros_ec_codec I2S",
> .id = 0,
>
>
>
Hi Wei,
  Yes you are right. Thanks for the fix!


Re: [v4 PATCH 6/8] clocksource/drivers/riscv: Add required checks during clock source init

2019-02-12 Thread Anup Patel
On Tue, Feb 12, 2019 at 4:40 PM Atish Patra  wrote:
>
> Currently, clocksource registration happens for an invalid cpu for
> non-smp kernels. This lead to kernel panic as cpu hotplug registration
> will fail for those cpus. Moreover, riscv_hartid_to_cpuid can return
> errors now.
>
> Do not proceed if hartid or cpuid is invalid. Take this opprtunity to

s/opprtunity/opportunity

Otherwise, looks good to me.

Reviewed-by: Anup Patel 

Regards,
Anup


Re: [PATCH v4 6/6] RISC-V: Free-up initrd in free_initrd_mem()

2019-02-12 Thread Christoph Hellwig
On Wed, Feb 13, 2019 at 06:32:24AM +, Anup Patel wrote:
> index 9cd583b6d1cd..c22b873de856 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -97,8 +97,9 @@ static void __init setup_initrd(void)
>   initrd_end = 0;
>  }
>  
> -void free_initrd_mem(unsigned long start, unsigned long end)
> +void __init free_initrd_mem(unsigned long start, unsigned long end)
>  {
> + memblock_free(__pa(start), end - start);

I'm pretty sure this should be a call to free_reserved_area instead.

All regions reserved using memblock_reserved and not freed before
initializing the MM are marked reserved and don't have valid page
counts, etc.

So we need the actions in free_reserved_area to actually make the
memory useful.  Now every other architecture except for arm64
seems to do fine without a memblock_free.  I'm not an expert on
memblock (but I've CCed one), but I guess the reason is that once
the kernel has booted we don't really care about freeing memblock
area.


Re: [PATCH] printk: add KERN_NOTIME to skip the timestamp

2019-02-12 Thread Sergey Senozhatsky
On (02/13/19 15:29), Sergey Senozhatsky wrote:
>
> cat /sys/module/printk/parameters/time ?
 ^
cat / echo

Works both ways.

-ss


[PATCH] arm/mach-at91/pm : fix possible object reference leak

2019-02-12 Thread Peng Hao
of_find_device_by_node() takes a reference to the struct device
when it finds a match via get_device. When returning error we should
call put_device.

Signed-off-by: Peng Hao 
---
 arch/arm/mach-at91/pm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index 51e808a..70fadb7 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -621,6 +621,7 @@ static int __init at91_pm_backup_init(void)
 
 securam_fail:
iounmap(pm_data.sfrbu);
+   put_device(&pdev->dev);
pm_data.sfrbu = NULL;
return ret;
 }
-- 
1.8.3.1



[PATCH v4 5/6] RISC-V: Implement compile-time fixed mappings

2019-02-12 Thread Anup Patel
This patch implements compile-time virtual to physical mappings. These
compile-time fixed mappings can be used by earlycon, ACPI, and early
ioremap for creating fixed mappings when FIX_EARLYCON_MEM=y.

To start with, we have enabled compile-time fixed mappings for earlycon.

Signed-off-by: Anup Patel 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Palmer Dabbelt 
---
 arch/riscv/Kconfig  |  3 +++
 arch/riscv/include/asm/fixmap.h | 44 +
 arch/riscv/mm/init.c| 34 +
 3 files changed, 81 insertions(+)
 create mode 100644 arch/riscv/include/asm/fixmap.h

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 515fc3cc9687..3cfd10d35a28 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -89,6 +89,9 @@ config GENERIC_CSUM
 config GENERIC_HWEIGHT
def_bool y
 
+config FIX_EARLYCON_MEM
+   def_bool y
+
 config PGTABLE_LEVELS
int
default 3 if 64BIT
diff --git a/arch/riscv/include/asm/fixmap.h b/arch/riscv/include/asm/fixmap.h
new file mode 100644
index ..57afe604b495
--- /dev/null
+++ b/arch/riscv/include/asm/fixmap.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2019 Western Digital Corporation or its affiliates.
+ */
+
+#ifndef _ASM_RISCV_FIXMAP_H
+#define _ASM_RISCV_FIXMAP_H
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Here we define all the compile-time 'special' virtual addresses.
+ * The point is to have a constant address at compile time, but to
+ * set the physical address only in the boot process.
+ *
+ * These 'compile-time allocated' memory buffers are page-sized. Use
+ * set_fixmap(idx,phys) to associate physical memory with fixmap indices.
+ */
+enum fixed_addresses {
+   FIX_HOLE,
+   FIX_EARLYCON_MEM_BASE,
+   __end_of_fixed_addresses
+};
+
+#define FIXADDR_SIZE   (__end_of_fixed_addresses * PAGE_SIZE)
+#define FIXADDR_TOP(PAGE_OFFSET)
+#define FIXADDR_START  (FIXADDR_TOP - FIXADDR_SIZE)
+
+#define FIXMAP_PAGE_IO PAGE_KERNEL
+
+#define __early_set_fixmap __set_fixmap
+
+#define __late_set_fixmap  __set_fixmap
+#define __late_clear_fixmap(idx) __set_fixmap((idx), 0, FIXMAP_PAGE_CLEAR)
+
+extern void __set_fixmap(enum fixed_addresses idx,
+phys_addr_t phys, pgprot_t prot);
+
+#include 
+
+#endif /* _ASM_RISCV_FIXMAP_H */
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 7ed6ae90cf6b..efcbdb9b3da3 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -111,8 +112,28 @@ pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata 
__aligned(PAGE_SIZE);
 #define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
 pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
 pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
+pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
 #endif
 
+pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
+
+void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
+{
+   unsigned long addr = __fix_to_virt(idx);
+   pte_t *ptep;
+
+   BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
+
+   ptep = &fixmap_pte[pte_index(addr)];
+
+   if (pgprot_val(prot)) {
+   set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
+   } else {
+   pte_clear(&init_mm, addr, ptep);
+   local_flush_tlb_page(addr);
+   }
+}
+
 asmlinkage void __init setup_vm(void)
 {
extern char _start;
@@ -135,20 +156,33 @@ asmlinkage void __init setup_vm(void)
 
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
+
swapper_pg_dir[o] =
pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
__pgprot(_PAGE_TABLE));
}
for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
+
+   swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] =
+   pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pmd),
+   __pgprot(_PAGE_TABLE));
+   fixmap_pmd[(FIXADDR_START >> PMD_SHIFT) % PTRS_PER_PMD] =
+   pfn_pmd(PFN_DOWN((uintptr_t)fixmap_pte),
+   __pgprot(_PAGE_TABLE));
 #else
trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
pfn_pgd(PFN_DOWN(pa), prot);
 
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
+
swapper_pg_dir[o] =
pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
}
+
+   swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] =
+   pfn_pgd(PFN_DOWN((uint

[PATCH v4 2/6] RISC-V: Setup init_mm before parse_early_param()

2019-02-12 Thread Anup Patel
We should setup init_mm before doing parse_early_param() in setup_arch()
to be consistent with setup_arch() of other architectures such as x86,
ARM, and ARM64.

Signed-off-by: Anup Patel 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Palmer Dabbelt 
---
 arch/riscv/kernel/setup.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 36f60b4d2147..9e6395b7d409 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -208,15 +208,15 @@ static void __init setup_bootmem(void)
 
 void __init setup_arch(char **cmdline_p)
 {
-   *cmdline_p = boot_command_line;
-
-   parse_early_param();
-
init_mm.start_code = (unsigned long) _stext;
init_mm.end_code   = (unsigned long) _etext;
init_mm.end_data   = (unsigned long) _edata;
init_mm.brk= (unsigned long) _end;
 
+   *cmdline_p = boot_command_line;
+
+   parse_early_param();
+
setup_bootmem();
paging_init();
unflatten_device_tree();
@@ -235,4 +235,3 @@ void __init setup_arch(char **cmdline_p)
 
riscv_fill_hwcap();
 }
-
-- 
2.17.1



[PATCH v4 4/6] RISC-V: Move setup_vm() to mm/init.c

2019-02-12 Thread Anup Patel
The setup_vm() is responsible for setting up initial page table hence
should be placed in mm/init.c.

Signed-off-by: Anup Patel 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Palmer Dabbelt 
---
 arch/riscv/kernel/setup.c | 49 ---
 arch/riscv/mm/init.c  | 49 +++
 2 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index ab29a66a17fc..9cd583b6d1cd 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -102,55 +102,6 @@ void free_initrd_mem(unsigned long start, unsigned long 
end)
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
 
-pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
-pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
-
-#ifndef __PAGETABLE_PMD_FOLDED
-#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
-pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
-pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
-#endif
-
-asmlinkage void __init setup_vm(void)
-{
-   extern char _start;
-   uintptr_t i;
-   uintptr_t pa = (uintptr_t) &_start;
-   pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC);
-
-   va_pa_offset = PAGE_OFFSET - pa;
-   pfn_base = PFN_DOWN(pa);
-
-   /* Sanity check alignment and size */
-   BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
-   BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
-
-#ifndef __PAGETABLE_PMD_FOLDED
-   trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
-   pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd),
-   __pgprot(_PAGE_TABLE));
-   trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
-
-   for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
-   size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
-   swapper_pg_dir[o] =
-   pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
-   __pgprot(_PAGE_TABLE));
-   }
-   for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
-   swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
-#else
-   trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
-   pfn_pgd(PFN_DOWN(pa), prot);
-
-   for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
-   size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
-   swapper_pg_dir[o] =
-   pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
-   }
-#endif
-}
-
 void __init parse_dtb(unsigned int hartid, void *dtb)
 {
if (!early_init_dt_scan(__va(dtb)))
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index a57dba8ac9e7..7ed6ae90cf6b 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -103,3 +103,52 @@ void __init setup_bootmem(void)
  &memblock.memory, 0);
}
 }
+
+pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
+pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
+
+#ifndef __PAGETABLE_PMD_FOLDED
+#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
+pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
+pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
+#endif
+
+asmlinkage void __init setup_vm(void)
+{
+   extern char _start;
+   uintptr_t i;
+   uintptr_t pa = (uintptr_t) &_start;
+   pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC);
+
+   va_pa_offset = PAGE_OFFSET - pa;
+   pfn_base = PFN_DOWN(pa);
+
+   /* Sanity check alignment and size */
+   BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
+   BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
+
+#ifndef __PAGETABLE_PMD_FOLDED
+   trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
+   pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd),
+   __pgprot(_PAGE_TABLE));
+   trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
+
+   for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
+   size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
+   swapper_pg_dir[o] =
+   pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
+   __pgprot(_PAGE_TABLE));
+   }
+   for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
+   swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
+#else
+   trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
+   pfn_pgd(PFN_DOWN(pa), prot);
+
+   for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
+   size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
+   swapper_pg_dir[o] =
+   pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
+   }
+#endif
+}
-- 
2.17.1



[PATCH v4 3/6] RISC-V: Move setup_bootmem() to mm/init.c

2019-02-12 Thread Anup Patel
The setup_bootmem() mainly populates memblocks and does early memory
reservations. The right location for this function is mm/init.c.

Signed-off-by: Anup Patel 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Palmer Dabbelt 
---
 arch/riscv/include/asm/pgtable.h |  1 +
 arch/riscv/kernel/setup.c| 48 
 arch/riscv/mm/init.c | 40 ++
 3 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 16301966d65b..35893810cba3 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -404,6 +404,7 @@ static inline int ptep_clear_flush_young(struct 
vm_area_struct *vma,
 #define kern_addr_valid(addr)   (1) /* FIXME */
 #endif
 
+extern void setup_bootmem(void);
 extern void paging_init(void);
 
 static inline void pgtable_cache_init(void)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 9e6395b7d409..ab29a66a17fc 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -163,49 +163,6 @@ void __init parse_dtb(unsigned int hartid, void *dtb)
 #endif
 }
 
-static void __init setup_bootmem(void)
-{
-   struct memblock_region *reg;
-   phys_addr_t mem_size = 0;
-
-   /* Find the memory region containing the kernel */
-   for_each_memblock(memory, reg) {
-   phys_addr_t vmlinux_end = __pa(_end);
-   phys_addr_t end = reg->base + reg->size;
-
-   if (reg->base <= vmlinux_end && vmlinux_end <= end) {
-   /*
-* Reserve from the start of the region to the end of
-* the kernel
-*/
-   memblock_reserve(reg->base, vmlinux_end - reg->base);
-   mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET);
-   }
-   }
-   BUG_ON(mem_size == 0);
-
-   set_max_mapnr(PFN_DOWN(mem_size));
-   max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());
-
-#ifdef CONFIG_BLK_DEV_INITRD
-   setup_initrd();
-#endif /* CONFIG_BLK_DEV_INITRD */
-
-   early_init_fdt_reserve_self();
-   early_init_fdt_scan_reserved_mem();
-   memblock_allow_resize();
-   memblock_dump_all();
-
-   for_each_memblock(memory, reg) {
-   unsigned long start_pfn = memblock_region_memory_base_pfn(reg);
-   unsigned long end_pfn = memblock_region_memory_end_pfn(reg);
-
-   memblock_set_node(PFN_PHYS(start_pfn),
- PFN_PHYS(end_pfn - start_pfn),
- &memblock.memory, 0);
-   }
-}
-
 void __init setup_arch(char **cmdline_p)
 {
init_mm.start_code = (unsigned long) _stext;
@@ -218,6 +175,11 @@ void __init setup_arch(char **cmdline_p)
parse_early_param();
 
setup_bootmem();
+
+#ifdef CONFIG_BLK_DEV_INITRD
+   setup_initrd();
+#endif /* CONFIG_BLK_DEV_INITRD */
+
paging_init();
unflatten_device_tree();
 
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 504a5e491f5a..a57dba8ac9e7 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -63,3 +64,42 @@ void free_initmem(void)
 {
free_initmem_default(0);
 }
+
+void __init setup_bootmem(void)
+{
+   struct memblock_region *reg;
+   phys_addr_t mem_size = 0;
+
+   /* Find the memory region containing the kernel */
+   for_each_memblock(memory, reg) {
+   phys_addr_t vmlinux_end = __pa(_end);
+   phys_addr_t end = reg->base + reg->size;
+
+   if (reg->base <= vmlinux_end && vmlinux_end <= end) {
+   /*
+* Reserve from the start of the region to the end of
+* the kernel
+*/
+   memblock_reserve(reg->base, vmlinux_end - reg->base);
+   mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET);
+   }
+   }
+   BUG_ON(mem_size == 0);
+
+   set_max_mapnr(PFN_DOWN(mem_size));
+   max_low_pfn = memblock_end_of_DRAM();
+
+   early_init_fdt_reserve_self();
+   early_init_fdt_scan_reserved_mem();
+   memblock_allow_resize();
+   memblock_dump_all();
+
+   for_each_memblock(memory, reg) {
+   unsigned long start_pfn = memblock_region_memory_base_pfn(reg);
+   unsigned long end_pfn = memblock_region_memory_end_pfn(reg);
+
+   memblock_set_node(PFN_PHYS(start_pfn),
+ PFN_PHYS(end_pfn - start_pfn),
+ &memblock.memory, 0);
+   }
+}
-- 
2.17.1



[PATCH v4 6/6] RISC-V: Free-up initrd in free_initrd_mem()

2019-02-12 Thread Anup Patel
We should free-up initrd memory in free_initrd_mem() instead
of doing nothing.

Signed-off-by: Anup Patel 
---
 arch/riscv/kernel/setup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 9cd583b6d1cd..c22b873de856 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -97,8 +97,9 @@ static void __init setup_initrd(void)
initrd_end = 0;
 }
 
-void free_initrd_mem(unsigned long start, unsigned long end)
+void __init free_initrd_mem(unsigned long start, unsigned long end)
 {
+   memblock_free(__pa(start), end - start);
 }
 #endif /* CONFIG_BLK_DEV_INITRD */
 
-- 
2.17.1



[PATCH v4 1/6] RISC-V: Move free_initrd_mem() to kernel/setup.c

2019-02-12 Thread Anup Patel
We move free_initrd_mem() to kernel/setup.c so that all initrd related
functions are in one place.

Signed-off-by: Anup Patel 
Reviewed-by: Christoph Hellwig 
Reviewed-by: Palmer Dabbelt 
---
 arch/riscv/kernel/setup.c | 4 
 arch/riscv/mm/init.c  | 7 ---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 77564310235f..36f60b4d2147 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -96,6 +96,10 @@ static void __init setup_initrd(void)
initrd_start = 0;
initrd_end = 0;
 }
+
+void free_initrd_mem(unsigned long start, unsigned long end)
+{
+}
 #endif /* CONFIG_BLK_DEV_INITRD */
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 658ebf645f42..504a5e491f5a 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -14,7 +14,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -64,9 +63,3 @@ void free_initmem(void)
 {
free_initmem_default(0);
 }
-
-#ifdef CONFIG_BLK_DEV_INITRD
-void free_initrd_mem(unsigned long start, unsigned long end)
-{
-}
-#endif /* CONFIG_BLK_DEV_INITRD */
-- 
2.17.1



[PATCH v4 0/6] Fixmap support and MM cleanups

2019-02-12 Thread Anup Patel
This patchset does:
1. Moves MM related code from kernel/setup.c to mm/init.c
2. Implements compile-time fixed mappings

Using fixed mappings available, we can now get earlyprints
even without SBI calls. For example, we can use kernel
parameter "earlycon=uart8250,mmio,0x1000" to get early
prints on QEMU virt machine without using SBI calls.

The patchset is tested on QEMU virt machine. It is based on
Linux-5.0-rc6 and can be found at riscv_fixmap_v4 branch of:
https://github.com/avpatel/linux.git.

Changes since v3:
 - Re-worked and simplified PATCH6

Changes since v2:
 - Fixed commit description of PATCH6
 - Ensured commit description of all PATCH use upto 72
   characters per line

Changes since v1:
 - Use more characters per line in changelog of PATCH3
 - Removed #ifndef __ASSEMBLY__ from PATCH5
 - Use more characters per line in commets of PATCH5
 - Added PATCH6 to implement keepinitrd kernel parameter

Anup Patel (6):
  RISC-V: Move free_initrd_mem() to kernel/setup.c
  RISC-V: Setup init_mm before parse_early_param()
  RISC-V: Move setup_bootmem() to mm/init.c
  RISC-V: Move setup_vm() to mm/init.c
  RISC-V: Implement compile-time fixed mappings
  RISC-V: Free-up initrd in free_initrd_mem()

 arch/riscv/Kconfig   |   3 +
 arch/riscv/include/asm/fixmap.h  |  44 +++
 arch/riscv/include/asm/pgtable.h |   1 +
 arch/riscv/kernel/setup.c| 107 +++---
 arch/riscv/mm/init.c | 124 ++-
 5 files changed, 180 insertions(+), 99 deletions(-)
 create mode 100644 arch/riscv/include/asm/fixmap.h

-- 
2.17.1



  1   2   3   4   5   6   7   8   9   10   >