public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
From: Ben Elliston <bje@redhat.com>
To: sid@sources.redhat.com
Subject: New ro_value_control_register class
Date: Sun, 18 Nov 2001 11:07:00 -0000	[thread overview]
Message-ID: <15370.42327.275439.742878@scooby.brisbane.redhat.com> (raw)

The following patch adds a new sidutil:: "ro_value_control_register"
class which can be used to implement proper read-only registers where
the underlying value may be changed programmatically, but not via bus
accesses.  Does this look okay to commit?


2001-11-30  Ben Elliston  <bje@redhat.com>

	* sidbusutil.h (class ro_value_control_register): New class.
	(value_control_register::shift_amount): Make protected.

Index: sidbusutil.h
===================================================================
RCS file: /cvs/src/sid/include/sidbusutil.h,v
retrieving revision 1.53
diff -u -c -r1.53 sidbusutil.h
*** sidbusutil.h	2001/09/20 17:15:18	1.53
--- sidbusutil.h	2001/12/02 22:00:24
***************
*** 788,806 ****
  					 const value_control_register<DataType>& it);
      friend std::istream& operator >> <> (std::istream& i, 
  					 value_control_register<DataType>& it);
-   
- private:
-     DataType field_value;
      
      // return index of mask LSB
      unsigned shift_amount() const
        {
! 	DataType mask = this->get_mask ();
! 	for (unsigned i=0; i<sizeof(DataType)*8; i++)
! 	  if (mask & (1 << i))
! 	    return i;
! 	assert(0);
        }
    };
  
    // This is a type of control register whose value never changes.
--- 788,841 ----
  					 const value_control_register<DataType>& it);
      friend std::istream& operator >> <> (std::istream& i, 
  					 value_control_register<DataType>& it);
      
+   protected:
      // return index of mask LSB
      unsigned shift_amount() const
+     {
+       DataType mask = this->get_mask ();
+       for (unsigned i=0; i<sizeof(DataType)*8; i++)
+ 	if (mask & (1 << i))
+ 	  return i;
+       assert(0);
+     }
+     
+   private:
+     DataType field_value;
+   };
+ 
+   // This is a read-only value control register.  Its underlying value
+   // may be changed programmatically, but as far as a bus accessor is
+   // concerned, writing to the register has no effect.
+   template <typename DataType>
+   class ro_value_control_register: public value_control_register<DataType>
+   {
+   public:
+     ro_value_control_register(control_register_bank<DataType>* b,
+ 			      sid::host_int_4 o,
+ 			      DataType m,
+ 			      DataType v):
+       value_control_register<DataType>(b,o,m,true,true,v)
+     {}
+     
+     ro_value_control_register(control_register_bank<DataType>* b,
+ 			      sid::host_int_4 o,
+ 			      DataType m):
+       value_control_register<DataType>(b,o,m,true,true,0)
+     {}
+ 
+     // Some convenience operators for accessing register fields
+     void operator = (const DataType& v)
        {
! 	DataType shifted_v = v << this->shift_amount();
! 	value_control_register<DataType>::set (shifted_v, this->get_mask()); 
        }
+ 
+   protected:
+     void set (DataType set_value, DataType set_mask)
+     {
+       // do nothing
+     }
    };
  
    // This is a type of control register whose value never changes.

WARNING: multiple messages have this Message-ID
From: Ben Elliston <bje@redhat.com>
To: sid@sources.redhat.com
Subject: New ro_value_control_register class
Date: Sun, 02 Dec 2001 14:04:00 -0000	[thread overview]
Message-ID: <15370.42327.275439.742878@scooby.brisbane.redhat.com> (raw)
Message-ID: <20011202140400.VRtJRBuFD1Wlv831zoWOOzClpOgW5PbGTkMP_rkwK5A@z> (raw)

The following patch adds a new sidutil:: "ro_value_control_register"
class which can be used to implement proper read-only registers where
the underlying value may be changed programmatically, but not via bus
accesses.  Does this look okay to commit?


2001-11-30  Ben Elliston  <bje@redhat.com>

	* sidbusutil.h (class ro_value_control_register): New class.
	(value_control_register::shift_amount): Make protected.

Index: sidbusutil.h
===================================================================
RCS file: /cvs/src/sid/include/sidbusutil.h,v
retrieving revision 1.53
diff -u -c -r1.53 sidbusutil.h
*** sidbusutil.h	2001/09/20 17:15:18	1.53
--- sidbusutil.h	2001/12/02 22:00:24
***************
*** 788,806 ****
  					 const value_control_register<DataType>& it);
      friend std::istream& operator >> <> (std::istream& i, 
  					 value_control_register<DataType>& it);
-   
- private:
-     DataType field_value;
      
      // return index of mask LSB
      unsigned shift_amount() const
        {
! 	DataType mask = this->get_mask ();
! 	for (unsigned i=0; i<sizeof(DataType)*8; i++)
! 	  if (mask & (1 << i))
! 	    return i;
! 	assert(0);
        }
    };
  
    // This is a type of control register whose value never changes.
--- 788,841 ----
  					 const value_control_register<DataType>& it);
      friend std::istream& operator >> <> (std::istream& i, 
  					 value_control_register<DataType>& it);
      
+   protected:
      // return index of mask LSB
      unsigned shift_amount() const
+     {
+       DataType mask = this->get_mask ();
+       for (unsigned i=0; i<sizeof(DataType)*8; i++)
+ 	if (mask & (1 << i))
+ 	  return i;
+       assert(0);
+     }
+     
+   private:
+     DataType field_value;
+   };
+ 
+   // This is a read-only value control register.  Its underlying value
+   // may be changed programmatically, but as far as a bus accessor is
+   // concerned, writing to the register has no effect.
+   template <typename DataType>
+   class ro_value_control_register: public value_control_register<DataType>
+   {
+   public:
+     ro_value_control_register(control_register_bank<DataType>* b,
+ 			      sid::host_int_4 o,
+ 			      DataType m,
+ 			      DataType v):
+       value_control_register<DataType>(b,o,m,true,true,v)
+     {}
+     
+     ro_value_control_register(control_register_bank<DataType>* b,
+ 			      sid::host_int_4 o,
+ 			      DataType m):
+       value_control_register<DataType>(b,o,m,true,true,0)
+     {}
+ 
+     // Some convenience operators for accessing register fields
+     void operator = (const DataType& v)
        {
! 	DataType shifted_v = v << this->shift_amount();
! 	value_control_register<DataType>::set (shifted_v, this->get_mask()); 
        }
+ 
+   protected:
+     void set (DataType set_value, DataType set_mask)
+     {
+       // do nothing
+     }
    };
  
    // This is a type of control register whose value never changes.

             reply	other threads:[~2001-12-02 22:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-18 11:07 Ben Elliston [this message]
2001-12-02 14:04 ` Ben Elliston

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15370.42327.275439.742878@scooby.brisbane.redhat.com \
    --to=bje@redhat.com \
    --cc=sid@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).