Hi Mark,
On Wed, Aug 28, 2013 at 9:47 PM, Mark Cave-Ayland mark.cave-ayland@ilande.co.uk wrote:
On 27/08/13 11:10, Artyom Tarasenko wrote:
Hi Mark,
On Mon, Aug 26, 2013 at 11:05 PM, Mark Cave-Ayland mark.cave-ayland@ilande.co.uk wrote:
On 24/08/13 23:06, Andreas Färber wrote:
Signed-off-by: Andreas Färberandreas.faerber@web.de
arch/ppc/qemu/qemu.c | 18 ++++++++++-- config/examples/ppc64_config.xml | 1 + config/examples/ppc_config.xml | 1 + drivers/build.xml | 1 + drivers/m48t59.c | 60 ++++++++++++++++++++++++++++++++++++++++ include/drivers/drivers.h | 3 ++ 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 drivers/m48t59.c
diff --git a/arch/ppc/qemu/qemu.c b/arch/ppc/qemu/qemu.c index 381affb..1e3994c 100644 --- a/arch/ppc/qemu/qemu.c +++ b/arch/ppc/qemu/qemu.c @@ -80,9 +80,13 @@ printk( const char *fmt, ... ) int arch_nvram_size(void) { if (is_apple()) { +#ifdef CONFIG_DRIVER_MACIO return macio_get_nvram_size(); +#endif } else {
// not implemented
+#ifdef CONFIG_DRIVER_M48T59
return m48t59_nvram_size();
+#endif } return 0; } @@ -90,17 +94,25 @@ int arch_nvram_size(void) void arch_nvram_put(char *buf) { if (is_apple()) { +#ifdef CONFIG_DRIVER_MACIO macio_nvram_put(buf); +#endif } else {
// not implemented
+#ifdef CONFIG_DRIVER_M48T59
m48t59_nvram_put(buf);
+#endif } }
void arch_nvram_get(char *buf) { if (is_apple()) { +#ifdef CONFIG_DRIVER_MACIO macio_nvram_get(buf); +#endif } else {
// not implemented
+#ifdef CONFIG_DRIVER_M48T59
m48t59_nvram_get(buf);
+#endif } } diff --git a/config/examples/ppc64_config.xml b/config/examples/ppc64_config.xml index 5f79c21..04343b4 100644 --- a/config/examples/ppc64_config.xml +++ b/config/examples/ppc64_config.xml @@ -75,3 +75,4 @@ <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/> <option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xf0000510"/> +<option name="CONFIG_DRIVER_M48T59" type="boolean" value="false"/> diff --git a/config/examples/ppc_config.xml b/config/examples/ppc_config.xml index 5bb789f..2229f00 100644 --- a/config/examples/ppc_config.xml +++ b/config/examples/ppc_config.xml @@ -78,3 +78,4 @@ <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/> <option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xf0000510"/> +<option name="CONFIG_DRIVER_M48T59" type="boolean" value="true"/> diff --git a/drivers/build.xml b/drivers/build.xml index edec6b5..bcb21ae 100644 --- a/drivers/build.xml +++ b/drivers/build.xml @@ -22,6 +22,7 @@ <object source="pc_serial.c" condition="DRIVER_PC_SERIAL"/> <object source="escc.c" condition="DRIVER_ESCC"/> <object source="fw_cfg.c" condition="DRIVER_FW_CFG"/> +<object source="m48t59.c" condition="DRIVER_M48T59"/> </library>
<dictionary name="openbios" target="forth">
diff --git a/drivers/m48t59.c b/drivers/m48t59.c new file mode 100644 index 0000000..cd9e9f6 --- /dev/null +++ b/drivers/m48t59.c @@ -0,0 +1,60 @@ +/*
- OpenBIOS PReP m48t59 driver
- Copyright (c) 2013 Andreas Färber
- */
+#include "config.h"
+#include "drivers/drivers.h" +#include "asm/io.h"
+#define PREP_NVRAM_SIZE 0x2000 +#define PREP_NVRAM_ADDR_LO 0x74 +#define PREP_NVRAM_ADDR_HI 0x75 +#define PREP_NVRAM_DATA 0x77
+static uint8_t m48t59_nvram_read_byte(uint16_t offset) +{
outb(offset& 0xff, PREP_NVRAM_ADDR_LO);
outb(offset>> 8, PREP_NVRAM_ADDR_HI);
return inb(PREP_NVRAM_DATA);
+}
+static void m48t59_nvram_read(uint16_t offset, char *buf, unsigned int len) +{
- unsigned int i;
- for (i = 0; i< len; i++) {
buf[i] = m48t59_nvram_read_byte(offset);
- }
+}
+static void m48t59_nvram_write_byte(uint16_t offset, uint8_t value) +{
outb(offset& 0xff, PREP_NVRAM_ADDR_LO);
outb(offset>> 8, PREP_NVRAM_ADDR_HI);
outb(value, PREP_NVRAM_DATA);
+}
+static void m48t59_nvram_write(uint16_t offset, const char *buf, unsigned int len) +{
- unsigned int i;
- for (i = 0; i< len; i++) {
m48t59_nvram_write_byte(offset, buf[i]);
- }
+}
+int m48t59_nvram_size(void) +{
- return PREP_NVRAM_SIZE;
+}
+void m48t59_nvram_put(char *buf) +{
- m48t59_nvram_write(0, buf, PREP_NVRAM_SIZE);
+}
+void m48t59_nvram_get(char *buf) +{
- m48t59_nvram_read(0, buf, PREP_NVRAM_SIZE);
+} diff --git a/include/drivers/drivers.h b/include/drivers/drivers.h index 47d730f..73da6a2 100644 --- a/include/drivers/drivers.h +++ b/include/drivers/drivers.h @@ -125,6 +125,9 @@ unsigned char keyboard_readdata(void); int macio_get_nvram_size(void); void macio_nvram_put(char *buf); void macio_nvram_get(char *buf); +int m48t59_nvram_size(void); +void m48t59_nvram_put(char *buf); +void m48t59_nvram_get(char *buf);
/* drivers/timer.c */ void setup_timers(void);
The basic patch looks good, although I have a feeling that the m48t59 is the same NVRAM chip used by SPARC64 so there could be some changes required to support both. Artyom, any thoughts?
The m48t59 wired differently on sun4u machines. PReP seems to use PIO, whereas sun4u uses MMIO for accessing the chip. (It is possible that both modes are supported on sun4u, but only MMIO is exposed to user via OBP, but I couldn't find any documentation which would prove or deny that).
No objections to this patch from my side.
Thanks Artyom.
Given that m48t59 could potentially be used across different architectures, on further inspection I'd prefer something a bit more generic and a bit less PReP-specific.
Oh. I missed that the file is located directly at drivers/ .You are right, it has to be a bit more generic. The NVRAM_SIZE must be the same accross different architectures, but ADDR_LO ADDR_HI and NVRAM_DATA are definitely not.
As a compromise, how about renaming the PREP_NVRAM_* constants to M48T59_NVRAM_* and moving them to a .h file somewhere under include/arch/ppc? Then at least if someone tries to re-use the driver in a different architecture, it will fail to compile which will serve as a reminder that some alterations to the interface will be required.
ATB,
Mark.