From: "Jan Beulich" Subject: [PATCH] linux: force proper address translation in Dell RBU Date: Thu, 19 Nov 2009 09:50:35 +0000 Message-ID: <4B0522FB0200007800020C9D@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC9E38AFB.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Douglas_Warzecha@Dell.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartC9E38AFB.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Replacing virt_to_phys() by virt_to_bus(), and adding code to ensure contiguity as required by the firmware. As usual, written and tested on 2.6.27.37 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich Tested-by: Douglas Warzecha --- sle11-2009-10-16.orig/drivers/firmware/dell_rbu.c 2009-02-02 = 09:22:26.000000000 +0100 +++ sle11-2009-10-16/drivers/firmware/dell_rbu.c 2009-10-26 = 16:34:16.000000000 +0100 @@ -169,9 +169,28 @@ static int create_packet(void *data, siz spin_lock(&rbu_data.lock); goto out_alloc_packet_array; } +#ifdef CONFIG_XEN + if (ordernum && xen_create_contiguous_region( + (unsigned long)packet_data_temp_buf, ordernum, 0)) = { + free_pages((unsigned long)packet_data_temp_buf, + ordernum); + printk(KERN_WARNING + "dell_rbu:%s: failed to adjust new " + "packet\n", __func__); + retval =3D -ENOMEM; + spin_lock(&rbu_data.lock); + goto out_alloc_packet_array; + } +#endif =20 - if ((unsigned long)virt_to_phys(packet_data_temp_buf) + if ((unsigned long)virt_to_bus(packet_data_temp_buf) < allocation_floor) { +#ifdef CONFIG_XEN + if (ordernum) + xen_destroy_contiguous_region( + (unsigned long)packet_data_temp_buf= , + ordernum); +#endif pr_debug("packet 0x%lx below floor at 0x%lx.\n", (unsigned long)virt_to_phys( packet_data_temp_buf), @@ -185,7 +204,7 @@ static int create_packet(void *data, siz newpacket->data =3D packet_data_temp_buf; =20 pr_debug("create_packet: newpacket at physical addr %lx\n", - (unsigned long)virt_to_phys(newpacket->data)); + (unsigned long)virt_to_bus(newpacket->data)); =20 /* packets may not have fixed size */ newpacket->length =3D length; @@ -204,7 +223,7 @@ out_alloc_packet_array: /* always free packet array */ for (;idx>0;idx--) { pr_debug("freeing unused packet below floor 0x%lx.\n", - (unsigned long)virt_to_phys( + (unsigned long)virt_to_bus( invalid_addr_packet_array[idx-1])); free_pages((unsigned long)invalid_addr_packet_array[idx-1],= ordernum); @@ -348,6 +367,13 @@ static void packet_empty_list(void) * to make sure there are no stale RBU packets left in = memory */ memset(newpacket->data, 0, rbu_data.packetsize); +#ifdef CONFIG_XEN + if (newpacket->ordernum) + xen_destroy_contiguous_region( + (unsigned long)newpacket->data, + newpacket->ordernum); +#endif + free_pages((unsigned long) newpacket->data, newpacket->ordernum); kfree(newpacket); @@ -402,7 +428,9 @@ static int img_update_realloc(unsigned l { unsigned char *image_update_buffer =3D NULL; unsigned long rc; +#ifndef CONFIG_XEN unsigned long img_buf_phys_addr; +#endif int ordernum; int dma_alloc =3D 0; =20 @@ -433,15 +461,19 @@ static int img_update_realloc(unsigned l =20 spin_unlock(&rbu_data.lock); =20 +#ifndef CONFIG_XEN ordernum =3D get_order(size); image_update_buffer =3D (unsigned char *) __get_free_pages(GFP_KERNEL, ordernum); =20 img_buf_phys_addr =3D - (unsigned long) virt_to_phys(image_update_buffer); + (unsigned long) virt_to_bus(image_update_buffer); =20 if (img_buf_phys_addr > BIOS_SCAN_LIMIT) { free_pages((unsigned long) image_update_buffer, ordernum); +#else + { +#endif ordernum =3D -1; image_update_buffer =3D dma_alloc_coherent(NULL, size, &dell_rbu_dmaaddr, GFP_KERNEL); @@ -706,6 +738,12 @@ static struct bin_attribute rbu_packet_s static int __init dcdrbu_init(void) { int rc =3D 0; + +#ifdef CONFIG_XEN + if (!is_initial_xendomain()) + return -ENODEV; +#endif + spin_lock_init(&rbu_data.lock); =20 init_packet_head(); --=__PartC9E38AFB.1__= Content-Type: text/plain; name="xenlinux-dell-rbu.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-dell-rbu.patch" Subject: force proper address translation in Dell RBU=0A=0AReplacing = virt_to_phys() by virt_to_bus(), and adding code to ensure=0Acontiguity as = required by the firmware.=0A=0AAs usual, written and tested on 2.6.27.37 = and made apply to the 2.6.18=0Atree without further testing.=0A=0ASigned-of= f-by: Jan Beulich =0ATested-by: Douglas Warzecha = =0A=0A--- sle11-2009-10-16.orig/drivers/firmware= /dell_rbu.c 2009-02-02 09:22:26.000000000 +0100=0A+++ sle11-2009-10-16/= drivers/firmware/dell_rbu.c 2009-10-26 16:34:16.000000000 +0100=0A@@ = -169,9 +169,28 @@ static int create_packet(void *data, siz=0A = spin_lock(&rbu_data.lock);=0A goto out_alloc_packet_array= ;=0A }=0A+#ifdef CONFIG_XEN=0A+ if (ordernum && = xen_create_contiguous_region(=0A+ (unsigned = long)packet_data_temp_buf, ordernum, 0)) {=0A+ free_pages(= (unsigned long)packet_data_temp_buf,=0A+ = ordernum);=0A+ printk(KERN_WARNING=0A+ = "dell_rbu:%s: failed to adjust new "=0A+ = "packet\n", __func__);=0A+ retval =3D -ENOMEM;=0A+ = spin_lock(&rbu_data.lock);=0A+ goto out_alloc_pack= et_array;=0A+ }=0A+#endif=0A =0A- if ((unsigned = long)virt_to_phys(packet_data_temp_buf)=0A+ if ((unsigned = long)virt_to_bus(packet_data_temp_buf)=0A < = allocation_floor) {=0A+#ifdef CONFIG_XEN=0A+ if = (ordernum)=0A+ xen_destroy_contiguous_region(=0A+ = (unsigned long)packet_data_temp_buf,=0A+ = ordernum);=0A+#endif=0A = pr_debug("packet 0x%lx below floor at 0x%lx.\n",=0A = (unsigned long)virt_to_phys(=0A = packet_data_temp_buf),=0A@@ -185,7 +204,7 @@ static int create_pack= et(void *data, siz=0A newpacket->data =3D packet_data_temp_buf;=0A =0A = pr_debug("create_packet: newpacket at physical addr %lx\n",=0A- = (unsigned long)virt_to_phys(newpacket->data));=0A+ (unsigned = long)virt_to_bus(newpacket->data));=0A =0A /* packets may not have = fixed size */=0A newpacket->length =3D length;=0A@@ -204,7 +223,7 = @@ out_alloc_packet_array:=0A /* always free packet array */=0A = for (;idx>0;idx--) {=0A pr_debug("freeing unused packet = below floor 0x%lx.\n",=0A- (unsigned long)virt_to_phys= (=0A+ (unsigned long)virt_to_bus(=0A = invalid_addr_packet_array[idx-1]));=0A free_pages((unsigned = long)invalid_addr_packet_array[idx-1],=0A ordernum);= =0A@@ -348,6 +367,13 @@ static void packet_empty_list(void)=0A * = to make sure there are no stale RBU packets left in memory=0A = */=0A memset(newpacket->data, 0, rbu_data.packetsize);=0A+#ifdef = CONFIG_XEN=0A+ if (newpacket->ordernum)=0A+ = xen_destroy_contiguous_region(=0A+ (unsigned = long)newpacket->data,=0A+ newpacket->ordernum= );=0A+#endif=0A+=0A free_pages((unsigned long) newpacket->data,= =0A newpacket->ordernum);=0A kfree(newpa= cket);=0A@@ -402,7 +428,9 @@ static int img_update_realloc(unsigned l=0A = {=0A unsigned char *image_update_buffer =3D NULL;=0A unsigned = long rc;=0A+#ifndef CONFIG_XEN=0A unsigned long img_buf_phys_addr;=0A= +#endif=0A int ordernum;=0A int dma_alloc =3D 0;=0A =0A@@ = -433,15 +461,19 @@ static int img_update_realloc(unsigned l=0A =0A = spin_unlock(&rbu_data.lock);=0A =0A+#ifndef CONFIG_XEN=0A ordernum = =3D get_order(size);=0A image_update_buffer =3D=0A = (unsigned char *) __get_free_pages(GFP_KERNEL, ordernum);=0A =0A = img_buf_phys_addr =3D=0A- (unsigned long) virt_to_phys(image_= update_buffer);=0A+ (unsigned long) virt_to_bus(image_update_bu= ffer);=0A =0A if (img_buf_phys_addr > BIOS_SCAN_LIMIT) {=0A = free_pages((unsigned long) image_update_buffer, ordernum);=0A+#else=0A+ = {=0A+#endif=0A ordernum =3D -1;=0A image_update_buffer= =3D dma_alloc_coherent(NULL, size,=0A &dell_rbu_dmaaddr, = GFP_KERNEL);=0A@@ -706,6 +738,12 @@ static struct bin_attribute rbu_packet_= s=0A static int __init dcdrbu_init(void)=0A {=0A int rc =3D = 0;=0A+=0A+#ifdef CONFIG_XEN=0A+ if (!is_initial_xendomain())=0A+ = return -ENODEV;=0A+#endif=0A+=0A spin_lock_init(&rbu_data.lock);=0A = =0A init_packet_head();=0A --=__PartC9E38AFB.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartC9E38AFB.1__=--