[PATCH] [media] drxd: Use kmemdup rather than duplicating its implementation

2011-11-18 Thread Thomas Meyer
The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer tho...@m3y3r.de
---

diff -u -p a/drivers/media/dvb/frontends/drxd_hard.c 
b/drivers/media/dvb/frontends/drxd_hard.c
--- a/drivers/media/dvb/frontends/drxd_hard.c 2011-11-07 19:37:48.623295422 
+0100
+++ b/drivers/media/dvb/frontends/drxd_hard.c 2011-11-08 10:48:49.317800208 
+0100
@@ -914,14 +914,13 @@ static int load_firmware(struct drxd_sta
return -EIO;
}
 
-   state-microcode = kmalloc(fw-size, GFP_KERNEL);
+   state-microcode = kmemdup(fw-data, fw-size, GFP_KERNEL);
if (state-microcode == NULL) {
release_firmware(fw);
printk(KERN_ERR drxd: firmware load failure: no memory\n);
return -ENOMEM;
}
 
-   memcpy(state-microcode, fw-data, fw-size);
state-microcode_length = fw-size;
release_firmware(fw);
return 0;
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] dw2102: Use kmemdup rather than duplicating its implementation

2011-11-18 Thread Thomas Meyer
The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer tho...@m3y3r.de
---

diff -u -p a/drivers/media/dvb/dvb-usb/dw2102.c 
b/drivers/media/dvb/dvb-usb/dw2102.c
--- a/drivers/media/dvb/dvb-usb/dw2102.c 2011-11-07 19:37:48.086620605 +0100
+++ b/drivers/media/dvb/dvb-usb/dw2102.c 2011-11-08 10:48:56.977902892 +0100
@@ -1859,12 +1859,11 @@ static struct dvb_usb_device_properties
 static int dw2102_probe(struct usb_interface *intf,
const struct usb_device_id *id)
 {
-   p1100 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
+   p1100 = kmemdup(s6x0_properties,
+   sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
if (!p1100)
return -ENOMEM;
/* copy default structure */
-   memcpy(p1100, s6x0_properties,
-   sizeof(struct dvb_usb_device_properties));
/* fill only different fields */
p1100-firmware = dvb-usb-p1100.fw;
p1100-devices[0] = d1100;
@@ -1872,13 +1871,12 @@ static int dw2102_probe(struct usb_inter
p1100-rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
p1100-adapter-fe[0].frontend_attach = stv0288_frontend_attach;
 
-   s660 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
+   s660 = kmemdup(s6x0_properties,
+  sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
if (!s660) {
kfree(p1100);
return -ENOMEM;
}
-   memcpy(s660, s6x0_properties,
-   sizeof(struct dvb_usb_device_properties));
s660-firmware = dvb-usb-s660.fw;
s660-num_device_descs = 3;
s660-devices[0] = d660;
@@ -1886,14 +1884,13 @@ static int dw2102_probe(struct usb_inter
s660-devices[2] = d480_2;
s660-adapter-fe[0].frontend_attach = ds3000_frontend_attach;
 
-   p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
+   p7500 = kmemdup(s6x0_properties,
+   sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
if (!p7500) {
kfree(p1100);
kfree(s660);
return -ENOMEM;
}
-   memcpy(p7500, s6x0_properties,
-   sizeof(struct dvb_usb_device_properties));
p7500-firmware = dvb-usb-p7500.fw;
p7500-devices[0] = d7500;
p7500-rc.legacy.rc_map_table = rc_map_tbs_table;
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] v4l: Casting (void *) value returned by kmalloc is useless

2011-11-18 Thread Thomas Meyer
The semantic patch that makes this change is available
in scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci.

Signed-off-by: Thomas Meyer tho...@m3y3r.de
---

diff -u -p a/drivers/media/video/vino.c b/drivers/media/video/vino.c
--- a/drivers/media/video/vino.c 2011-11-07 19:37:51.673341747 +0100
+++ b/drivers/media/video/vino.c 2011-11-08 09:05:04.618617718 +0100
@@ -708,7 +708,7 @@ static int vino_allocate_buffer(struct v
size, count);
 
/* allocate memory for table with virtual (page) addresses */
-   fb-desc_table.virtual = (unsigned long *)
+   fb-desc_table.virtual =
kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
if (!fb-desc_table.virtual)
return -ENOMEM;
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] cx25821: Use kmemdup rather than duplicating its implementation

2011-11-18 Thread Thomas Meyer
The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer tho...@m3y3r.de
---

diff -u -p a/drivers/media/video/cx25821/cx25821-audio-upstream.c 
b/drivers/media/video/cx25821/cx25821-audio-upstream.c
--- a/drivers/media/video/cx25821/cx25821-audio-upstream.c 2011-11-07 
19:37:49.746645818 +0100
+++ b/drivers/media/video/cx25821/cx25821-audio-upstream.c 2011-11-08 
10:47:22.883308220 +0100
@@ -739,25 +739,22 @@ int cx25821_audio_upstream_init(struct c
 
if (dev-input_audiofilename) {
str_length = strlen(dev-input_audiofilename);
-   dev-_audiofilename = kmalloc(str_length + 1, GFP_KERNEL);
+   dev-_audiofilename = kmemdup(dev-input_audiofilename,
+ str_length + 1, GFP_KERNEL);
 
if (!dev-_audiofilename)
goto error;
 
-   memcpy(dev-_audiofilename, dev-input_audiofilename,
-  str_length + 1);
-
/* Default if filename is empty string */
if (strcmp(dev-input_audiofilename, ) == 0)
dev-_audiofilename = /root/audioGOOD.wav;
} else {
str_length = strlen(_defaultAudioName);
-   dev-_audiofilename = kmalloc(str_length + 1, GFP_KERNEL);
+   dev-_audiofilename = kmemdup(_defaultAudioName,
+ str_length + 1, GFP_KERNEL);
 
if (!dev-_audiofilename)
goto error;
-
-   memcpy(dev-_audiofilename, _defaultAudioName, str_length + 1);
}
 
retval = cx25821_sram_channel_setup_upstream_audio(dev, sram_ch,
diff -u -p a/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c 
b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c
--- a/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c 2011-11-07 
19:37:49.756645970 +0100
+++ b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c 2011-11-08 
10:47:21.626624708 +0100
@@ -761,22 +761,18 @@ int cx25821_vidupstream_init_ch2(struct
 
if (dev-input_filename_ch2) {
str_length = strlen(dev-input_filename_ch2);
-   dev-_filename_ch2 = kmalloc(str_length + 1, GFP_KERNEL);
+   dev-_filename_ch2 = kmemdup(dev-input_filename_ch2,
+str_length + 1, GFP_KERNEL);
 
if (!dev-_filename_ch2)
goto error;
-
-   memcpy(dev-_filename_ch2, dev-input_filename_ch2,
-  str_length + 1);
} else {
str_length = strlen(dev-_defaultname_ch2);
-   dev-_filename_ch2 = kmalloc(str_length + 1, GFP_KERNEL);
+   dev-_filename_ch2 = kmemdup(dev-_defaultname_ch2,
+str_length + 1, GFP_KERNEL);
 
if (!dev-_filename_ch2)
goto error;
-
-   memcpy(dev-_filename_ch2, dev-_defaultname_ch2,
-  str_length + 1);
}
 
/* Default if filename is empty string */
diff -u -p a/drivers/media/video/cx25821/cx25821-video-upstream.c 
b/drivers/media/video/cx25821/cx25821-video-upstream.c
--- a/drivers/media/video/cx25821/cx25821-video-upstream.c 2011-11-07 
19:37:49.756645970 +0100
+++ b/drivers/media/video/cx25821/cx25821-video-upstream.c 2011-11-08 
10:47:22.036630204 +0100
@@ -816,20 +816,18 @@ int cx25821_vidupstream_init_ch1(struct
 
if (dev-input_filename) {
str_length = strlen(dev-input_filename);
-   dev-_filename = kmalloc(str_length + 1, GFP_KERNEL);
+   dev-_filename = kmemdup(dev-input_filename, str_length + 1,
+GFP_KERNEL);
 
if (!dev-_filename)
goto error;
-
-   memcpy(dev-_filename, dev-input_filename, str_length + 1);
} else {
str_length = strlen(dev-_defaultname);
-   dev-_filename = kmalloc(str_length + 1, GFP_KERNEL);
+   dev-_filename = kmemdup(dev-_defaultname, str_length + 1,
+GFP_KERNEL);
 
if (!dev-_filename)
goto error;
-
-   memcpy(dev-_filename, dev-_defaultname, str_length + 1);
}
 
/* Default if filename is empty string */


--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] pwc: Use kmemdup rather than duplicating its implementation

2011-11-18 Thread Thomas Meyer
The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer tho...@m3y3r.de
---

diff -u -p a/drivers/media/video/pwc/pwc-ctrl.c 
b/drivers/media/video/pwc/pwc-ctrl.c
--- a/drivers/media/video/pwc/pwc-ctrl.c 2011-11-07 19:37:51.14699 +0100
+++ b/drivers/media/video/pwc/pwc-ctrl.c 2011-11-08 10:47:00.679677247 +0100
@@ -113,10 +113,9 @@ static int _send_control_msg(struct pwc_
void *kbuf = NULL;
 
if (buflen) {
-   kbuf = kmalloc(buflen, GFP_KERNEL); /* not allowed on stack */
+   kbuf = kmemdup(buf, buflen, GFP_KERNEL); /* not allowed on 
stack */
if (kbuf == NULL)
return -ENOMEM;
-   memcpy(kbuf, buf, buflen);
}
 
rc = usb_control_msg(pdev-udev, usb_sndctrlpipe(pdev-udev, 0),
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/2] as3645a: Add driver for LED flash controller

2011-11-18 Thread Laurent Pinchart
Hi Andy,

On Wednesday 16 November 2011 15:35:18 Andy Shevchenko wrote:
 On Wed, 2011-11-16 at 15:10 +0100, Laurent Pinchart wrote:
  This patch adds the driver for the as3645a LED flash controller. This
  controller supports a high power led in flash and torch modes and an
  indicator light, sometimes also called privacy light.
 
 Just few nitpicks.
 
  diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
  index 4e8a0c4..9617c05 100644
  --- a/drivers/media/video/Kconfig
  +++ b/drivers/media/video/Kconfig
  @@ -533,6 +533,13 @@ config VIDEO_ADP1653
  
This is a driver for the ADP1653 flash controller. It is used for
example in Nokia N900.
  
  +config VIDEO_AS3645A
  +   tristate AS3645A flash driver support
  +   depends on I2C  VIDEO_V4L2  MEDIA_CONTROLLER
  +   ---help---
  + This is a driver for the AS3645A and LM3555 flash controllers. It has
  + build in control for Flash, Torch and Indicator LEDs.
 
 Probably we might use uncapitalized words for flash, torch and
 indicator

OK. I'll fix that in the pull request.

  diff --git a/drivers/media/video/as3645a.c
  b/drivers/media/video/as3645a.c new file mode 100644
  index 000..d583a9c
  --- /dev/null
  +++ b/drivers/media/video/as3645a.c
  
  +static int as3645a_probe(struct i2c_client *client,
  +const struct i2c_device_id *devid)
  +{
 
 To be consistent with remove()

As discussed on Jabber, the mutex is initialized as one of the last probe() 
operations, and we're guaranteed not to fail then. There's thus no problem 
with this.

 + mutex_init(flash-power_lock);
 
  +   ret = as3645a_init_controls(flash);
  +   if (ret  0)
  +   goto done;
  +
  +   ret = media_entity_init(flash-subdev.entity, 0, NULL, 0);
  +   if (ret  0)
  +   goto done;
  +
  +   flash-subdev.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
  
  +   flash-led_mode = V4L2_FLASH_LED_MODE_NONE;
  +
  +done:
  +   if (ret  0) {
 
 + mutex_destroy(flash-power_lock);
 
  + v4l2_ctrl_handler_free(flash-ctrls);
  +   kfree(flash);
  +   }
  +
  +   return ret;
  +}

-- 
Regards,

Laurent Pinchart
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] MEM2MEM: Add support for eMMa-PrP mem2mem operations.

2011-11-18 Thread Sylwester Nawrocki
Hi Javier,

Good to see non Samsung device using v4l2 mem-to-mem framework. What is your
experience, have you encountered any specific problems with it ?

And just out of curiosity, are you planning to develop video codec driver 
in v4l2 for i.MX27 as well ?

I have a few comments, please see below...

On 11/16/2011 05:23 PM, Javier Martin wrote:
 i.MX2x SoCs have a PrP which is capable of resizing and format
 conversion of video frames. This driver provides support for
 resizing and format conversion from YUYV to YUV420.
 
 This operation is of the utmost importance since some of these
 SoCs like i.MX27 include an H.264 video codec which only
 accepts YUV420 as input.
 
 Signed-off-by: Javier Martinjavier.mar...@vista-silicon.com
 ---
   arch/arm/mach-imx/devices-imx27.h   |2 +
   arch/arm/plat-mxc/devices/platform-mx2-camera.c |   33 +
   arch/arm/plat-mxc/include/mach/devices-common.h |2 +
   drivers/media/video/Kconfig |   11 +
   drivers/media/video/Makefile|2 +
   drivers/media/video/mx2_emmaprp.c   | 1059 
 +++
   6 files changed, 1109 insertions(+), 0 deletions(-)
   create mode 100644 drivers/media/video/mx2_emmaprp.c
 
 diff --git a/arch/arm/mach-imx/devices-imx27.h 
 b/arch/arm/mach-imx/devices-imx27.h
 index 2f727d7..519aa36 100644
 --- a/arch/arm/mach-imx/devices-imx27.h
 +++ b/arch/arm/mach-imx/devices-imx27.h
 @@ -50,6 +50,8 @@ extern const struct imx_imx_uart_1irq_data 
 imx27_imx_uart_data[];
   extern const struct imx_mx2_camera_data imx27_mx2_camera_data;
   #define imx27_add_mx2_camera(pdata) \
   imx_add_mx2_camera(imx27_mx2_camera_data, pdata)
 +#define imx27_alloc_mx2_emmaprp(pdata)   \
 + imx_alloc_mx2_emmaprp(imx27_mx2_camera_data)
 
   extern const struct imx_mxc_ehci_data imx27_mxc_ehci_otg_data;
   #define imx27_add_mxc_ehci_otg(pdata)   \
 diff --git a/arch/arm/plat-mxc/devices/platform-mx2-camera.c 
 b/arch/arm/plat-mxc/devices/platform-mx2-camera.c
 index b3f4828..4a8bd73 100644
 --- a/arch/arm/plat-mxc/devices/platform-mx2-camera.c
 +++ b/arch/arm/plat-mxc/devices/platform-mx2-camera.c
 @@ -6,6 +6,7 @@
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*/
 +#includelinux/dma-mapping.h
   #includemach/hardware.h
   #includemach/devices-common.h
 
 @@ -62,3 +63,35 @@ struct platform_device *__init imx_add_mx2_camera(
   res, data-iobaseemmaprp ? 4 : 2,
   pdata, sizeof(*pdata), DMA_BIT_MASK(32));
   }
 +
 +struct platform_device *__init imx_alloc_mx2_emmaprp(
 + const struct imx_mx2_camera_data *data)
 +{
 + struct resource res[] = {
 + {
 + .start = data-iobaseemmaprp,
 + .end = data-iobaseemmaprp + data-iosizeemmaprp - 1,
 + .flags = IORESOURCE_MEM,
 + }, {
 + .start = data-irqemmaprp,
 + .end = data-irqemmaprp,
 + .flags = IORESOURCE_IRQ,
 + },
 + };
 + struct platform_device *pdev;
 + int ret = -ENOMEM;
 +
 + pdev = platform_device_alloc(m2m-emmaprp, 0);
 + if (!pdev)
 + goto err;
 +
 + ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
 + if (ret)
 + goto err;
 +
 + return pdev;
 +err:
 + platform_device_put(pdev);
 + return ERR_PTR(-ENODEV);
 +
 +}
 diff --git a/arch/arm/plat-mxc/include/mach/devices-common.h 
 b/arch/arm/plat-mxc/include/mach/devices-common.h
 index def9ba5..ce64bd5 100644
 --- a/arch/arm/plat-mxc/include/mach/devices-common.h
 +++ b/arch/arm/plat-mxc/include/mach/devices-common.h
 @@ -223,6 +223,8 @@ struct imx_mx2_camera_data {
   struct platform_device *__init imx_add_mx2_camera(
   const struct imx_mx2_camera_data *data,
   const struct mx2_camera_platform_data *pdata);
 +struct platform_device *__init imx_alloc_mx2_emmaprp(
 + const struct imx_mx2_camera_data *data);
 
   #includemach/mxc_ehci.h
   struct imx_mxc_ehci_data {
 diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
 index b303a3f..6e57825 100644
 --- a/drivers/media/video/Kconfig
 +++ b/drivers/media/video/Kconfig
 @@ -1107,4 +1107,15 @@ config VIDEO_SAMSUNG_S5P_MFC
   help
   MFC 5.1 driver for V4L2.
 
 +config VIDEO_MX2_EMMAPRP
 + tristate MX2 eMMa-PrP support
 + depends on VIDEO_DEV  VIDEO_V4L2  MACH_MX27
 + select VIDEOBUF2_DMA_CONTIG
 + select V4L2_MEM2MEM_DEV
 + default n

The default is 'n' so this line is redundant.

 + help
 + MX2X chips have a PrP that can be used to process buffers from
 + memory to memory. Operations include resizing and format
 + conversion.
 +
   endif # V4L_MEM2MEM_DRIVERS
 diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
 index 117f9c4..7ae711e 100644
 --- 

Re: [PATCH] MEM2MEM: Add support for eMMa-PrP mem2mem operations.

2011-11-18 Thread javier Martin
Hi Sylwester,
thank you for your review.

On 18 November 2011 17:07, Sylwester Nawrocki snj...@gmail.com wrote:
 Hi Javier,

 Good to see non Samsung device using v4l2 mem-to-mem framework. What is your
 experience, have you encountered any specific problems with it ?

I've found the framework quite convenient and comfortable, it
definitely saves a lot of work and coding once you understand it
properly.
For a simple device as i.MX2 eMMa-PrP a driver can be in a working
state in a couple of days. I've not found any drawbacks.

 And just out of curiosity, are you planning to develop video codec driver
 in v4l2 for i.MX27 as well ?

It depends on the result of a proof of concept we are preparing now.
But yes, it could be possible. AFAIK, Sascha Hauer (added to CC) has a
prototype driver for this one though.

 I have a few comments, please see below...

It seems I'll have to prepare a second version with all the fixes
you've pointed out which seem quite reasonable to me.

Regards.

-- 
Javier Martin
Vista Silicon S.L.
CDTUC - FASE C - Oficina S-345
Avda de los Castros s/n
39005- Santander. Cantabria. Spain
+34 942 25 32 60
www.vista-silicon.com
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/11] ARM: integrate CMA with DMA-mapping subsystem

2011-11-18 Thread Marek Szyprowski
This patch adds support for CMA to dma-mapping subsystem for ARM
architecture. By default a global CMA area is used, but specific devices
are allowed to have their private memory areas if required (they can be
created with dma_declare_contiguous() function during board
initialization).

Contiguous memory areas reserved for DMA are remapped with 2-level page
tables on boot. Once a buffer is requested, a low memory kernel mapping
is updated to to match requested memory access type.

GFP_ATOMIC allocations are performed from special pool which is created
early during boot. This way remapping page attributes is not needed on
allocation time.

CMA has been enabled unconditionally for ARMv6+ systems.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
CC: Michal Nazarewicz min...@mina86.com
---
 Documentation/kernel-parameters.txt   |4 +
 arch/arm/Kconfig  |2 +
 arch/arm/include/asm/dma-contiguous.h |   16 ++
 arch/arm/include/asm/mach/map.h   |1 +
 arch/arm/kernel/setup.c   |8 +-
 arch/arm/mm/dma-mapping.c |  368 +++--
 arch/arm/mm/init.c|   20 ++-
 arch/arm/mm/mm.h  |3 +
 arch/arm/mm/mmu.c |   29 ++-
 9 files changed, 364 insertions(+), 87 deletions(-)
 create mode 100644 arch/arm/include/asm/dma-contiguous.h

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 164024e..6685e63 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -515,6 +515,10 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
a hypervisor.
Default: yes
 
+   coherent_pool=nn[KMG]   [ARM,KNL]
+   Sets the size of memory pool for coherent, atomic dma
+   allocations if Contiguous Memory Allocator (CMA) is 
used.
+
code_bytes  [X86] How many bytes of object code to print
in an oops report.
Range: 0 - 8192
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 44789ef..53c96d9 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -4,6 +4,8 @@ config ARM
select HAVE_AOUT
select HAVE_DMA_API_DEBUG
select HAVE_IDE if PCI || ISA || PCMCIA
+   select HAVE_DMA_CONTIGUOUS if (CPU_V6 || CPU_V6K || CPU_V7)
+   select CMA if (CPU_V6 || CPU_V6K || CPU_V7)
select HAVE_MEMBLOCK
select RTC_LIB
select SYS_SUPPORTS_APM_EMULATION
diff --git a/arch/arm/include/asm/dma-contiguous.h 
b/arch/arm/include/asm/dma-contiguous.h
new file mode 100644
index 000..c7ba05e
--- /dev/null
+++ b/arch/arm/include/asm/dma-contiguous.h
@@ -0,0 +1,16 @@
+#ifndef ASMARM_DMA_CONTIGUOUS_H
+#define ASMARM_DMA_CONTIGUOUS_H
+
+#ifdef __KERNEL__
+
+#include linux/device.h
+#include linux/dma-contiguous.h
+#include asm-generic/dma-contiguous.h
+
+#ifdef CONFIG_CMA
+
+void dma_contiguous_early_fixup(phys_addr_t base, unsigned long size);
+
+#endif
+#endif
+#endif
diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
index b36f365..a6efcdd 100644
--- a/arch/arm/include/asm/mach/map.h
+++ b/arch/arm/include/asm/mach/map.h
@@ -30,6 +30,7 @@ struct map_desc {
 #define MT_MEMORY_DTCM 12
 #define MT_MEMORY_ITCM 13
 #define MT_MEMORY_SO   14
+#define MT_MEMORY_DMA_READY15
 
 #ifdef CONFIG_MMU
 extern void iotable_init(struct map_desc *, int);
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 7e7977a..4c82ad3 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -78,6 +78,7 @@ __setup(fpe=, fpe_setup);
 extern void paging_init(struct machine_desc *desc);
 extern void sanity_check_meminfo(void);
 extern void reboot_setup(char *str);
+extern void setup_dma_zone(struct machine_desc *desc);
 
 unsigned int processor_id;
 EXPORT_SYMBOL(processor_id);
@@ -917,6 +918,7 @@ void __init setup_arch(char **cmdline_p)
parse_early_param();
 
sanity_check_meminfo();
+   setup_dma_zone(mdesc);
arm_memblock_init(meminfo, mdesc);
 
paging_init(mdesc);
@@ -932,12 +934,6 @@ void __init setup_arch(char **cmdline_p)
 
tcm_init();
 
-#ifdef CONFIG_ZONE_DMA
-   if (mdesc-dma_zone_size) {
-   extern unsigned long arm_dma_zone_size;
-   arm_dma_zone_size = mdesc-dma_zone_size;
-   }
-#endif
 #ifdef CONFIG_MULTI_IRQ_HANDLER
handle_arch_irq = mdesc-handle_irq;
 #endif
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index e4e7f6c..c63174c 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -17,7 +17,9 @@
 #include linux/init.h
 #include linux/device.h
 #include linux/dma-mapping.h
+#include linux/dma-contiguous.h
 #include linux/highmem.h
+#include linux/memblock.h
 #include linux/slab.h
 
 

[PATCH 05/11] mm: page_alloc: introduce alloc_contig_range()

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

This commit adds the alloc_contig_range() function which tries
to allocate given range of pages.  It tries to migrate all
already allocated pages that fall in the range thus freeing them.
Once all pages in the range are freed they are removed from the
buddy system thus allocated for the caller to use.

__alloc_contig_migrate_range() borrows some code from KAMEZAWA
Hiroyuki's __alloc_contig_pages().

Signed-off-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 include/linux/page-isolation.h |3 +
 mm/page_alloc.c|  223 
 2 files changed, 226 insertions(+), 0 deletions(-)

diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h
index 051c1b1..d305080 100644
--- a/include/linux/page-isolation.h
+++ b/include/linux/page-isolation.h
@@ -33,5 +33,8 @@ test_pages_isolated(unsigned long start_pfn, unsigned long 
end_pfn);
 extern int set_migratetype_isolate(struct page *page);
 extern void unset_migratetype_isolate(struct page *page);
 
+/* The below functions must be run on a range from a single zone. */
+int alloc_contig_range(unsigned long start, unsigned long end);
+void free_contig_range(unsigned long pfn, unsigned nr_pages);
 
 #endif
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 58d1a2e..b7aac26 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -57,6 +57,7 @@
 #include linux/ftrace_event.h
 #include linux/memcontrol.h
 #include linux/prefetch.h
+#include linux/migrate.h
 
 #include asm/tlbflush.h
 #include asm/div64.h
@@ -5687,6 +5688,228 @@ out:
spin_unlock_irqrestore(zone-lock, flags);
 }
 
+static unsigned long pfn_align_to_maxpage_down(unsigned long pfn)
+{
+   return pfn  ~(MAX_ORDER_NR_PAGES - 1);
+}
+
+static unsigned long pfn_align_to_maxpage_up(unsigned long pfn)
+{
+   return ALIGN(pfn, MAX_ORDER_NR_PAGES);
+}
+
+static int __alloc_contig_migrate_range(unsigned long start, unsigned long end)
+{
+   /* This function is based on compact_zone() from compaction.c. */
+
+   unsigned long pfn = start;
+   int ret = -EBUSY;
+   unsigned tries = 0;
+
+   struct compact_control cc = {
+   .nr_migratepages = 0,
+   .nr_freepages = 0,
+   .order = -1,
+   .zone = page_zone(pfn_to_page(start)),
+   .sync = true,
+   .migrate_pfn = 0,
+   };
+   INIT_LIST_HEAD(cc.freepages);
+   INIT_LIST_HEAD(cc.migratepages);
+
+   /*
+* Compaction code uses two pointers, a migrate_pfn and
+* free_pfn.  The first one goes from the beginning, and the
+* second one from the end of the zone.  Once they meet,
+* compaction stops.
+*
+* This is good behaviour if you want to migrate all pages to
+* the end of the zone put that's not what we want.  We want
+* to migrate pages from [start, end) *anywhere* inside the
+* zone.  To do that, we set migrate_pfn to the beginning of
+* the zone and never touch it again so compaction will finish
+* only when the free_pfn pointer reaches beginning of the
+* zone.
+*/
+
+   cc.migrate_pfn = cc.zone-zone_start_pfn;
+   cc.free_pfn = cc.migrate_pfn + cc.zone-spanned_pages;
+   cc.free_pfn = ~(pageblock_nr_pages-1);
+
+   migrate_prep_local();
+
+   while (pfn  end || cc.nr_migratepages) {
+   /* Abort on signal */
+   if (fatal_signal_pending(current)) {
+   ret = -EINTR;
+   goto done;
+   }
+
+   /* Are there any pages left? */
+   if (cc.nr_freepages  cc.free_pfn = cc.migrate_pfn) {
+   /* We've run out of pages to migrate to. */
+   ret = -EBUSY;
+   goto done;
+   }
+
+   /* Get some pages to migrate. */
+   if (list_empty(cc.migratepages)) {
+   cc.nr_migratepages = 0;
+   pfn = isolate_migratepages_range(cc.zone, cc,
+pfn, end);
+   if (!pfn) {
+   ret = -EINTR;
+   goto done;
+   }
+   tries = 0;
+   }
+
+   /* Try to migrate. */
+   ret = migrate_pages(cc.migratepages, compaction_alloc,
+   (unsigned long)cc, false, cc.sync);
+
+   /* Migrated all of them? Great! */
+   if (list_empty(cc.migratepages))
+   continue;
+
+   /* Try five times. */
+   if (++tries == 5) {
+   ret = ret  0 ? ret : -EBUSY;
+   goto done;
+   }
+
+   /* Before each time drain everything 

[PATCH 07/11] mm: page_isolation: MIGRATE_CMA isolation functions added

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

This commit changes various functions that change pages and
pageblocks migrate type between MIGRATE_ISOLATE and
MIGRATE_MOVABLE in such a way as to allow to work with
MIGRATE_CMA migrate type.

Signed-off-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 include/linux/page-isolation.h |   23 ---
 mm/memory-failure.c|2 +-
 mm/memory_hotplug.c|6 +++---
 mm/page_alloc.c|   18 --
 mm/page_isolation.c|   15 ---
 5 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h
index af650db..c8004dc 100644
--- a/include/linux/page-isolation.h
+++ b/include/linux/page-isolation.h
@@ -3,7 +3,7 @@
 
 /*
  * Changes migrate type in [start_pfn, end_pfn) to be MIGRATE_ISOLATE.
- * If specified range includes migrate types other than MOVABLE,
+ * If specified range includes migrate types other than MOVABLE or CMA,
  * this will fail with -EBUSY.
  *
  * For isolating all pages in the range finally, the caller have to
@@ -11,30 +11,31 @@
  * test it.
  */
 extern int
-start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn);
+start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
+unsigned migratetype);
 
 /*
  * Changes MIGRATE_ISOLATE to MIGRATE_MOVABLE.
  * target range is [start_pfn, end_pfn)
  */
 extern int
-undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn);
+undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
+   unsigned migratetype);
 
 /*
- * test all pages in [start_pfn, end_pfn)are isolated or not.
+ * Test all pages in [start_pfn, end_pfn) are isolated or not.
  */
-extern int
-test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
+int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
 
 /*
- * Internal funcs.Changes pageblock's migrate type.
- * Please use make_pagetype_isolated()/make_pagetype_movable().
+ * Internal functions. Changes pageblock's migrate type.
  */
-extern int set_migratetype_isolate(struct page *page);
-extern void unset_migratetype_isolate(struct page *page);
+int set_migratetype_isolate(struct page *page);
+void unset_migratetype_isolate(struct page *page, unsigned migratetype);
 
 /* The below functions must be run on a range from a single zone. */
-int alloc_contig_range(unsigned long start, unsigned long end);
+int alloc_contig_range(unsigned long start, unsigned long end,
+  unsigned migratetype);
 void free_contig_range(unsigned long pfn, unsigned nr_pages);
 
 /* CMA stuff */
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 06d3479..3cf809d 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1400,7 +1400,7 @@ static int get_any_page(struct page *p, unsigned long 
pfn, int flags)
/* Not a free page */
ret = 1;
}
-   unset_migratetype_isolate(p);
+   unset_migratetype_isolate(p, MIGRATE_MOVABLE);
unlock_memory_hotplug();
return ret;
 }
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 2168489..2a44d55 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -891,7 +891,7 @@ static int __ref offline_pages(unsigned long start_pfn,
nr_pages = end_pfn - start_pfn;
 
/* set above range as isolated */
-   ret = start_isolate_page_range(start_pfn, end_pfn);
+   ret = start_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
if (ret)
goto out;
 
@@ -956,7 +956,7 @@ repeat:
   We cannot do rollback at this point. */
offline_isolated_pages(start_pfn, end_pfn);
/* reset pagetype flags and makes migrate type to be MOVABLE */
-   undo_isolate_page_range(start_pfn, end_pfn);
+   undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
/* removal success */
zone-present_pages -= offlined_pages;
zone-zone_pgdat-node_present_pages -= offlined_pages;
@@ -981,7 +981,7 @@ failed_removal:
start_pfn, end_pfn);
memory_notify(MEM_CANCEL_OFFLINE, arg);
/* pushback to free area */
-   undo_isolate_page_range(start_pfn, end_pfn);
+   undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
 
 out:
unlock_memory_hotplug();
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9ec73f4..714b1c1 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5710,7 +5710,7 @@ out:
return ret;
 }
 
-void unset_migratetype_isolate(struct page *page)
+void unset_migratetype_isolate(struct page *page, unsigned migratetype)
 {
struct zone *zone;
unsigned long flags;
@@ -5718,8 +5718,8 @@ void unset_migratetype_isolate(struct page *page)
spin_lock_irqsave(zone-lock, flags);
if 

[PATCH 11/11] ARM: Samsung: use CMA for 2 memory banks for s5p-mfc device

2011-11-18 Thread Marek Szyprowski
Replace custom memory bank initialization using memblock_reserve and
dma_declare_coherent with a single call to CMA's dma_declare_contiguous.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 arch/arm/plat-s5p/dev-mfc.c |   51 ++-
 1 files changed, 7 insertions(+), 44 deletions(-)

diff --git a/arch/arm/plat-s5p/dev-mfc.c b/arch/arm/plat-s5p/dev-mfc.c
index a30d36b..fcb8400 100644
--- a/arch/arm/plat-s5p/dev-mfc.c
+++ b/arch/arm/plat-s5p/dev-mfc.c
@@ -14,6 +14,7 @@
 #include linux/interrupt.h
 #include linux/platform_device.h
 #include linux/dma-mapping.h
+#include linux/dma-contiguous.h
 #include linux/memblock.h
 #include linux/ioport.h
 
@@ -22,52 +23,14 @@
 #include plat/irqs.h
 #include plat/mfc.h
 
-struct s5p_mfc_reserved_mem {
-   phys_addr_t base;
-   unsigned long   size;
-   struct device   *dev;
-};
-
-static struct s5p_mfc_reserved_mem s5p_mfc_mem[2] __initdata;
-
 void __init s5p_mfc_reserve_mem(phys_addr_t rbase, unsigned int rsize,
phys_addr_t lbase, unsigned int lsize)
 {
-   int i;
-
-   s5p_mfc_mem[0].dev = s5p_device_mfc_r.dev;
-   s5p_mfc_mem[0].base = rbase;
-   s5p_mfc_mem[0].size = rsize;
-
-   s5p_mfc_mem[1].dev = s5p_device_mfc_l.dev;
-   s5p_mfc_mem[1].base = lbase;
-   s5p_mfc_mem[1].size = lsize;
-
-   for (i = 0; i  ARRAY_SIZE(s5p_mfc_mem); i++) {
-   struct s5p_mfc_reserved_mem *area = s5p_mfc_mem[i];
-   if (memblock_remove(area-base, area-size)) {
-   printk(KERN_ERR Failed to reserve memory for MFC 
device (%ld bytes at 0x%08lx)\n,
-  area-size, (unsigned long) area-base);
-   area-base = 0;
-   }
-   }
-}
-
-static int __init s5p_mfc_memory_init(void)
-{
-   int i;
-
-   for (i = 0; i  ARRAY_SIZE(s5p_mfc_mem); i++) {
-   struct s5p_mfc_reserved_mem *area = s5p_mfc_mem[i];
-   if (!area-base)
-   continue;
+   if (dma_declare_contiguous(s5p_device_mfc_r.dev, rsize, rbase, 0))
+   printk(KERN_ERR Failed to reserve memory for MFC device (%u 
bytes at 0x%08lx)\n,
+  rsize, (unsigned long) rbase);
 
-   if (dma_declare_coherent_memory(area-dev, area-base,
-   area-base, area-size,
-   DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0)
-   printk(KERN_ERR Failed to declare coherent memory for 
MFC device (%ld bytes at 0x%08lx)\n,
-  area-size, (unsigned long) area-base);
-   }
-   return 0;
+   if (dma_declare_contiguous(s5p_device_mfc_l.dev, lsize, lbase, 0))
+   printk(KERN_ERR Failed to reserve memory for MFC device (%u 
bytes at 0x%08lx)\n,
+  rsize, (unsigned long) rbase);
 }
-device_initcall(s5p_mfc_memory_init);
-- 
1.7.1.569.g6f426

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/11] mm: mmzone: MIGRATE_CMA migration type added

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

The MIGRATE_CMA migration type has two main characteristics:
(i) only movable pages can be allocated from MIGRATE_CMA
pageblocks and (ii) page allocator will never change migration
type of MIGRATE_CMA pageblocks.

This guarantees (to some degree) that page in a MIGRATE_CMA page
block can always be migrated somewhere else (unless there's no
memory left in the system).

It is designed to be used for allocating big chunks (eg. 10MiB)
of physically contiguous memory.  Once driver requests
contiguous memory, pages from MIGRATE_CMA pageblocks may be
migrated away to create a contiguous block.

To minimise number of migrations, MIGRATE_CMA migration type
is the last type tried when page allocator falls back to other
migration types then requested.

Signed-off-by: Michal Nazarewicz min...@mina86.com
[m.szyprowski: removed CONFIG_CMA_MIGRATE_TYPE]
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 include/linux/mmzone.h |   41 
 include/linux/page-isolation.h |3 ++
 mm/Kconfig |2 +-
 mm/compaction.c|   11 +--
 mm/page_alloc.c|   68 ++-
 5 files changed, 98 insertions(+), 27 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 84e07d0..604a235 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -35,13 +35,35 @@
  */
 #define PAGE_ALLOC_COSTLY_ORDER 3
 
-#define MIGRATE_UNMOVABLE 0
-#define MIGRATE_RECLAIMABLE   1
-#define MIGRATE_MOVABLE   2
-#define MIGRATE_PCPTYPES  3 /* the number of types on the pcp lists */
-#define MIGRATE_RESERVE   3
-#define MIGRATE_ISOLATE   4 /* can't allocate from here */
-#define MIGRATE_TYPES 5
+enum {
+   MIGRATE_UNMOVABLE,
+   MIGRATE_RECLAIMABLE,
+   MIGRATE_MOVABLE,
+   MIGRATE_PCPTYPES,   /* the number of types on the pcp lists */
+   MIGRATE_RESERVE = MIGRATE_PCPTYPES,
+   /*
+* MIGRATE_CMA migration type is designed to mimic the way
+* ZONE_MOVABLE works.  Only movable pages can be allocated
+* from MIGRATE_CMA pageblocks and page allocator never
+* implicitly change migration type of MIGRATE_CMA pageblock.
+*
+* The way to use it is to change migratetype of a range of
+* pageblocks to MIGRATE_CMA which can be done by
+* __free_pageblock_cma() function.  What is important though
+* is that a range of pageblocks must be aligned to
+* MAX_ORDER_NR_PAGES should biggest page be bigger then
+* a single pageblock.
+*/
+   MIGRATE_CMA,
+   MIGRATE_ISOLATE,/* can't allocate from here */
+   MIGRATE_TYPES
+};
+
+#ifdef CONFIG_CMA
+#  define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
+#else
+#  define is_migrate_cma(migratetype) false
+#endif
 
 #define for_each_migratetype_order(order, type) \
for (order = 0; order  MAX_ORDER; order++) \
@@ -54,6 +76,11 @@ static inline int get_pageblock_migratetype(struct page 
*page)
return get_pageblock_flags_group(page, PB_migrate, PB_migrate_end);
 }
 
+static inline bool is_pageblock_cma(struct page *page)
+{
+   return is_migrate_cma(get_pageblock_migratetype(page));
+}
+
 struct free_area {
struct list_headfree_list[MIGRATE_TYPES];
unsigned long   nr_free;
diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h
index d305080..af650db 100644
--- a/include/linux/page-isolation.h
+++ b/include/linux/page-isolation.h
@@ -37,4 +37,7 @@ extern void unset_migratetype_isolate(struct page *page);
 int alloc_contig_range(unsigned long start, unsigned long end);
 void free_contig_range(unsigned long pfn, unsigned nr_pages);
 
+/* CMA stuff */
+extern void init_cma_reserved_pageblock(struct page *page);
+
 #endif
diff --git a/mm/Kconfig b/mm/Kconfig
index 011b110..e080cac 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -192,7 +192,7 @@ config COMPACTION
 config MIGRATION
bool Page migration
def_bool y
-   depends on NUMA || ARCH_ENABLE_MEMORY_HOTREMOVE || COMPACTION
+   depends on NUMA || ARCH_ENABLE_MEMORY_HOTREMOVE || COMPACTION || CMA
help
  Allows the migration of the physical location of pages of processes
  while the virtual addresses are not changed. This is useful in
diff --git a/mm/compaction.c b/mm/compaction.c
index e71ceaf..3e07341 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -19,6 +19,11 @@
 #define CREATE_TRACE_POINTS
 #include trace/events/compaction.h
 
+static inline bool is_migrate_cma_or_movable(int migratetype)
+{
+   return is_migrate_cma(migratetype) || migratetype == MIGRATE_MOVABLE;
+}
+
 unsigned long release_freepages(struct list_head *freelist)
 {
struct page *page, *next;
@@ -114,8 +119,8 @@ static bool 

[PATCH 03/11] mm: mmzone: introduce zone_pfn_same_memmap()

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

This commit introduces zone_pfn_same_memmap() function which checkes
whether two PFNs within the same zone have struct pages within the
same memmap.  This check is needed because in general pointer
arithmetic on struct pages may lead to invalid pointers.

On memory models that are not affected, zone_pfn_same_memmap() is
defined as always returning true so the call should be optimised
at compile time.

Signed-off-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 include/linux/mmzone.h |   16 
 mm/compaction.c|5 -
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 188cb2f..84e07d0 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1166,6 +1166,22 @@ static inline int memmap_valid_within(unsigned long pfn,
 }
 #endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
 
+#if defined(CONFIG_SPARSEMEM)  !defined(CONFIG_SPARSEMEM_VMEMMAP)
+/*
+ * Both PFNs must be from the same zone!  If this function returns
+ * true, pfn_to_page(pfn1) + (pfn2 - pfn1) == pfn_to_page(pfn2).
+ */
+static inline bool zone_pfn_same_memmap(unsigned long pfn1, unsigned long pfn2)
+{
+   return pfn_to_section_nr(pfn1) == pfn_to_section_nr(pfn2);
+}
+
+#else
+
+#define zone_pfn_same_memmap(pfn1, pfn2) (true)
+
+#endif
+
 #endif /* !__GENERATING_BOUNDS.H */
 #endif /* !__ASSEMBLY__ */
 #endif /* _LINUX_MMZONE_H */
diff --git a/mm/compaction.c b/mm/compaction.c
index 6afae0e..09c9702 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -111,7 +111,10 @@ skip:
 
 next:
pfn += isolated;
-   page += isolated;
+   if (zone_pfn_same_memmap(pfn - isolated, pfn))
+   page += isolated;
+   else
+   page = pfn_to_page(pfn);
}
 
trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);
-- 
1.7.1.569.g6f426

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/11] mm: compaction: introduce isolate_{free,migrate}pages_range().

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

This commit introduces isolate_freepages_range() and
isolate_migratepages_range() functions.  The first one replaces
isolate_freepages_block() and the second one extracts functionality
from isolate_migratepages().

They are more generic and instead of operating on pageblocks operate
on PFN ranges.

Signed-off-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 mm/compaction.c |  170 ---
 1 files changed, 111 insertions(+), 59 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 899d956..6afae0e 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -54,51 +54,64 @@ static unsigned long release_freepages(struct list_head 
*freelist)
return count;
 }
 
-/* Isolate free pages onto a private freelist. Must hold zone-lock */
-static unsigned long isolate_freepages_block(struct zone *zone,
-   unsigned long blockpfn,
-   struct list_head *freelist)
+/**
+ * isolate_freepages_range() - isolate free pages, must hold zone-lock.
+ * @zone:  Zone pages are in.
+ * @start: The first PFN to start isolating.
+ * @end:   The one-past-last PFN.
+ * @freelist:  A list to save isolated pages to.
+ *
+ * If @freelist is not provided, holes in range (either non-free pages
+ * or invalid PFNs) are considered an error and function undos its
+ * actions and returns zero.
+ *
+ * If @freelist is provided, function will simply skip non-free and
+ * missing pages and put only the ones isolated on the list.
+ *
+ * Returns number of isolated pages.  This may be more then end-start
+ * if end fell in a middle of a free page.
+ */
+static unsigned long
+isolate_freepages_range(struct zone *zone,
+   unsigned long start, unsigned long end,
+   struct list_head *freelist)
 {
-   unsigned long zone_end_pfn, end_pfn;
-   int nr_scanned = 0, total_isolated = 0;
-   struct page *cursor;
-
-   /* Get the last PFN we should scan for free pages at */
-   zone_end_pfn = zone-zone_start_pfn + zone-spanned_pages;
-   end_pfn = min(blockpfn + pageblock_nr_pages, zone_end_pfn);
+   unsigned long nr_scanned = 0, total_isolated = 0;
+   unsigned long pfn = start;
+   struct page *page;
 
-   /* Find the first usable PFN in the block to initialse page cursor */
-   for (; blockpfn  end_pfn; blockpfn++) {
-   if (pfn_valid_within(blockpfn))
-   break;
-   }
-   cursor = pfn_to_page(blockpfn);
+   VM_BUG_ON(!pfn_valid(pfn));
+   page = pfn_to_page(pfn);
 
/* Isolate free pages. This assumes the block is valid */
-   for (; blockpfn  end_pfn; blockpfn++, cursor++) {
-   int isolated, i;
-   struct page *page = cursor;
-
-   if (!pfn_valid_within(blockpfn))
-   continue;
-   nr_scanned++;
-
-   if (!PageBuddy(page))
-   continue;
+   while (pfn  end) {
+   unsigned isolated = 1, i;
+
+   if (!pfn_valid_within(pfn))
+   goto skip;
+   ++nr_scanned;
+
+   if (!PageBuddy(page)) {
+skip:
+   if (freelist)
+   goto next;
+   for (; start  pfn; ++start)
+   __free_page(pfn_to_page(pfn));
+   return 0;
+   }
 
/* Found a free page, break it into order-0 pages */
isolated = split_free_page(page);
total_isolated += isolated;
-   for (i = 0; i  isolated; i++) {
-   list_add(page-lru, freelist);
-   page++;
+   if (freelist) {
+   struct page *p = page;
+   for (i = isolated; i; --i, ++p)
+   list_add(p-lru, freelist);
}
 
-   /* If a page was split, advance to the end of it */
-   if (isolated) {
-   blockpfn += isolated - 1;
-   cursor += isolated - 1;
-   }
+next:
+   pfn += isolated;
+   page += isolated;
}
 
trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);
@@ -135,7 +148,7 @@ static void isolate_freepages(struct zone *zone,
struct compact_control *cc)
 {
struct page *page;
-   unsigned long high_pfn, low_pfn, pfn;
+   unsigned long high_pfn, low_pfn, pfn, zone_end_pfn, end_pfn;
unsigned long flags;
int nr_freepages = cc-nr_freepages;
struct list_head *freelist = cc-freepages;
@@ -155,6 +168,8 @@ static void isolate_freepages(struct zone *zone,
 */
high_pfn = min(low_pfn, pfn);
 
+  

[PATCH 08/11] drivers: add Contiguous Memory Allocator

2011-11-18 Thread Marek Szyprowski
The Contiguous Memory Allocator is a set of helper functions for DMA
mapping framework that improves allocations of contiguous memory chunks.

CMA grabs memory on system boot, marks it with CMA_MIGRATE_TYPE and
gives back to the system. Kernel is allowed to allocate movable pages
within CMA's managed memory so that it can be used for example for page
cache when DMA mapping do not use it. On dma_alloc_from_contiguous()
request such pages are migrated out of CMA area to free required
contiguous block and fulfill the request. This allows to allocate large
contiguous chunks of memory at any time assuming that there is enough
free memory available in the system.

This code is heavily based on earlier works by Michal Nazarewicz.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
CC: Michal Nazarewicz min...@mina86.com
---
 Documentation/kernel-parameters.txt  |5 +
 arch/Kconfig |3 +
 drivers/base/Kconfig |   89 
 drivers/base/Makefile|1 +
 drivers/base/dma-contiguous.c|  396 ++
 include/asm-generic/dma-contiguous.h |   27 +++
 include/linux/device.h   |4 +
 include/linux/dma-contiguous.h   |  110 ++
 8 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 drivers/base/dma-contiguous.c
 create mode 100644 include/asm-generic/dma-contiguous.h
 create mode 100644 include/linux/dma-contiguous.h

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index a0c5c5f..164024e 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -503,6 +503,11 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
Also note the kernel might malfunction if you disable
some critical bits.
 
+   cma=nn[MG]  [ARM,KNL]
+   Sets the size of kernel global memory area for 
contiguous
+   memory allocations. For more information, see
+   include/linux/dma-contiguous.h
+
cmo_free_hint=  [PPC] Format: { yes | no }
Specify whether pages are marked as being inactive
when they are freed.  This is used in CMO environments
diff --git a/arch/Kconfig b/arch/Kconfig
index 4b0669c..a3b39a2 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -124,6 +124,9 @@ config HAVE_ARCH_TRACEHOOK
 config HAVE_DMA_ATTRS
bool
 
+config HAVE_DMA_CONTIGUOUS
+   bool
+
 config USE_GENERIC_SMP_HELPERS
bool
 
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 21cf46f..99f5fad 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -174,4 +174,93 @@ config SYS_HYPERVISOR
 
 source drivers/base/regmap/Kconfig
 
+config CMA
+   bool Contiguous Memory Allocator (EXPERIMENTAL)
+   depends on HAVE_DMA_CONTIGUOUS  HAVE_MEMBLOCK  EXPERIMENTAL
+   select MIGRATION
+   help
+ This enables the Contiguous Memory Allocator which allows drivers
+ to allocate big physically-contiguous blocks of memory for use with
+ hardware components that do not support I/O map nor scatter-gather.
+
+ For more information see include/linux/dma-contiguous.h.
+ If unsure, say n.
+
+if CMA
+
+config CMA_DEBUG
+   bool CMA debug messages (DEVELOPMENT)
+   depends on DEBUG_KERNEL
+   help
+ Turns on debug messages in CMA.  This produces KERN_DEBUG
+ messages for every CMA call as well as various messages while
+ processing calls such as dma_alloc_from_contiguous().
+ This option does not affect warning and error messages.
+
+comment Default contiguous memory area size:
+
+config CMA_SIZE_MBYTES
+   int Size in Mega Bytes
+   depends on !CMA_SIZE_SEL_PERCENTAGE
+   default 16
+   help
+ Defines the size (in MiB) of the default memory area for Contiguous
+ Memory Allocator.
+
+config CMA_SIZE_PERCENTAGE
+   int Percentage of total memory
+   depends on !CMA_SIZE_SEL_MBYTES
+   default 10
+   help
+ Defines the size of the default memory area for Contiguous Memory
+ Allocator as a percentage of the total memory in the system.
+
+choice
+   prompt Selected region size
+   default CMA_SIZE_SEL_ABSOLUTE
+
+config CMA_SIZE_SEL_MBYTES
+   bool Use mega bytes value only
+
+config CMA_SIZE_SEL_PERCENTAGE
+   bool Use percentage value only
+
+config CMA_SIZE_SEL_MIN
+   bool Use lower value (minimum)
+
+config CMA_SIZE_SEL_MAX
+   bool Use higher value (maximum)
+
+endchoice
+
+config CMA_ALIGNMENT
+   int Maximum PAGE_SIZE order of alignment for contiguous buffers
+   range 4 9
+   default 8
+   help
+ DMA mapping framework by default aligns all buffers to the smallest
+ PAGE_SIZE order 

[PATCHv17 0/11] Contiguous Memory Allocator

2011-11-18 Thread Marek Szyprowski
Welcome everyone once again,

This is yet another release of the Contiguous Memory Allocator patches.
This version is mainly a result of the discussion on Kernel Summit in
Prague. The main change is completely different code base for the
migration feature of the CMA. Now it shares the code with memory
compaction subsystem, not the hotplug like it was before. This code has
been kindly provided by Michal Nazarewicz. There are also a few fixes
here and there, see changelog for the details.

Please notice that this patch series is aimed to start further
discussion. There are still few issues that need to be resolved before
CMA will be really ready. The most hot problem is the issue with movable
pages that causes migration to fail from time to time. Our investigation
leads us to the point that these rare pages cannot be migrated because
there are some pending io operations on them.

ARM integration code has not been changed since last version, it
provides implementation of all the ideas that has been discussed during
Linaro Sprint meeting. Here are the details:

  This version provides a solution for complete integration of CMA to
  DMA mapping subsystem on ARM architecture. The issue caused by double
  dma pages mapping and possible aliasing in coherent memory mapping has
  been finally resolved, both for GFP_ATOMIC case (allocations comes from
  coherent memory pool) and non-GFP_ATOMIC case (allocations comes from
  CMA managed areas).

  For coherent, nommu, ARMv4 and ARMv5 systems the current DMA-mapping
  implementation has been kept.

  For ARMv6+ systems, CMA has been enabled and a special pool of coherent
  memory for atomic allocations has been created. The size of this pool
  defaults to DEFAULT_CONSISTEN_DMA_SIZE/8, but can be changed with
  coherent_pool kernel parameter (if really required).

  All atomic allocations are served from this pool. I've did a little
  simplification here, because there is no separate pool for writecombine
  memory - such requests are also served from coherent pool. I don't
  think that such simplification is a problem here - I found no driver
  that use dma_alloc_writecombine with GFP_ATOMIC flags.

  All non-atomic allocation are served from CMA area. Kernel mapping is
  updated to reflect required memory attributes changes. This is possible
  because during early boot, all CMA area are remapped with 4KiB pages in
  kernel low-memory.

  This version have been tested on Samsung S5PC110 based Goni machine and
  Exynos4 UniversalC210 board with various V4L2 multimedia drivers.

  Coherent atomic allocations has been tested by manually enabling the dma
  bounce for the s3c-sdhci device.

All patches are prepared for Linux Kernel v3.2-rc2.

A few words for these who see CMA for the first time:

   The Contiguous Memory Allocator (CMA) makes it possible for device
   drivers to allocate big contiguous chunks of memory after the system
   has booted. 

   The main difference from the similar frameworks is the fact that CMA
   allows to transparently reuse memory region reserved for the big
   chunk allocation as a system memory, so no memory is wasted when no
   big chunk is allocated. Once the alloc request is issued, the
   framework will migrate system pages to create a required big chunk of
   physically contiguous memory.

   For more information you can refer to nice LWN articles: 
   http://lwn.net/Articles/447405/ and http://lwn.net/Articles/450286/
   as well as links to previous versions of the CMA framework.

   The CMA framework has been initially developed by Michal Nazarewicz
   at Samsung Poland RD Center. Since version 9, I've taken over the
   development, because Michal has left the company.

TODO (optional):
- implement support for contiguous memory areas placed in HIGHMEM zone
- resolve issue with movable pages with pending io operations

Best regards
Marek Szyprowski
Samsung Poland RD Center


Links to previous versions of the patchset:
v16: http://www.spinics.net/lists/linux-mm/msg25066.html
v15: http://www.spinics.net/lists/linux-mm/msg23365.html
v14: http://www.spinics.net/lists/linux-media/msg36536.html
v13: (internal, intentionally not released)
v12: http://www.spinics.net/lists/linux-media/msg35674.html
v11: http://www.spinics.net/lists/linux-mm/msg21868.html
v10: http://www.spinics.net/lists/linux-mm/msg20761.html
 v9: http://article.gmane.org/gmane.linux.kernel.mm/60787
 v8: http://article.gmane.org/gmane.linux.kernel.mm/56855
 v7: http://article.gmane.org/gmane.linux.kernel.mm/55626
 v6: http://article.gmane.org/gmane.linux.kernel.mm/55626
 v5: (intentionally left out as CMA v5 was identical to CMA v4)
 v4: http://article.gmane.org/gmane.linux.kernel.mm/52010
 v3: http://article.gmane.org/gmane.linux.kernel.mm/51573
 v2: http://article.gmane.org/gmane.linux.kernel.mm/50986
 v1: http://article.gmane.org/gmane.linux.kernel.mm/50669


Changelog:

v17:
1. Replaced whole CMA core memory migration code to the new one kindly
   provided by 

[PATCH 09/11] X86: integrate CMA with DMA-mapping subsystem

2011-11-18 Thread Marek Szyprowski
This patch adds support for CMA to dma-mapping subsystem for x86
architecture that uses common pci-dma/pci-nommu implementation. This
allows to test CMA on KVM/QEMU and a lot of common x86 boxes.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
CC: Michal Nazarewicz min...@mina86.com
---
 arch/x86/Kconfig  |1 +
 arch/x86/include/asm/dma-contiguous.h |   13 +
 arch/x86/include/asm/dma-mapping.h|4 
 arch/x86/kernel/pci-dma.c |   18 --
 arch/x86/kernel/pci-nommu.c   |8 +---
 arch/x86/kernel/setup.c   |2 ++
 6 files changed, 37 insertions(+), 9 deletions(-)
 create mode 100644 arch/x86/include/asm/dma-contiguous.h

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index cb9a104..57a7177 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -29,6 +29,7 @@ config X86
select ARCH_WANT_OPTIONAL_GPIOLIB
select ARCH_WANT_FRAME_POINTERS
select HAVE_DMA_ATTRS
+   select HAVE_DMA_CONTIGUOUS if !SWIOTLB
select HAVE_KRETPROBES
select HAVE_OPTPROBES
select HAVE_FTRACE_MCOUNT_RECORD
diff --git a/arch/x86/include/asm/dma-contiguous.h 
b/arch/x86/include/asm/dma-contiguous.h
new file mode 100644
index 000..8fb117d
--- /dev/null
+++ b/arch/x86/include/asm/dma-contiguous.h
@@ -0,0 +1,13 @@
+#ifndef ASMX86_DMA_CONTIGUOUS_H
+#define ASMX86_DMA_CONTIGUOUS_H
+
+#ifdef __KERNEL__
+
+#include linux/device.h
+#include linux/dma-contiguous.h
+#include asm-generic/dma-contiguous.h
+
+static inline void dma_contiguous_early_fixup(phys_addr_t base, unsigned long 
size) { }
+
+#endif
+#endif
diff --git a/arch/x86/include/asm/dma-mapping.h 
b/arch/x86/include/asm/dma-mapping.h
index ed3065f..90ac6f0 100644
--- a/arch/x86/include/asm/dma-mapping.h
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -13,6 +13,7 @@
 #include asm/io.h
 #include asm/swiotlb.h
 #include asm-generic/dma-coherent.h
+#include linux/dma-contiguous.h
 
 #ifdef CONFIG_ISA
 # define ISA_DMA_BIT_MASK DMA_BIT_MASK(24)
@@ -61,6 +62,9 @@ extern int dma_set_mask(struct device *dev, u64 mask);
 extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_addr, gfp_t flag);
 
+extern void dma_generic_free_coherent(struct device *dev, size_t size,
+ void *vaddr, dma_addr_t dma_addr);
+
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t 
size)
 {
if (!dev-dma_mask)
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 80dc793..f4abafc 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -90,14 +90,18 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t 
size,
 dma_addr_t *dma_addr, gfp_t flag)
 {
unsigned long dma_mask;
-   struct page *page;
+   struct page *page = NULL;
+   unsigned int count = PAGE_ALIGN(size)  PAGE_SHIFT;
dma_addr_t addr;
 
dma_mask = dma_alloc_coherent_mask(dev, flag);
 
flag |= __GFP_ZERO;
 again:
-   page = alloc_pages_node(dev_to_node(dev), flag, get_order(size));
+   if (!(flag  GFP_ATOMIC))
+   page = dma_alloc_from_contiguous(dev, count, get_order(size));
+   if (!page)
+   page = alloc_pages_node(dev_to_node(dev), flag, 
get_order(size));
if (!page)
return NULL;
 
@@ -117,6 +121,16 @@ again:
return page_address(page);
 }
 
+void dma_generic_free_coherent(struct device *dev, size_t size, void *vaddr,
+  dma_addr_t dma_addr)
+{
+   unsigned int count = PAGE_ALIGN(size)  PAGE_SHIFT;
+   struct page *page = virt_to_page(vaddr);
+
+   if (!dma_release_from_contiguous(dev, page, count))
+   free_pages((unsigned long)vaddr, get_order(size));
+}
+
 /*
  * See Documentation/x86/x86_64/boot-options.txt for the iommu kernel
  * parameter documentation.
diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
index 3af4af8..656566f 100644
--- a/arch/x86/kernel/pci-nommu.c
+++ b/arch/x86/kernel/pci-nommu.c
@@ -74,12 +74,6 @@ static int nommu_map_sg(struct device *hwdev, struct 
scatterlist *sg,
return nents;
 }
 
-static void nommu_free_coherent(struct device *dev, size_t size, void *vaddr,
-   dma_addr_t dma_addr)
-{
-   free_pages((unsigned long)vaddr, get_order(size));
-}
-
 static void nommu_sync_single_for_device(struct device *dev,
dma_addr_t addr, size_t size,
enum dma_data_direction dir)
@@ -97,7 +91,7 @@ static void nommu_sync_sg_for_device(struct device *dev,
 
 struct dma_map_ops nommu_dma_ops = {
.alloc_coherent = dma_generic_alloc_coherent,
-   .free_coherent  = nommu_free_coherent,
+   .free_coherent  = 

[PATCH 04/11] mm: compaction: export some of the functions

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

This commit exports some of the functions from compaction.c file
outside of it adding their declaration into internal.h header
file so that other mm related code can use them.

This forced compaction.c to always be compiled (as opposed to being
compiled only if CONFIG_COMPACTION is defined) but as to avoid
introducing code that user did not ask for, part of the compaction.c
is now wrapped in on #ifdef.

Signed-off-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 mm/Makefile |3 +-
 mm/compaction.c |  112 +++
 mm/internal.h   |   35 +
 3 files changed, 83 insertions(+), 67 deletions(-)

diff --git a/mm/Makefile b/mm/Makefile
index 50ec00e..24ed801 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -13,7 +13,7 @@ obj-y := filemap.o mempool.o oom_kill.o 
fadvise.o \
   readahead.o swap.o truncate.o vmscan.o shmem.o \
   prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
   page_isolation.o mm_init.o mmu_context.o percpu.o \
-  $(mmu-y)
+  $(mmu-y) compaction.o
 obj-y += init-mm.o
 
 ifdef CONFIG_NO_BOOTMEM
@@ -32,7 +32,6 @@ obj-$(CONFIG_NUMA)+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)+= sparse.o
 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
 obj-$(CONFIG_SLOB) += slob.o
-obj-$(CONFIG_COMPACTION) += compaction.o
 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
 obj-$(CONFIG_KSM) += ksm.o
 obj-$(CONFIG_PAGE_POISONING) += debug-pagealloc.o
diff --git a/mm/compaction.c b/mm/compaction.c
index 09c9702..e71ceaf 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -19,28 +19,7 @@
 #define CREATE_TRACE_POINTS
 #include trace/events/compaction.h
 
-/*
- * compact_control is used to track pages being migrated and the free pages
- * they are being migrated to during memory compaction. The free_pfn starts
- * at the end of a zone and migrate_pfn begins at the start. Movable pages
- * are moved to the end of a zone during a compaction run and the run
- * completes when free_pfn = migrate_pfn
- */
-struct compact_control {
-   struct list_head freepages; /* List of free pages to migrate to */
-   struct list_head migratepages;  /* List of pages being migrated */
-   unsigned long nr_freepages; /* Number of isolated free pages */
-   unsigned long nr_migratepages;  /* Number of pages to migrate */
-   unsigned long free_pfn; /* isolate_freepages search base */
-   unsigned long migrate_pfn;  /* isolate_migratepages search base */
-   bool sync;  /* Synchronous migration */
-
-   unsigned int order; /* order a direct compactor needs */
-   int migratetype;/* MOVABLE, RECLAIMABLE etc */
-   struct zone *zone;
-};
-
-static unsigned long release_freepages(struct list_head *freelist)
+unsigned long release_freepages(struct list_head *freelist)
 {
struct page *page, *next;
unsigned long count = 0;
@@ -71,7 +50,7 @@ static unsigned long release_freepages(struct list_head 
*freelist)
  * Returns number of isolated pages.  This may be more then end-start
  * if end fell in a middle of a free page.
  */
-static unsigned long
+unsigned long
 isolate_freepages_range(struct zone *zone,
unsigned long start, unsigned long end,
struct list_head *freelist)
@@ -263,13 +242,6 @@ static bool too_many_isolated(struct zone *zone)
return isolated  (inactive + active) / 2;
 }
 
-/* possible outcome of isolate_migratepages */
-typedef enum {
-   ISOLATE_ABORT,  /* Abort compaction now */
-   ISOLATE_NONE,   /* No pages isolated, continue scanning */
-   ISOLATE_SUCCESS,/* Pages isolated, migrate */
-} isolate_migrate_t;
-
 /**
  * isolate_migratepages_range() - isolate all migrate-able pages in range.
  * @zone:  Zone pages are in.
@@ -289,7 +261,7 @@ typedef enum {
  * does not modify any cc's fields, ie. it does not modify (or read
  * for that matter) cc-migrate_pfn.
  */
-static unsigned long
+unsigned long
 isolate_migratepages_range(struct zone *zone, struct compact_control *cc,
   unsigned long low_pfn, unsigned long end_pfn)
 {
@@ -404,43 +376,11 @@ isolate_migratepages_range(struct zone *zone, struct 
compact_control *cc,
 }
 
 /*
- * Isolate all pages that can be migrated from the block pointed to by
- * the migrate scanner within compact_control.
- */
-static isolate_migrate_t isolate_migratepages(struct zone *zone,
-   struct compact_control *cc)
-{
-   unsigned long low_pfn, end_pfn;
-
-   /* Do not scan outside zone boundaries */
-   low_pfn = max(cc-migrate_pfn, zone-zone_start_pfn);
-
-   /* Only scan within a pageblock boundary 

[PATCH 01/11] mm: page_alloc: handle MIGRATE_ISOLATE in free_pcppages_bulk()

2011-11-18 Thread Marek Szyprowski
From: Michal Nazarewicz min...@mina86.com

If page is on PCP list while pageblock it belongs to gets isolated,
the page's private still holds the old migrate type.  This means
that free_pcppages_bulk() will put the page on a freelist of the
old migrate type instead of MIGRATE_ISOLATE.

This commit changes that by explicitly checking whether page's
pageblock's migrate type is MIGRATE_ISOLATE and if it is, overwrites
page's private data.

Signed-off-by: Michal Nazarewicz min...@mina86.com
Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 mm/page_alloc.c |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9dd443d..58d1a2e 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -628,6 +628,18 @@ static void free_pcppages_bulk(struct zone *zone, int 
count,
page = list_entry(list-prev, struct page, lru);
/* must delete as __free_one_page list manipulates */
list_del(page-lru);
+
+   /*
+* When page is isolated in set_migratetype_isolate()
+* function it's page_private is not changed since the
+* function has no way of knowing if it can touch it.
+* This means that when a page is on PCP list, it's
+* page_private no longer matches the desired migrate
+* type.
+*/
+   if (get_pageblock_migratetype(page) == MIGRATE_ISOLATE)
+   set_page_private(page, MIGRATE_ISOLATE);
+
/* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
__free_one_page(page, zone, 0, page_private(page));
trace_mm_page_pcpu_drain(page, 0, page_private(page));
-- 
1.7.1.569.g6f426

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Mygica U6012B support

2011-11-18 Thread M Eaton
I recently purchased a Mygica U6012B hybrid ATSC usb tuner, and made
an attempt at adding support.

It has the following chips (by visual inspection):
CX23102
CX24227
TDA18271

I based the GPIO and memory address on the inf file that came with the
tuner: http://sites.google.com/a/divinehawk.com/tv/home/GTATSC.inf

Here is the patch and the logs from inserting and scanning. I am
unable to pick up anything on my scans - what is my next step? Any
help appreciated!

diff -ur linux/drivers/media/video/cx231xx/cx231xx-avcore.c
newlinux/drivers/media/video/cx231xx/cx231xx-avcore.c
--- linux/drivers/media/video/cx231xx/cx231xx-avcore.c  2011-06-21
23:45:32.0 -0400
+++ newlinux/drivers/media/video/cx231xx/cx231xx-avcore.c   2011-11-18
08:23:27.595967953 -0500
@@ -352,6 +352,7 @@
case CX231XX_BOARD_CNXT_RDE_253S:
case CX231XX_BOARD_CNXT_RDU_253S:
case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
+   case CX231XX_BOARD_GTECH_U6012B:
case CX231XX_BOARD_HAUPPAUGE_EXETER:
case CX231XX_BOARD_HAUPPAUGE_USBLIVE2:
case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
@@ -1730,6 +1731,7 @@
case CX231XX_BOARD_CNXT_SHELBY:
case CX231XX_BOARD_CNXT_RDU_250:
case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
+   case CX231XX_BOARD_GTECH_U6012B:
case CX231XX_BOARD_HAUPPAUGE_EXETER:
func_mode = 0x03;
break;
diff -ur linux/drivers/media/video/cx231xx/cx231xx-cards.c
newlinux/drivers/media/video/cx231xx/cx231xx-cards.c
--- linux/drivers/media/video/cx231xx/cx231xx-cards.c   2011-07-27
23:45:49.0 -0400
+++ newlinux/drivers/media/video/cx231xx/cx231xx-cards.c2011-11-18
08:26:04.480745912 -0500
@@ -336,6 +336,45 @@
}
},
},
+   [CX231XX_BOARD_GTECH_U6012B] = {
+   .name = GeniaTech/Mygica U6012B,
+   .tuner_type = TUNER_NXP_TDA18271,
+   .tuner_addr = 0x60,
+   .tuner_gpio = RDE250_XCV_TUNER,
+   .tuner_sif_gpio = 0x05,
+   .tuner_scl_gpio = 0x1a,
+   .tuner_sda_gpio = 0x1b,
+   .decoder = CX231XX_AVDECODER,
+   .output_mode = OUT_MODE_VIP11,
+   .demod_xfer_mode = 0,
+   .ctl_pin_status_mask = 0xFFC4,
+   .agc_analog_digital_select_gpio = 0x1c,
+   .gpio_pin_status_mask = 0x4001000,
+   .tuner_i2c_master = 1,
+   .demod_i2c_master = 2,
+   .has_dvb = 1,
+   .demod_addr = 0x19,
+   .norm = V4L2_STD_NTSC,
+
+   .input = {{
+   .type = CX231XX_VMUX_TELEVISION,
+   .vmux = CX231XX_VIN_3_1,
+   .amux = CX231XX_AMUX_VIDEO,
+   .gpio = NULL,
+   }, {
+   .type = CX231XX_VMUX_COMPOSITE1,
+   .vmux = CX231XX_VIN_2_1,
+   .amux = CX231XX_AMUX_LINE_IN,
+   .gpio = NULL,
+   }, {
+   .type = CX231XX_VMUX_SVIDEO,
+   .vmux = CX231XX_VIN_1_1 |
+   (CX231XX_VIN_1_2  8) |
+   CX25840_SVIDEO_ON,
+   .amux = CX231XX_AMUX_LINE_IN,
+   .gpio = NULL,
+   } },
+   },
[CX231XX_BOARD_HAUPPAUGE_EXETER] = {
.name = Hauppauge EXETER,
.tuner_type = TUNER_NXP_TDA18271,
@@ -624,6 +663,8 @@
 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
{USB_DEVICE(0x0572, 0x58A0),
 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
+   {USB_DEVICE(0x1F4D, 0x6011),
+.driver_info = CX231XX_BOARD_GTECH_U6012B},
{USB_DEVICE(0x2040, 0xb110),
 .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL},
{USB_DEVICE(0x2040, 0xb111),
diff -ur linux/drivers/media/video/cx231xx/cx231xx-core.c
newlinux/drivers/media/video/cx231xx/cx231xx-core.c
--- linux/drivers/media/video/cx231xx/cx231xx-core.c2011-06-21
23:45:32.0 -0400
+++ newlinux/drivers/media/video/cx231xx/cx231xx-core.c 2011-11-18
08:23:27.599967977 -0500
@@ -720,6 +720,7 @@
break;
case CX231XX_BOARD_CNXT_RDE_253S:
case CX231XX_BOARD_CNXT_RDU_253S:
+   case CX231XX_BOARD_GTECH_U6012B:
errCode = 
cx231xx_set_agc_analog_digital_mux_select(dev, 1);
break;
case CX231XX_BOARD_HAUPPAUGE_EXETER:
@@ -740,6 +741,7 @@
break;
case CX231XX_BOARD_CNXT_RDE_253S:
case CX231XX_BOARD_CNXT_RDU_253S:
+   case CX231XX_BOARD_GTECH_U6012B:
case CX231XX_BOARD_HAUPPAUGE_EXETER:
case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL:
@@ -1381,6 +1383,7 @@
break;
 

cron job: media_tree daily build: ERRORS

2011-11-18 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:Fri Nov 18 19:00:19 CET 2011
git hash:e9eb0dadba932940f721f9d27544a7818b2fa1c5
gcc version:  i686-linux-gcc (GCC) 4.6.1
host hardware:x86_64
host os:  3.0-4.slh.7-amd64

linux-git-arm-eabi-enoxys: WARNINGS
linux-git-arm-eabi-omap: WARNINGS
linux-git-armv5-ixp: WARNINGS
linux-git-i686: WARNINGS
linux-git-m32r: OK
linux-git-mips: WARNINGS
linux-git-powerpc64: WARNINGS
linux-git-x86_64: WARNINGS
linux-2.6.31.12-i686: ERRORS
linux-2.6.32.6-i686: ERRORS
linux-2.6.33-i686: ERRORS
linux-2.6.34-i686: ERRORS
linux-2.6.35.3-i686: ERRORS
linux-2.6.36-i686: WARNINGS
linux-2.6.37-i686: WARNINGS
linux-2.6.38.2-i686: WARNINGS
linux-2.6.39.1-i686: WARNINGS
linux-3.0-i686: WARNINGS
linux-3.1-i686: WARNINGS
linux-3.2-rc1-i686: ERRORS
linux-2.6.31.12-x86_64: ERRORS
linux-2.6.32.6-x86_64: ERRORS
linux-2.6.33-x86_64: ERRORS
linux-2.6.34-x86_64: ERRORS
linux-2.6.35.3-x86_64: ERRORS
linux-2.6.36-x86_64: WARNINGS
linux-2.6.37-x86_64: WARNINGS
linux-2.6.38.2-x86_64: WARNINGS
linux-2.6.39.1-x86_64: WARNINGS
linux-3.0-x86_64: WARNINGS
linux-3.1-x86_64: WARNINGS
linux-3.2-rc1-x86_64: ERRORS
spec-git: WARNINGS
sparse: ERRORS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Friday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Friday.tar.bz2

The V4L-DVB specification from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/media.html
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] go7007: Fix 2250 urb type

2011-11-18 Thread Pete Eberlein
commit a846d8fce9e8be30046be3c512982bd0345e7015
Author: Pete Eberlein p...@sensoray.com
Date:   Fri Nov 18 10:00:15 2011 -0800

go7007: Fix 2250 urb type

The 2250 board uses bulk endpoint for interrupt handling,
and should use a bulk urb instead of an int urb.

Signed-off-by: Pete Eberlein p...@sensoray.com

diff --git a/drivers/staging/media/go7007/go7007-usb.c 
b/drivers/staging/media/go7007/go7007-usb.c
index 3db3b0a..cffb0b3 100644
--- a/drivers/staging/media/go7007/go7007-usb.c
+++ b/drivers/staging/media/go7007/go7007-usb.c
@@ -1054,7 +1054,13 @@ static int go7007_usb_probe(struct usb_interface *intf,
else
go-hpi_ops = go7007_usb_onboard_hpi_ops;
go-hpi_context = usb;
-   usb_fill_int_urb(usb-intr_urb, usb-usbdev,
+   if (go-board_id == GO7007_BOARDID_SENSORAY_2250)
+   usb_fill_bulk_urb(usb-intr_urb, usb-usbdev,
+   usb_rcvbulkpipe(usb-usbdev, 4),
+   usb-intr_urb-transfer_buffer, 2*sizeof(u16),
+   go7007_usb_readinterrupt_complete, go);
+   else
+   usb_fill_int_urb(usb-intr_urb, usb-usbdev,
usb_rcvintpipe(usb-usbdev, 4),
usb-intr_urb-transfer_buffer, 2*sizeof(u16),
go7007_usb_readinterrupt_complete, go, 8);


--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Linaro-mm-sig] [PATCHv17 0/11] Contiguous Memory Allocator

2011-11-18 Thread sandeep patil
On Fri, Nov 18, 2011 at 8:43 AM, Marek Szyprowski
m.szyprow...@samsung.com wrote:
 Welcome everyone once again,

 Please notice that this patch series is aimed to start further
 discussion. There are still few issues that need to be resolved before
 CMA will be really ready. The most hot problem is the issue with movable
 pages that causes migration to fail from time to time. Our investigation
 leads us to the point that these rare pages cannot be migrated because
 there are some pending io operations on them.


I am running a simple test to allocate contiguous regions and write a log on
in a file on sdcard simultaneously. I can reproduce this migration failure 100%
times with it.
when I tracked the pages that failed to migrate, I found them on the
buffer head lru
list with a reference held on the buffer_head in the page, which
causes drop_buffers()
to fail.

So, i guess my question is, until all the migration failures are
tracked down and fixed,
is there a plan to retry the contiguous allocation from a new range in
the CMA region?

~ sandeep
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Linaro-mm-sig] [PATCHv17 0/11] Contiguous Memory Allocator

2011-11-18 Thread Michal Nazarewicz

On Fri, 18 Nov 2011 22:20:48 +0100, sandeep patil psandee...@gmail.com wrote:

I am running a simple test to allocate contiguous regions and write a log on
in a file on sdcard simultaneously. I can reproduce this migration failure 100%
times with it.
when I tracked the pages that failed to migrate, I found them on the
buffer head lru
list with a reference held on the buffer_head in the page, which
causes drop_buffers()
to fail.

So, i guess my question is, until all the migration failures are
tracked down and fixed,
is there a plan to retry the contiguous allocation from a new range in
the CMA region?


No.  Current CMA implementation will stick to the same range of pages also
on consequent allocations of the same size.

--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of  o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz(o o)
ooo +email/xmpp: m...@google.com--ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] MEM2MEM: Add support for eMMa-PrP mem2mem operations.

2011-11-18 Thread Robert Schwebel
On Fri, Nov 18, 2011 at 05:27:12PM +0100, javier Martin wrote:
 But yes, it could be possible. AFAIK, Sascha Hauer (added to CC) has a
 prototype driver for this one though.

Yes, we have indeed a prototype for the VPU, both on MX27 and MX53.
However, it wasn't changed to a mem2mem device yet, although that is
what needs to be done. Unfortunately, we currently do not have a
customer who would let us drive that forward, so it probably needs some
time until we find somebody and can work on that again.

rsc
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Linaro-mm-sig] [PATCHv17 0/11] Contiguous Memory Allocator

2011-11-18 Thread sandeep patil
2011/11/18 Michal Nazarewicz min...@mina86.com:
 On Fri, 18 Nov 2011 22:20:48 +0100, sandeep patil psandee...@gmail.com
 wrote:

 I am running a simple test to allocate contiguous regions and write a log
 on
 in a file on sdcard simultaneously. I can reproduce this migration failure
 100%
 times with it.
 when I tracked the pages that failed to migrate, I found them on the
 buffer head lru
 list with a reference held on the buffer_head in the page, which
 causes drop_buffers()
 to fail.

 So, i guess my question is, until all the migration failures are
 tracked down and fixed,
 is there a plan to retry the contiguous allocation from a new range in
 the CMA region?

 No.  Current CMA implementation will stick to the same range of pages also
 on consequent allocations of the same size.


Doesn't that mean the drivers that fail to allocate from contiguous DMA region
will fail, if the migration fails?

~ sandeep
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] omap3isp: Prevent pipelines that contain a crashed entity from starting

2011-11-18 Thread Laurent Pinchart
The OMAP3 ISP preview engine will violate the L4 bus protocol if we try
to write some of its internal registers after it failed to stop
properly. This generates an external abort on non-linefetch fault,
triggering a fatal kernel oops.

We can't always prevent preview engine stop failures (they can for
instance be caused by a sensor crash), but we can improve the system
reliability by refusing to start streaming on a pipeline that contains
a block that failed to crash. The driver will then eventually reset the
ISP (when all applications will have closed their file handles related
to OMAP3 ISP device nodes), making the ISP usable again.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Sakari Ailus sakari.ai...@maxwell.research.nokia.com
---
 drivers/media/video/omap3isp/isp.c |   24 ++--
 drivers/media/video/omap3isp/isp.h |3 ++-
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/media/video/omap3isp/isp.c 
b/drivers/media/video/omap3isp/isp.c
index b818cac..bad3f24 100644
--- a/drivers/media/video/omap3isp/isp.c
+++ b/drivers/media/video/omap3isp/isp.c
@@ -761,10 +761,21 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
entity = pad-entity;
subdev = media_entity_to_v4l2_subdev(entity);
 
+   /* The entity can already be running only if it failed to stop
+* at the last isp_disable_pipeline() call. This is a sign that
+* it likely crashed, and might not respond to read/write
+* operations on the L4 bus. This would result in a bus fault
+* and a kernel oops. Refuse to start streaming in that case.
+*/
+   if (isp-running  (1  subdev-entity.id))
+   return -EIO;
+
ret = v4l2_subdev_call(subdev, video, s_stream, mode);
if (ret  0  ret != -ENOIOCTLCMD)
return ret;
 
+   isp-running |= 1  subdev-entity.id;
+
if (subdev == isp-isp_ccdc.subdev) {
v4l2_subdev_call(isp-isp_aewb.subdev, video,
s_stream, mode);
@@ -882,12 +893,11 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
if (ret) {
dev_info(isp-dev, Unable to stop %s\n, subdev-name);
failure = -ETIMEDOUT;
+   } else {
+   isp-running = ~(1  subdev-entity.id);
}
}
 
-   if (failure  0)
-   isp-needs_reset = true;
-
return failure;
 }
 
@@ -1071,6 +1081,7 @@ static int isp_reset(struct isp_device *isp)
udelay(1);
}
 
+   isp-running = 0;
return 0;
 }
 
@@ -1500,10 +1511,11 @@ void omap3isp_put(struct isp_device *isp)
if (--isp-ref_count == 0) {
isp_disable_interrupts(isp);
isp_save_ctx(isp);
-   if (isp-needs_reset) {
+   /* Reset the ISP if an entity has failed to stop. This is the
+* only way to recover from such conditions.
+*/
+   if (isp-running)
isp_reset(isp);
-   isp-needs_reset = false;
-   }
isp_disable_clocks(isp);
}
mutex_unlock(isp-isp_mutex);
diff --git a/drivers/media/video/omap3isp/isp.h 
b/drivers/media/video/omap3isp/isp.h
index 705946e..c958f07 100644
--- a/drivers/media/video/omap3isp/isp.h
+++ b/drivers/media/video/omap3isp/isp.h
@@ -145,6 +145,7 @@ struct isp_platform_callback {
  * @raw_dmamask: Raw DMA mask
  * @stat_lock: Spinlock for handling statistics
  * @isp_mutex: Mutex for serializing requests to ISP.
+ * @running: Bitmask of running entities (indexed by entity ID)
  * @has_context: Context has been saved at least once and can be restored.
  * @ref_count: Reference count for handling multiple ISP requests.
  * @cam_ick: Pointer to camera interface clock structure.
@@ -184,7 +185,7 @@ struct isp_device {
/* ISP Obj */
spinlock_t stat_lock;   /* common lock for statistic drivers */
struct mutex isp_mutex; /* For handling ref_count field */
-   bool needs_reset;
+   u32 running;
int has_context;
int ref_count;
unsigned int autoidle;
-- 
Regards,

Laurent Pinchart

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html