[PATCH v2] ivtv: use arch_phys_wc_add() and require PAT disabled

2015-04-27 Thread Luis R. Rodriguez
From: Luis R. Rodriguez mcg...@suse.com

We are burrying direct access to MTRR code support on
x86 in order to take advantage of PAT. In the future we
also want to make the default behaviour of ioremap_nocache()
to use strong UC, use of mtrr_add() on those systems
would make write-combining void.

In order to help both enable us to later make strong
UC default and in order to phase out direct MTRR access
code port the driver over to arch_phys_wc_add() and
annotate that the device driver requires systems to
boot with PAT disabled, with the nopat kernel parameter.

This is a worthy comprmise given that the hardware is
really rare these days, and perhaps only some lost souls
in some third world country are expected to be using this
feature of the device driver.

Cc: Andy Walls awa...@md.metrocast.net
Cc: Mauro Carvalho Chehab mche...@osg.samsung.com
Cc: Andy Lutomirski l...@amacapital.net
Cc: Suresh Siddha sbsid...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Thomas Gleixner t...@linutronix.de
Cc: Juergen Gross jgr...@suse.com
Cc: Daniel Vetter daniel.vet...@ffwll.ch
Cc: Dave Airlie airl...@redhat.com
Cc: Bjorn Helgaas bhelg...@google.com
Cc: Antonino Daplas adap...@gmail.com
Cc: Jean-Christophe Plagniol-Villard plagn...@jcrosoft.com
Cc: Tomi Valkeinen tomi.valkei...@ti.com
Cc: Dave Hansen dave.han...@linux.intel.com
Cc: Arnd Bergmann a...@arndb.de
Cc: Michael S. Tsirkin m...@redhat.com
Cc: Stefan Bader stefan.ba...@canonical.com
Cc: Ville Syrjälä syrj...@sci.fi
Cc: Mel Gorman mgor...@suse.de
Cc: Vlastimil Babka vba...@suse.cz
Cc: Borislav Petkov b...@suse.de
Cc: Davidlohr Bueso dbu...@suse.de
Cc: konrad.w...@oracle.com
Cc: ville.syrj...@linux.intel.com
Cc: david.vra...@citrix.com
Cc: jbeul...@suse.com
Cc: toshi.k...@hp.com
Cc: Roger Pau Monné roger@citrix.com
Cc: linux-fb...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Cc: ivtv-de...@ivtvdriver.org
Cc: linux-media@vger.kernel.org
Cc: xen-de...@lists.xensource.com
Signed-off-by: Luis R. Rodriguez mcg...@suse.com
---

This v2 moves the PAT bail out error check on to ivtvfb_init()
as per Andy's request. It also removes some comment about TODO
items for PAT.

 drivers/media/pci/ivtv/Kconfig  |  3 +++
 drivers/media/pci/ivtv/ivtvfb.c | 58 -
 2 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/drivers/media/pci/ivtv/Kconfig b/drivers/media/pci/ivtv/Kconfig
index dd6ee57e..b2a7f88 100644
--- a/drivers/media/pci/ivtv/Kconfig
+++ b/drivers/media/pci/ivtv/Kconfig
@@ -57,5 +57,8 @@ config VIDEO_FB_IVTV
  This is used in the Hauppauge PVR-350 card. There is a driver
  homepage at http://www.ivtvdriver.org.
 
+ If you have this hardware you will need to boot with PAT disabled
+ on your x86 systems, use the nopat kernel parameter.
+
  To compile this driver as a module, choose M here: the
  module will be called ivtvfb.
diff --git a/drivers/media/pci/ivtv/ivtvfb.c b/drivers/media/pci/ivtv/ivtvfb.c
index 9ff1230..8761e3e 100644
--- a/drivers/media/pci/ivtv/ivtvfb.c
+++ b/drivers/media/pci/ivtv/ivtvfb.c
@@ -44,8 +44,8 @@
 #include linux/ivtvfb.h
 #include linux/slab.h
 
-#ifdef CONFIG_MTRR
-#include asm/mtrr.h
+#ifdef CONFIG_X86_64
+#include asm/pat.h
 #endif
 
 #include ivtv-driver.h
@@ -155,12 +155,11 @@ struct osd_info {
/* Buffer size */
u32 video_buffer_size;
 
-#ifdef CONFIG_MTRR
/* video_base rounded down as required by hardware MTRRs */
unsigned long fb_start_aligned_physaddr;
/* video_base rounded up as required by hardware MTRRs */
unsigned long fb_end_aligned_physaddr;
-#endif
+   int wc_cookie;
 
/* Store the buffer offset */
int set_osd_coords_x;
@@ -1099,6 +1098,8 @@ static int ivtvfb_init_vidmode(struct ivtv *itv)
 static int ivtvfb_init_io(struct ivtv *itv)
 {
struct osd_info *oi = itv-osd_info;
+   /* Find the largest power of two that maps the whole buffer */
+   int size_shift = 31;
 
mutex_lock(itv-serialize_lock);
if (ivtv_init_on_first_open(itv)) {
@@ -1132,29 +1133,16 @@ static int ivtvfb_init_io(struct ivtv *itv)
oi-video_pbase, oi-video_vbase,
oi-video_buffer_size / 1024);
 
-#ifdef CONFIG_MTRR
-   {
-   /* Find the largest power of two that maps the whole buffer */
-   int size_shift = 31;
-
-   while (!(oi-video_buffer_size  (1  size_shift))) {
-   size_shift--;
-   }
-   size_shift++;
-   oi-fb_start_aligned_physaddr = oi-video_pbase  ~((1  
size_shift) - 1);
-   oi-fb_end_aligned_physaddr = oi-video_pbase + 
oi-video_buffer_size;
-   oi-fb_end_aligned_physaddr += (1  size_shift) - 1;
-   oi-fb_end_aligned_physaddr = ~((1  size_shift) - 1);
-   if (mtrr_add(oi-fb_start_aligned_physaddr,
-   oi-fb_end_aligned_physaddr - 

Re: [PATCH v2] ivtv: use arch_phys_wc_add() and require PAT disabled

2015-04-27 Thread Andy Walls
On Mon, 2015-04-27 at 09:43 -0700, Luis R. Rodriguez wrote:
 From: Luis R. Rodriguez mcg...@suse.com
 
 We are burrying direct access to MTRR code support on
 x86 in order to take advantage of PAT. In the future we
 also want to make the default behaviour of ioremap_nocache()
 to use strong UC, use of mtrr_add() on those systems
 would make write-combining void.
 
 In order to help both enable us to later make strong
 UC default and in order to phase out direct MTRR access
 code port the driver over to arch_phys_wc_add() and
 annotate that the device driver requires systems to
 boot with PAT disabled, with the nopat kernel parameter.
 
 This is a worthy comprmise given that the hardware is
 really rare these days, and perhaps only some lost souls
 in some third world country are expected to be using this
 feature of the device driver.
 
 Cc: Andy Walls awa...@md.metrocast.net

Acked-by: Andy Walls awa...@md.metrocast.net

Regards,
Andy

 Cc: Mauro Carvalho Chehab mche...@osg.samsung.com
 Cc: Andy Lutomirski l...@amacapital.net
 Cc: Suresh Siddha sbsid...@gmail.com
 Cc: Ingo Molnar mi...@elte.hu
 Cc: Thomas Gleixner t...@linutronix.de
 Cc: Juergen Gross jgr...@suse.com
 Cc: Daniel Vetter daniel.vet...@ffwll.ch
 Cc: Dave Airlie airl...@redhat.com
 Cc: Bjorn Helgaas bhelg...@google.com
 Cc: Antonino Daplas adap...@gmail.com
 Cc: Jean-Christophe Plagniol-Villard plagn...@jcrosoft.com
 Cc: Tomi Valkeinen tomi.valkei...@ti.com
 Cc: Dave Hansen dave.han...@linux.intel.com
 Cc: Arnd Bergmann a...@arndb.de
 Cc: Michael S. Tsirkin m...@redhat.com
 Cc: Stefan Bader stefan.ba...@canonical.com
 Cc: Ville Syrjälä syrj...@sci.fi
 Cc: Mel Gorman mgor...@suse.de
 Cc: Vlastimil Babka vba...@suse.cz
 Cc: Borislav Petkov b...@suse.de
 Cc: Davidlohr Bueso dbu...@suse.de
 Cc: konrad.w...@oracle.com
 Cc: ville.syrj...@linux.intel.com
 Cc: david.vra...@citrix.com
 Cc: jbeul...@suse.com
 Cc: toshi.k...@hp.com
 Cc: Roger Pau Monné roger@citrix.com
 Cc: linux-fb...@vger.kernel.org
 Cc: linux-ker...@vger.kernel.org
 Cc: ivtv-de...@ivtvdriver.org
 Cc: linux-media@vger.kernel.org
 Cc: xen-de...@lists.xensource.com
 Signed-off-by: Luis R. Rodriguez mcg...@suse.com
 ---
 
 This v2 moves the PAT bail out error check on to ivtvfb_init()
 as per Andy's request. It also removes some comment about TODO
 items for PAT.
 
  drivers/media/pci/ivtv/Kconfig  |  3 +++
  drivers/media/pci/ivtv/ivtvfb.c | 58 
 -
  2 files changed, 26 insertions(+), 35 deletions(-)
 
 diff --git a/drivers/media/pci/ivtv/Kconfig b/drivers/media/pci/ivtv/Kconfig
 index dd6ee57e..b2a7f88 100644
 --- a/drivers/media/pci/ivtv/Kconfig
 +++ b/drivers/media/pci/ivtv/Kconfig
 @@ -57,5 +57,8 @@ config VIDEO_FB_IVTV
 This is used in the Hauppauge PVR-350 card. There is a driver
 homepage at http://www.ivtvdriver.org.
  
 +   If you have this hardware you will need to boot with PAT disabled
 +   on your x86 systems, use the nopat kernel parameter.
 +
 To compile this driver as a module, choose M here: the
 module will be called ivtvfb.
 diff --git a/drivers/media/pci/ivtv/ivtvfb.c b/drivers/media/pci/ivtv/ivtvfb.c
 index 9ff1230..8761e3e 100644
 --- a/drivers/media/pci/ivtv/ivtvfb.c
 +++ b/drivers/media/pci/ivtv/ivtvfb.c
 @@ -44,8 +44,8 @@
  #include linux/ivtvfb.h
  #include linux/slab.h
  
 -#ifdef CONFIG_MTRR
 -#include asm/mtrr.h
 +#ifdef CONFIG_X86_64
 +#include asm/pat.h
  #endif
  
  #include ivtv-driver.h
 @@ -155,12 +155,11 @@ struct osd_info {
   /* Buffer size */
   u32 video_buffer_size;
  
 -#ifdef CONFIG_MTRR
   /* video_base rounded down as required by hardware MTRRs */
   unsigned long fb_start_aligned_physaddr;
   /* video_base rounded up as required by hardware MTRRs */
   unsigned long fb_end_aligned_physaddr;
 -#endif
 + int wc_cookie;
  
   /* Store the buffer offset */
   int set_osd_coords_x;
 @@ -1099,6 +1098,8 @@ static int ivtvfb_init_vidmode(struct ivtv *itv)
  static int ivtvfb_init_io(struct ivtv *itv)
  {
   struct osd_info *oi = itv-osd_info;
 + /* Find the largest power of two that maps the whole buffer */
 + int size_shift = 31;
  
   mutex_lock(itv-serialize_lock);
   if (ivtv_init_on_first_open(itv)) {
 @@ -1132,29 +1133,16 @@ static int ivtvfb_init_io(struct ivtv *itv)
   oi-video_pbase, oi-video_vbase,
   oi-video_buffer_size / 1024);
  
 -#ifdef CONFIG_MTRR
 - {
 - /* Find the largest power of two that maps the whole buffer */
 - int size_shift = 31;
 -
 - while (!(oi-video_buffer_size  (1  size_shift))) {
 - size_shift--;
 - }
 - size_shift++;
 - oi-fb_start_aligned_physaddr = oi-video_pbase  ~((1  
 size_shift) - 1);
 - oi-fb_end_aligned_physaddr = oi-video_pbase + 
 oi-video_buffer_size;
 - oi-fb_end_aligned_physaddr += (1  size_shift) - 1;
 -