[SerialICE] New patch to review for serialice: 8f1e36e Refactor logging functions

Kyösti Mälkki (kyosti.malkki@gmail.com) gerrit at coreboot.org
Mon Mar 4 09:46:24 CET 2013


Kyösti Mälkki (kyosti.malkki at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2579

-gerrit

commit 8f1e36e9f83bc221b2a303beabe804af472d5dbf
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date:   Sun Mar 3 14:07:18 2013 +0200

    Refactor logging functions
    
    This adds root_info() and resource_info() functions to add
    informational lines (tagged with I...) in the log.
    
    This also fixes index and cs:eip values printed for these lines.
    
    Change-Id: Ib83140037ef4e910f2828783fd7505eac74fac2f
    Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
 SerialICE/simba/hooks.lua     | 61 +++++++++++++++++++------------------------
 SerialICE/simba/output.lua    | 34 ++++++++++++++----------
 SerialICE/simba/pci_cfg.lua   |  6 ++---
 SerialICE/simba/serialice.lua |  6 ++---
 4 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/SerialICE/simba/hooks.lua b/SerialICE/simba/hooks.lua
index 72e1a55..7e530b1 100644
--- a/SerialICE/simba/hooks.lua
+++ b/SerialICE/simba/hooks.lua
@@ -1,10 +1,13 @@
 
 
-function new_list()
-	return { list = nil }
+froot = { id = 0, name = "SerialICE" }
+fresource = { id = 1, name = "Resource" }
+
+function new_hooks(str)
+	return { list = nil, name = str }
 end
 
-next_filter_id = 1
+next_filter_id = 2
 next_action_id = 1
 current_parent_id = 0
 
@@ -19,16 +22,15 @@ function new_parent_action()
 end
 
 
-io_hooks = new_list()
-mem_hooks = new_list()
-
-cpumsr_hooks = new_list()
-cpuid_hooks = new_list()
+io_hooks = new_hooks("IO")
+mem_hooks = new_hooks("MEM")
 
+cpumsr_hooks = new_hooks("CPU MSR")
+cpuid_hooks = new_hooks("CPUID")
 
 function enable_hook(list, filter)
 	if not filter then
-		printks(froot, "Enable_hook called with filter==nil\n")
+		root_info("Enable_hook called with filter==nil\n")
 		return
 	end
 
@@ -40,37 +42,27 @@ function enable_hook(list, filter)
 	end
 	if not found then
 		filter.id = next_filter_id
+		filter.list = list
 		next_filter_id = next_filter_id + 1
 		list.list = { next = list.list, hook = filter }
 	end
-	if (list == io_hooks) then
-		printks(fresource, "[%04x] IO [%04x-%04x] = %s\n",
-				filter.id, filter.base, filter.base + filter.size - 1, filter.name)
-	elseif (list == mem_hooks) then
-		printks(fresource, "[%04x] MEM [%08x-%08x] = %s\n",
-				filter.id, filter.base, filter.base + filter.size - 1, filter.name)
-	else
-		printks(fresource, "[%04x] %s\n", filter.id, filter.name)
-	end
+	update_hook(filter)
 	filter.enable = true
 end
 
-function disable_hook(list, filter)
-	if not filter then
-		return
-	end
-	local l = list.list
-	local found = false
-	while l and not found do
-		found = (l.hook == filter)
-		l = l.next
+function disable_hook(f)
+	if f.id and f.enable and f.enable == true then
+		resource_info(f, "disabled")
 	end
-	if found then
-		printks(froot, "id=%04x disabled\n", filter.id)
-		filter.enable = false
+	f.enable = false
+end
+
+function update_hook(f)
+	if f.list == io_hooks or f.list == mem_hooks then
+		resource_info(f, "[%04x-%04x] = %s",
+				f.base, f.base + f.size - 1, f.name)
 	else
-		printks(filter, "disabled\n")
-		filter.enable = false
+		resource_info(f, "%s", f.name)
 	end
 end
 
@@ -157,7 +149,7 @@ function generic_io_bar(bar)
 	if (bar.f.base ~= 0) then
 		enable_hook(io_hooks, bar.f)
 	else
-		disable_hook(io_hooks, bar.f)
+		disable_hook(bar.f)
 	end
 end
 
@@ -176,7 +168,7 @@ function generic_mmio_bar(bar)
 	if bar.f.base ~= 0 then
 		enable_hook(mem_hooks, bar.f)
 	else
-		disable_hook(mem_hooks, bar.f)
+		disable_hook(bar.f)
 	end
 end
 
@@ -233,6 +225,7 @@ function pre_action(action, dir_wr, addr, size, data)
 	action.dropped = false
 	action.to_hw = false
 	action.to_qemu = false
+	action.info_only = false
 
 	action.write = dir_wr
 	action.addr = addr
diff --git a/SerialICE/simba/output.lua b/SerialICE/simba/output.lua
index fac895d..a01e074 100644
--- a/SerialICE/simba/output.lua
+++ b/SerialICE/simba/output.lua
@@ -1,14 +1,4 @@
 
-
-froot = {
-	id = 0,
-	name = "SerialICE",
-}
-
-fresource = {
-	name = "Resource",
-}
-
 -- -------------------------------------------------------------------
 -- logging functions
 
@@ -24,6 +14,8 @@ function printk(f, action, fmt, ...)
 	local str = ""
 	if action.undefined or action.f or action == cpu_action then
 		str = str .. "R"
+	elseif action.info_only then
+		str = str .. "I"
 	else
 		str = str .. "."
 	end
@@ -58,10 +50,24 @@ function printk(f, action, fmt, ...)
 	end
 end
 
-function printks(f, fmt, ...)
-	print_address(0,0,"I...",0,0)
-	printf("%s: ", f.name)
-	printf(fmt, ...)
+info_action = {}
+
+function print_info(f, str)
+	pre_action(info_action)
+	info_action.info_only = true
+	info_action.parent_id = current_parent_id
+	info_action.my_id = next_action_id
+	printk(f, info_action, "%s", str)
+end
+
+function root_info(fmt, ...)
+	print_info(froot, string.format(fmt, ...))
+end
+
+function resource_info(f, fmt, ...)
+	print_info(fresource,
+		string.format("[%04x] %s ", f.id, f.list.name) ..
+		string.format(fmt, ...) .. "\n")
 end
 
 function trim (s)
diff --git a/SerialICE/simba/pci_cfg.lua b/SerialICE/simba/pci_cfg.lua
index d874e9f..e7bdf65 100644
--- a/SerialICE/simba/pci_cfg.lua
+++ b/SerialICE/simba/pci_cfg.lua
@@ -8,11 +8,11 @@ pci_cfg_action = {}
 PCI_CFG_READ = false
 PCI_CFG_WRITE = true
 
-pci_cfg_hooks = new_list()
+pci_cfg_hooks = new_hooks("PCI")
 
 function add_pci_cfg_hook(dev, reg, size, func)
 	local bdfr = bit32.bor(dev.pci_dev, reg)
-	local name = string.format("PCI %x:%02x.%x [%04x]",
+	local name = string.format("%x:%02x.%x [%03x]",
 		bit32.band(0xff,bit32.rshift(bdfr, 20)), bit32.band(0x1f,bit32.rshift(bdfr, 15)),
 		bit32.band(0x7,bit32.rshift(bdfr, 12)), bit32.band(0xfff,bdfr))
 	local filter = {
@@ -327,6 +327,6 @@ end
 
 function pcie_mm_disable(dev, reg, base, size)
 	if dev.bar and dev.bar[reg] and dev.bar[reg].f then
-		disable_hook(mem_hooks, dev.bar[reg].f)
+		disable_hook(dev.bar[reg].f)
 	end
 end
diff --git a/SerialICE/simba/serialice.lua b/SerialICE/simba/serialice.lua
index 61e2fd1..82a2b03 100644
--- a/SerialICE/simba/serialice.lua
+++ b/SerialICE/simba/serialice.lua
@@ -98,16 +98,16 @@ if mainboard_script then
 	io.close(mainboard_script)
 	assert(mainboard_lua, ferr)
 	mainboard_lua()
-	printks(froot, "Mainboard script %s initialized.\n", mainboard_file)
+	root_info("Mainboard script %s initialized.\n", mainboard_file)
 	do_minimal_setup()
 	do_mainboard_setup()
 else
-	printks(froot, "Mainboard script %s not found.\n", mainboard_file)
+	root_info("Mainboard script %s not found.\n", mainboard_file)
 	do_minimal_setup()
 	do_default_setup()
 end
 
-printks(froot, "LUA script initialized.\n")
+root_info("LUA script initialized.\n")
 
 return true
 



More information about the SerialICE mailing list