[PATCH 09/10] radeontool: document functions that require mapped control region

Jonathan Nieder jrnieder at gmail.com
Fri Feb 24 20:01:38 PST 2012


Add assertions to all functions that assume the caller has called
map_radeon_cntl_mem and radeon_cntl_mem is non-NULL.  Use assert()
uniformly for this, replacing the more verbose

	if (!radeon_cntl_mem)
		die("internal error");

since assert() tends to produce more useful output that precisely
pinpoints the call site.

The intent is to document the current assumptions before breaking
them by changing map_radeon_cntl() to sometimes leave radeon_cntl_mem
equal to NULL (for example, when no Radeon is present).

Signed-off-by: Jonathan Nieder <jrnieder at gmail.com>
---
 radeontool.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/radeontool.c b/radeontool.c
index bf1dc3c5..3ff691fa 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <assert.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -54,10 +55,7 @@ static unsigned int radeon_get(unsigned long offset, const char *name)
     unsigned int value;
     if(debug) 
         printf("reading %s (%lx) is ",name,offset);
-    if(radeon_cntl_mem == NULL) {
-        printf("internal error\n");
-	exit(-2);
-    };
+    assert(radeon_cntl_mem);
 #ifdef __powerpc__
     __asm__ __volatile__ ("lwbrx %0,%1,%2\n\t"
 			  "eieio"
@@ -75,10 +73,7 @@ static void radeon_set(unsigned long offset, const char *name, unsigned int valu
 {
     if(debug) 
         printf("writing %s (%lx) -> %08x\n",name,offset,value);
-    if(radeon_cntl_mem == NULL) {
-        printf("internal error\n");
-	exit(-2);
-    };
+    assert(radeon_cntl_mem);
 #ifdef __powerpc__
     __asm__ __volatile__ ("stwbrx %1,%2,%3\n\t"
 			  "eieio"
@@ -96,6 +91,7 @@ static unsigned int radeon_get_indexed(unsigned long index_offset,
 				       unsigned long index_mask)
 {
     unsigned int temp = offset;
+    assert(radeon_cntl_mem);
     if (index_mask) {
 	temp = radeon_get(index_offset, "index");
 	temp &= ~index_mask;
@@ -110,6 +106,7 @@ static void radeon_set_indexed(unsigned long index_offset,
                                const char *name, unsigned int value, int index_mask)
 {
     unsigned int temp = offset;
+    assert(radeon_cntl_mem);
     if (index_mask) {
 	temp = radeon_get(index_offset, "index");
 	temp &= ~index_mask;
@@ -164,6 +161,7 @@ void radeon_cmd_regs(void)
 {
 #define SHOW_REG(r) printf("%s\t%08x\n", #r, radeon_get(r, #r))
 #define SHOW_CLK_REG(r) printf("%s\t%08x\n", #r, radeon_get_indexed(RADEON_CLOCK_CNTL_INDEX, RADEON_CLOCK_CNTL_DATA, (r), #r, 0x3f))	
+	assert(radeon_cntl_mem);
 	SHOW_REG(RADEON_DAC_CNTL);
 	SHOW_REG(RADEON_DAC_EXT_CNTL);
 	SHOW_REG(RADEON_DAC_MACRO_CNTL);
@@ -727,6 +725,7 @@ void radeon_reg_match(const char *pattern)
     unsigned long address;
     unsigned int value;
 
+    assert(radeon_cntl_mem);
     if (pattern[0] == '0' && pattern[1] == 'x') {
         address = strtol(&(pattern[2]), NULL, 16);
         value = radeon_get(address, pattern);
@@ -801,6 +800,7 @@ void radeon_reg_set(const char *inname, unsigned int value)
     int i;
     unsigned long address;
 
+    assert(radeon_cntl_mem);
     if (inname[0] == '0' && inname[1] == 'x') {
         address = strtol(&(inname[2]), NULL, 16);
         set_reg(inname, "", address, value, radeon_get, radeon_set);
@@ -823,6 +823,7 @@ void radeon_cmd_bits(void)
 {
     unsigned int dac_cntl;
 
+    assert(radeon_cntl_mem);
     dac_cntl = radeon_get(RADEON_DAC_CNTL,"RADEON_DAC_CNTL");  
     printf("RADEON_DAC_CNTL=%08x (",dac_cntl);  
     if(dac_cntl & RADEON_DAC_RANGE_CNTL)
@@ -842,6 +843,7 @@ void radeon_cmd_dac(char *param)
 {
     unsigned long dac_cntl;
 
+    assert(radeon_cntl_mem);
     dac_cntl = radeon_get(RADEON_DAC_CNTL,"RADEON_DAC_CNTL");
     if(param == NULL) {
         printf("The radeon external DAC looks %s\n",(dac_cntl&(RADEON_DAC_PDWN))?"off":"on");
@@ -860,6 +862,7 @@ void radeon_cmd_light(char *param)
 {
     unsigned long lvds_gen_cntl;
 
+    assert(radeon_cntl_mem);
     lvds_gen_cntl = radeon_get(RADEON_LVDS_GEN_CNTL,"RADEON_LVDS_GEN_CNTL");
     if(param == NULL) {
         printf("The radeon backlight looks %s\n",(lvds_gen_cntl&(RADEON_LVDS_ON))?"on":"off");
@@ -878,6 +881,7 @@ void radeon_cmd_stretch(char *param)
 {
     unsigned long fp_vert_stretch,fp_horz_stretch;
 
+    assert(radeon_cntl_mem);
     fp_vert_stretch = radeon_get(RADEON_FP_VERT_STRETCH,"RADEON_FP_VERT_STRETCH");
     fp_horz_stretch = radeon_get(RADEON_FP_HORZ_STRETCH,"RADEON_FP_HORZ_STRETCH");
     if(param == NULL) {
-- 
1.7.9.2



More information about the xorg-driver-ati mailing list