mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: Tony Luck <tony.luck@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Borislav Petkov <borislav.petkov@amd.com>
Subject: [RFC PATCH 1/3] Add DEVICE_BIT_ATTR
Date: Wed, 10 Oct 2012 16:19:59 +0200	[thread overview]
Message-ID: <1349878801-15956-2-git-send-email-bp@amd64.org> (raw)
In-Reply-To: <1349878801-15956-1-git-send-email-bp@amd64.org>

From: Borislav Petkov <borislav.petkov@amd.com>

Not-Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 drivers/base/core.c    | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/device.h |  9 +++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index abea76c36a4b..3946a6fbe7bf 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -171,6 +171,42 @@ ssize_t device_show_int(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(device_show_int);
 
+/*
+ * ->var is the bitvector and ->aux is the bit number
+ */
+ssize_t device_store_bit(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t size)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	u64 *bvec = (u64 *)ea->var;
+	u8 val, bit = ea->aux;
+
+	if (kstrtou8(buf, 10, &val) < 0)
+		return -EINVAL;
+
+	if (val > 63)
+		return -EINVAL;
+
+	if (val)
+		*bvec |=  BIT_64(bit);
+	else
+		*bvec &= ~BIT_64(bit);
+
+	return size;
+}
+EXPORT_SYMBOL_GPL(device_store_bit);
+
+ssize_t device_show_bit(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct dev_ext_attribute *ea = to_ext_attr(attr);
+	u64 *bvec = (u64 *)ea->var;
+	u8 bit = ea->aux;
+
+	return snprintf(buf, PAGE_SIZE, "%d\n", !!(*bvec & BIT_64(bit)));
+}
+EXPORT_SYMBOL_GPL(device_show_bit);
+
 /**
  *	device_release - free device structure.
  *	@kobj:	device's kobject.
diff --git a/include/linux/device.h b/include/linux/device.h
index 86ef6ab553b1..78ade603875f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -486,6 +486,7 @@ struct device_attribute {
 struct dev_ext_attribute {
 	struct device_attribute attr;
 	void *var;
+	u8 aux;
 };
 
 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
@@ -496,6 +497,10 @@ ssize_t device_show_int(struct device *dev, struct device_attribute *attr,
 			char *buf);
 ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
 			 const char *buf, size_t count);
+ssize_t device_show_bit(struct device *dev, struct device_attribute *attr,
+			char *buf);
+ssize_t device_store_bit(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t count);
 
 #define DEVICE_ATTR(_name, _mode, _show, _store) \
 	struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
@@ -505,6 +510,10 @@ ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
 #define DEVICE_INT_ATTR(_name, _mode, _var) \
 	struct dev_ext_attribute dev_attr_##_name = \
 		{ __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
+#define DEVICE_BIT_ATTR(_name, _mode, _bitvec, _bit) \
+	struct dev_ext_attribute dev_attr_##_name = \
+		{ __ATTR(_name, _mode, device_show_bit, device_store_bit), \
+			&(_bitvec), (_bit) }
 #define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
 	struct device_attribute dev_attr_##_name =		\
 		__ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
-- 
1.8.0.rc0.18.gf84667d


  reply	other threads:[~2012-10-10 14:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-10 14:19 [RFC PATCH 0/3] mca_config stuff Borislav Petkov
2012-10-10 14:19 ` Borislav Petkov [this message]
2012-10-10 14:20 ` [RFC PATCH 2/3] Change mce_dont_log_ce Borislav Petkov
2012-10-10 14:20 ` [RFC PATCH 3/3] Convert mce_disabled Borislav Petkov
2012-10-10 15:46   ` Luck, Tony
2012-10-10 15:53     ` Borislav Petkov
2012-10-12 10:50   ` Naveen N. Rao
2012-10-12 11:56     ` Borislav Petkov
2012-10-12 17:46       ` Luck, Tony
2012-10-12 21:58         ` Borislav Petkov
2012-10-15  5:53       ` Naveen N. Rao
2012-10-10 15:35 ` [RFC PATCH 0/3] mca_config stuff Luck, Tony
2012-10-10 19:53   ` Borislav Petkov

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=1349878801-15956-2-git-send-email-bp@amd64.org \
    --to=bp@amd64.org \
    --cc=borislav.petkov@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.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

Powered by JetHome