Skip to contentSkip to conversation

linux: force proper address translation in Dell RBU

PATCH In review Jan Beulich 2 participants 4 messages Nov 19, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: force proper address translation in Dell RBU

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.

drivers/firmware/dell_rbu.c +42 -4
@@ -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 = -ENOMEM;
+			spin_lock(&rbu_data.lock);
+			goto out_alloc_packet_array;
+		}
+#endif
 
-		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 = packet_data_temp_buf;
 
 	pr_debug("create_packet: newpacket at physical addr %lx\n",
-		(unsigned long)virt_to_phys(newpacket->data));
+		(unsigned long)virt_to_bus(newpacket->data));
 
 	/* packets may not have fixed size */
 	newpacket->length = 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 = NULL;
 	unsigned long rc;
+#ifndef CONFIG_XEN
 	unsigned long img_buf_phys_addr;
+#endif
 	int ordernum;
 	int dma_alloc = 0;
 
@@ -433,15 +461,19 @@ static int img_update_realloc(unsigned l
 
 	spin_unlock(&rbu_data.lock);
 
+#ifndef CONFIG_XEN
 	ordernum = get_order(size);
 	image_update_buffer =
 		(unsigned char *) __get_free_pages(GFP_KERNEL, ordernum);
 
 	img_buf_phys_addr =
-		(unsigned long) virt_to_phys(image_update_buffer);
+		(unsigned long) virt_to_bus(image_update_buffer);
 
 	if (img_buf_phys_addr > BIOS_SCAN_LIMIT) {
 		free_pages((unsigned long) image_update_buffer, ordernum);
+#else
+	{
+#endif
 		ordernum = -1;
 		image_update_buffer = 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 = 0;
+
+#ifdef CONFIG_XEN
+	if (!is_initial_xendomain())
+		return -ENODEV;
+#endif
+
 	spin_lock_init(&rbu_data.lock);
 
 	init_packet_head();

Subject: force proper address translation in Dell RBU

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.

drivers/firmware/dell_rbu.c +42 -4

99 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line

"Jan Beulich" <[email protected]> 19.11.09 10:50 >>>

Replacing virt_to_phys() by virt_to_bus(), and adding code to ensure contiguity as required by the firmware.

While similar address translation changes are also needed in dcdbas, doing them is not sufficient for the driver to work under Xen. It also requires that the issuing on SMIs happens on physical CPU#0, which presently we can arrange for only by using domctl interfaces. I'm not certain however that I could, not being there is any interest in this in the first place, reliably backport to 2.6.18 the hack we use for this in our forward ported trees. Of course, some mechanism will certainly be needed in the pv-ops Dom0 case once that reaches the point where it can be used in products...

Jan

#2 lore raw
In reply to Jan Beulich
Quoted 18 lines · Jan Beulich

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.

drivers/firmware/dell_rbu.c +3 -0
@@ -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)) {

drivers/firmware/dell_rbu.c static int create_packet(void *data, siz · line 184

Quoted 10 lines
drivers/firmware/dell_rbu.c +10 -0
+			free_pages((unsigned long)packet_data_temp_buf,
+				   ordernum);
+			printk(KERN_WARNING
+				"dell_rbu:%s: failed to adjust new "
+				"packet\n", __func__);
+			retval = -ENOMEM;
+			spin_lock(&rbu_data.lock);
+			goto out_alloc_packet_array;
+		}
+#endif

I was under the impression we did not want to create any of the #ifdef CONFIG_XEN at all. As a matter of fact, to actually eliminate or minimize the level of them.

Is there no other way to do this?

#3 lore raw
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Jan Beulich

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.

Duh! I need my coffee. Obviously this patch is not for the pv-ops kernel - please do ignore my comments.