Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a0b2b4d authored by Andi Kleen's avatar Andi Kleen Committed by Greg Kroah-Hartman
Browse files

sysdev: Pass the attribute to the low level sysdev show/store function



This allow to dynamically generate attributes and share show/store
functions between attributes. Right now most attributes are generated
by special macros and lots of duplicated code. With the attribute
passed it's instead possible to attach some data to the attribute
and then use that in shared low level functions to do different things.

I need this for the dynamically generated bank attributes in the x86
machine check code, but it'll allow some further cleanups.

I converted all users in tree to the new show/store prototype. It's a single
huge patch to avoid unbisectable sections.

Runtime tested: x86-32, x86-64
Compiled only: ia64, powerpc
Not compile tested/only grep converted: sh, arm, avr32

Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 36ce6dad
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -130,7 +130,9 @@ static const struct leds_evt_name evt_names[] = {
	{ "red",   led_red_on,   led_red_off   },
	{ "red",   led_red_on,   led_red_off   },
};
};


static ssize_t leds_store(struct sys_device *dev, const char *buf, size_t size)
static ssize_t leds_store(struct sys_device *dev,
			struct sysdev_attribute *attr,
			const char *buf, size_t size)
{
{
	int ret = -EINVAL, len = strcspn(buf, " ");
	int ret = -EINVAL, len = strcspn(buf, " ");


+25 −13
Original line number Original line Diff line number Diff line
@@ -26,14 +26,16 @@ static DEFINE_PER_CPU(struct cpu, cpu_devices);
 * XXX: If/when a SMP-capable implementation of AVR32 will ever be
 * XXX: If/when a SMP-capable implementation of AVR32 will ever be
 * made, we must make sure that the code executes on the correct CPU.
 * made, we must make sure that the code executes on the correct CPU.
 */
 */
static ssize_t show_pc0event(struct sys_device *dev, char *buf)
static ssize_t show_pc0event(struct sys_device *dev,
			struct sysdev_attribute *attr, char *buf)
{
{
	unsigned long pccr;
	unsigned long pccr;


	pccr = sysreg_read(PCCR);
	pccr = sysreg_read(PCCR);
	return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f);
	return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f);
}
}
static ssize_t store_pc0event(struct sys_device *dev, const char *buf,
static ssize_t store_pc0event(struct sys_device *dev,
			struct sysdev_attribute *attr, const char *buf,
			      size_t count)
			      size_t count)
{
{
	unsigned long val;
	unsigned long val;
@@ -46,15 +48,17 @@ static ssize_t store_pc0event(struct sys_device *dev, const char *buf,
	sysreg_write(PCCR, val);
	sysreg_write(PCCR, val);
	return count;
	return count;
}
}
static ssize_t show_pc0count(struct sys_device *dev, char *buf)
static ssize_t show_pc0count(struct sys_device *dev,
			struct sysdev_attribute *attr, char *buf)
{
{
	unsigned long pcnt0;
	unsigned long pcnt0;


	pcnt0 = sysreg_read(PCNT0);
	pcnt0 = sysreg_read(PCNT0);
	return sprintf(buf, "%lu\n", pcnt0);
	return sprintf(buf, "%lu\n", pcnt0);
}
}
static ssize_t store_pc0count(struct sys_device *dev, const char *buf,
static ssize_t store_pc0count(struct sys_device *dev,
			      size_t count)
				struct sysdev_attribute *attr,
				const char *buf, size_t count)
{
{
	unsigned long val;
	unsigned long val;
	char *endp;
	char *endp;
@@ -67,14 +71,16 @@ static ssize_t store_pc0count(struct sys_device *dev, const char *buf,
	return count;
	return count;
}
}


static ssize_t show_pc1event(struct sys_device *dev, char *buf)
static ssize_t show_pc1event(struct sys_device *dev,
				struct sysdev_attribute *attr, char *buf)
{
{
	unsigned long pccr;
	unsigned long pccr;


	pccr = sysreg_read(PCCR);
	pccr = sysreg_read(PCCR);
	return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f);
	return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f);
}
}
static ssize_t store_pc1event(struct sys_device *dev, const char *buf,
static ssize_t store_pc1event(struct sys_device *dev,
			      struct sysdev_attribute *attr, const char *buf,
			      size_t count)
			      size_t count)
{
{
	unsigned long val;
	unsigned long val;
@@ -87,14 +93,16 @@ static ssize_t store_pc1event(struct sys_device *dev, const char *buf,
	sysreg_write(PCCR, val);
	sysreg_write(PCCR, val);
	return count;
	return count;
}
}
static ssize_t show_pc1count(struct sys_device *dev, char *buf)
static ssize_t show_pc1count(struct sys_device *dev,
				struct sysdev_attribute *attr, char *buf)
{
{
	unsigned long pcnt1;
	unsigned long pcnt1;


	pcnt1 = sysreg_read(PCNT1);
	pcnt1 = sysreg_read(PCNT1);
	return sprintf(buf, "%lu\n", pcnt1);
	return sprintf(buf, "%lu\n", pcnt1);
}
}
static ssize_t store_pc1count(struct sys_device *dev, const char *buf,
static ssize_t store_pc1count(struct sys_device *dev,
				struct sysdev_attribute *attr, const char *buf,
			      size_t count)
			      size_t count)
{
{
	unsigned long val;
	unsigned long val;
@@ -108,14 +116,16 @@ static ssize_t store_pc1count(struct sys_device *dev, const char *buf,
	return count;
	return count;
}
}


static ssize_t show_pccycles(struct sys_device *dev, char *buf)
static ssize_t show_pccycles(struct sys_device *dev,
				struct sysdev_attribute *attr, char *buf)
{
{
	unsigned long pccnt;
	unsigned long pccnt;


	pccnt = sysreg_read(PCCNT);
	pccnt = sysreg_read(PCCNT);
	return sprintf(buf, "%lu\n", pccnt);
	return sprintf(buf, "%lu\n", pccnt);
}
}
static ssize_t store_pccycles(struct sys_device *dev, const char *buf,
static ssize_t store_pccycles(struct sys_device *dev,
				struct sysdev_attribute *attr, const char *buf,
			      size_t count)
			      size_t count)
{
{
	unsigned long val;
	unsigned long val;
@@ -129,14 +139,16 @@ static ssize_t store_pccycles(struct sys_device *dev, const char *buf,
	return count;
	return count;
}
}


static ssize_t show_pcenable(struct sys_device *dev, char *buf)
static ssize_t show_pcenable(struct sys_device *dev,
			struct sysdev_attribute *attr, char *buf)
{
{
	unsigned long pccr;
	unsigned long pccr;


	pccr = sysreg_read(PCCR);
	pccr = sysreg_read(PCCR);
	return sprintf(buf, "%c\n", (pccr & 1)?'1':'0');
	return sprintf(buf, "%c\n", (pccr & 1)?'1':'0');
}
}
static ssize_t store_pcenable(struct sys_device *dev, const char *buf,
static ssize_t store_pcenable(struct sys_device *dev,
			      struct sysdev_attribute *attr, const char *buf,
			      size_t count)
			      size_t count)
{
{
	unsigned long pccr, val;
	unsigned long pccr, val;
+15 −7
Original line number Original line Diff line number Diff line
@@ -55,7 +55,8 @@ static u64 resources[NR_CPUS];


#define show(name) 							\
#define show(name) 							\
static ssize_t 								\
static ssize_t 								\
show_##name(struct sys_device *dev, char *buf)				\
show_##name(struct sys_device *dev, struct sysdev_attribute *attr,	\
		char *buf)						\
{									\
{									\
	u32 cpu=dev->id;						\
	u32 cpu=dev->id;						\
	return sprintf(buf, "%lx\n", name[cpu]);			\
	return sprintf(buf, "%lx\n", name[cpu]);			\
@@ -63,7 +64,8 @@ show_##name(struct sys_device *dev, char *buf) \


#define store(name)							\
#define store(name)							\
static ssize_t 								\
static ssize_t 								\
store_##name(struct sys_device *dev, const char *buf, size_t size)	\
store_##name(struct sys_device *dev, struct sysdev_attribute *attr,	\
					const char *buf, size_t size)	\
{									\
{									\
	unsigned int cpu=dev->id;					\
	unsigned int cpu=dev->id;					\
	name[cpu] = simple_strtoull(buf, NULL, 16);			\
	name[cpu] = simple_strtoull(buf, NULL, 16);			\
@@ -76,7 +78,8 @@ show(call_start)
 * processor. The cpu number in driver is only used for storing data.
 * processor. The cpu number in driver is only used for storing data.
 */
 */
static ssize_t
static ssize_t
store_call_start(struct sys_device *dev, const char *buf, size_t size)
store_call_start(struct sys_device *dev, struct sysdev_attribute *attr,
		const char *buf, size_t size)
{
{
	unsigned int cpu=dev->id;
	unsigned int cpu=dev->id;
	unsigned long call_start = simple_strtoull(buf, NULL, 16);
	unsigned long call_start = simple_strtoull(buf, NULL, 16);
@@ -124,14 +127,16 @@ show(err_type_info)
store(err_type_info)
store(err_type_info)


static ssize_t
static ssize_t
show_virtual_to_phys(struct sys_device *dev, char *buf)
show_virtual_to_phys(struct sys_device *dev, struct sysdev_attribute *attr,
			char *buf)
{
{
	unsigned int cpu=dev->id;
	unsigned int cpu=dev->id;
	return sprintf(buf, "%lx\n", phys_addr[cpu]);
	return sprintf(buf, "%lx\n", phys_addr[cpu]);
}
}


static ssize_t
static ssize_t
store_virtual_to_phys(struct sys_device *dev, const char *buf, size_t size)
store_virtual_to_phys(struct sys_device *dev, struct sysdev_attribute *attr,
			const char *buf, size_t size)
{
{
	unsigned int cpu=dev->id;
	unsigned int cpu=dev->id;
	u64 virt_addr=simple_strtoull(buf, NULL, 16);
	u64 virt_addr=simple_strtoull(buf, NULL, 16);
@@ -154,7 +159,8 @@ show(err_struct_info)
store(err_struct_info)
store(err_struct_info)


static ssize_t
static ssize_t
show_err_data_buffer(struct sys_device *dev, char *buf)
show_err_data_buffer(struct sys_device *dev,
			struct sysdev_attribute *attr, char *buf)
{
{
	unsigned int cpu=dev->id;
	unsigned int cpu=dev->id;


@@ -165,7 +171,9 @@ show_err_data_buffer(struct sys_device *dev, char *buf)
}
}


static ssize_t
static ssize_t
store_err_data_buffer(struct sys_device *dev, const char *buf, size_t size)
store_err_data_buffer(struct sys_device *dev,
			struct sysdev_attribute *attr,
			const char *buf, size_t size)
{
{
	unsigned int cpu=dev->id;
	unsigned int cpu=dev->id;
	int ret;
	int ret;
+11 −4
Original line number Original line Diff line number Diff line
@@ -28,7 +28,9 @@ static DEFINE_PER_CPU(struct cpu, cpu_devices);
/* Time in microseconds we delay before sleeping in the idle loop */
/* Time in microseconds we delay before sleeping in the idle loop */
DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 };
DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 };


static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf,
static ssize_t store_smt_snooze_delay(struct sys_device *dev,
				      struct sysdev_attribute *attr,
				      const char *buf,
				      size_t count)
				      size_t count)
{
{
	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
@@ -44,7 +46,9 @@ static ssize_t store_smt_snooze_delay(struct sys_device *dev, const char *buf,
	return count;
	return count;
}
}


static ssize_t show_smt_snooze_delay(struct sys_device *dev, char *buf)
static ssize_t show_smt_snooze_delay(struct sys_device *dev,
				     struct sysdev_attribute *attr,
				     char *buf)
{
{
	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
	struct cpu *cpu = container_of(dev, struct cpu, sysdev);


@@ -152,14 +156,17 @@ static unsigned long write_##NAME(unsigned long val) \
	mtspr(ADDRESS, val); \
	mtspr(ADDRESS, val); \
	return 0; \
	return 0; \
} \
} \
static ssize_t show_##NAME(struct sys_device *dev, char *buf) \
static ssize_t show_##NAME(struct sys_device *dev, \
			struct sysdev_attribute *attr, \
			char *buf) \
{ \
{ \
	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
	unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
	unsigned long val = run_on_cpu(cpu->sysdev.id, read_##NAME, 0); \
	return sprintf(buf, "%lx\n", val); \
	return sprintf(buf, "%lx\n", val); \
} \
} \
static ssize_t __used \
static ssize_t __used \
	store_##NAME(struct sys_device *dev, const char *buf, size_t count) \
	store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \
			const char *buf, size_t count) \
{ \
{ \
	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
	struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
	unsigned long val; \
	unsigned long val; \
+30 −15
Original line number Original line Diff line number Diff line
@@ -97,7 +97,8 @@ static u8 spu_read_register_value(struct sys_device *sysdev, union spe_reg __iom
	return value.spe[spu->spe_id];
	return value.spe[spu->spe_id];
}
}


static ssize_t spu_show_temp(struct sys_device *sysdev, char *buf)
static ssize_t spu_show_temp(struct sys_device *sysdev, struct sysdev_attribute *attr,
			char *buf)
{
{
	u8 value;
	u8 value;
	struct cbe_pmd_regs __iomem *pmd_regs;
	struct cbe_pmd_regs __iomem *pmd_regs;
@@ -146,32 +147,38 @@ static ssize_t store_throttle(struct cbe_pmd_regs __iomem *pmd_regs, const char
	return size;
	return size;
}
}


static ssize_t spu_show_throttle_end(struct sys_device *sysdev, char *buf)
static ssize_t spu_show_throttle_end(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return show_throttle(get_pmd_regs(sysdev), buf, 0);
	return show_throttle(get_pmd_regs(sysdev), buf, 0);
}
}


static ssize_t spu_show_throttle_begin(struct sys_device *sysdev, char *buf)
static ssize_t spu_show_throttle_begin(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return show_throttle(get_pmd_regs(sysdev), buf, 8);
	return show_throttle(get_pmd_regs(sysdev), buf, 8);
}
}


static ssize_t spu_show_throttle_full_stop(struct sys_device *sysdev, char *buf)
static ssize_t spu_show_throttle_full_stop(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return show_throttle(get_pmd_regs(sysdev), buf, 16);
	return show_throttle(get_pmd_regs(sysdev), buf, 16);
}
}


static ssize_t spu_store_throttle_end(struct sys_device *sysdev, const char *buf, size_t size)
static ssize_t spu_store_throttle_end(struct sys_device *sysdev,
			struct sysdev_attribute *attr, const char *buf, size_t size)
{
{
	return store_throttle(get_pmd_regs(sysdev), buf, size, 0);
	return store_throttle(get_pmd_regs(sysdev), buf, size, 0);
}
}


static ssize_t spu_store_throttle_begin(struct sys_device *sysdev, const char *buf, size_t size)
static ssize_t spu_store_throttle_begin(struct sys_device *sysdev,
			struct sysdev_attribute *attr, const char *buf, size_t size)
{
{
	return store_throttle(get_pmd_regs(sysdev), buf, size, 8);
	return store_throttle(get_pmd_regs(sysdev), buf, size, 8);
}
}


static ssize_t spu_store_throttle_full_stop(struct sys_device *sysdev, const char *buf, size_t size)
static ssize_t spu_store_throttle_full_stop(struct sys_device *sysdev,
			struct sysdev_attribute *attr, const char *buf, size_t size)
{
{
	return store_throttle(get_pmd_regs(sysdev), buf, size, 16);
	return store_throttle(get_pmd_regs(sysdev), buf, size, 16);
}
}
@@ -192,43 +199,51 @@ static ssize_t ppe_show_temp(struct sys_device *sysdev, char *buf, int pos)


/* shows the temperature of the DTS on the PPE,
/* shows the temperature of the DTS on the PPE,
 * located near the linear thermal sensor */
 * located near the linear thermal sensor */
static ssize_t ppe_show_temp0(struct sys_device *sysdev, char *buf)
static ssize_t ppe_show_temp0(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return ppe_show_temp(sysdev, buf, 32);
	return ppe_show_temp(sysdev, buf, 32);
}
}


/* shows the temperature of the second DTS on the PPE */
/* shows the temperature of the second DTS on the PPE */
static ssize_t ppe_show_temp1(struct sys_device *sysdev, char *buf)
static ssize_t ppe_show_temp1(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return ppe_show_temp(sysdev, buf, 0);
	return ppe_show_temp(sysdev, buf, 0);
}
}


static ssize_t ppe_show_throttle_end(struct sys_device *sysdev, char *buf)
static ssize_t ppe_show_throttle_end(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 32);
	return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 32);
}
}


static ssize_t ppe_show_throttle_begin(struct sys_device *sysdev, char *buf)
static ssize_t ppe_show_throttle_begin(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 40);
	return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 40);
}
}


static ssize_t ppe_show_throttle_full_stop(struct sys_device *sysdev, char *buf)
static ssize_t ppe_show_throttle_full_stop(struct sys_device *sysdev,
			struct sysdev_attribute *attr, char *buf)
{
{
	return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 48);
	return show_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, 48);
}
}


static ssize_t ppe_store_throttle_end(struct sys_device *sysdev, const char *buf, size_t size)
static ssize_t ppe_store_throttle_end(struct sys_device *sysdev,
			struct sysdev_attribute *attr, const char *buf, size_t size)
{
{
	return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 32);
	return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 32);
}
}


static ssize_t ppe_store_throttle_begin(struct sys_device *sysdev, const char *buf, size_t size)
static ssize_t ppe_store_throttle_begin(struct sys_device *sysdev,
			struct sysdev_attribute *attr, const char *buf, size_t size)
{
{
	return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 40);
	return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 40);
}
}


static ssize_t ppe_store_throttle_full_stop(struct sys_device *sysdev, const char *buf, size_t size)
static ssize_t ppe_store_throttle_full_stop(struct sys_device *sysdev,
			struct sysdev_attribute *attr, const char *buf, size_t size)
{
{
	return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 48);
	return store_throttle(cbe_get_cpu_pmd_regs(sysdev->id), buf, size, 48);
}
}
Loading