Skip to content

Commit bd9ba8f

Browse files
committed
zorro/UAPI: Use proper types (endianness/size) in <linux/zorro.h>
Fix member definitions for non-native userspace handling: - All multi-byte values are big-endian, hence use __be*, - All pointers are 32-bit pointers under AmigaOS, but unused (except for cd_BoardAddr) under Linux, hence use __be32. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
1 parent 986ea58 commit bd9ba8f

8 files changed

Lines changed: 72 additions & 46 deletions

File tree

‎arch/m68k/amiga/config.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/keyboard.h>
2929

3030
#include <asm/bootinfo.h>
31+
#include <asm/byteorder.h>
3132
#include <asm/setup.h>
3233
#include <asm/pgtable.h>
3334
#include <asm/amigahw.h>
@@ -176,10 +177,10 @@ int __init amiga_parse_bootinfo(const struct bi_record *record)
176177
const struct ConfigDev *cd = (struct ConfigDev *)data;
177178
struct zorro_dev_init *dev = &zorro_autocon_init[zorro_num_autocon++];
178179
dev->rom = cd->cd_Rom;
179-
dev->slotaddr = cd->cd_SlotAddr;
180-
dev->slotsize = cd->cd_SlotSize;
181-
dev->boardaddr = (u32)cd->cd_BoardAddr;
182-
dev->boardsize = cd->cd_BoardSize;
180+
dev->slotaddr = be16_to_cpu(cd->cd_SlotAddr);
181+
dev->slotsize = be16_to_cpu(cd->cd_SlotSize);
182+
dev->boardaddr = be32_to_cpu(cd->cd_BoardAddr);
183+
dev->boardsize = be32_to_cpu(cd->cd_BoardSize);
183184
} else
184185
printk("amiga_parse_bootinfo: too many AutoConfig devices\n");
185186
#endif /* CONFIG_ZORRO */

‎arch/m68k/amiga/platform.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <asm/amigahw.h>
1515
#include <asm/amigayle.h>
16+
#include <asm/byteorder.h>
1617

1718

1819
#ifdef CONFIG_ZORRO
@@ -66,10 +67,12 @@ static int __init z_dev_present(zorro_id id)
6667
{
6768
unsigned int i;
6869

69-
for (i = 0; i < zorro_num_autocon; i++)
70-
if (zorro_autocon_init[i].rom.er_Manufacturer == ZORRO_MANUF(id) &&
71-
zorro_autocon_init[i].rom.er_Product == ZORRO_PROD(id))
70+
for (i = 0; i < zorro_num_autocon; i++) {
71+
const struct ExpansionRom *rom = &zorro_autocon_init[i].rom;
72+
if (be16_to_cpu(rom->er_Manufacturer) == ZORRO_MANUF(id) &&
73+
rom->er_Product == ZORRO_PROD(id))
7274
return 1;
75+
}
7376

7477
return 0;
7578
}

‎drivers/net/ethernet/amd/a2065.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/zorro.h>
5858
#include <linux/bitops.h>
5959

60+
#include <asm/byteorder.h>
6061
#include <asm/irq.h>
6162
#include <asm/amigaints.h>
6263
#include <asm/amigahw.h>
@@ -678,6 +679,7 @@ static int a2065_init_one(struct zorro_dev *z,
678679
unsigned long base_addr = board + A2065_LANCE;
679680
unsigned long mem_start = board + A2065_RAM;
680681
struct resource *r1, *r2;
682+
u32 serial;
681683
int err;
682684

683685
r1 = request_mem_region(base_addr, sizeof(struct lance_regs),
@@ -702,6 +704,7 @@ static int a2065_init_one(struct zorro_dev *z,
702704
r1->name = dev->name;
703705
r2->name = dev->name;
704706

707+
serial = be32_to_cpu(z->rom.er_SerialNumber);
705708
dev->dev_addr[0] = 0x00;
706709
if (z->id != ZORRO_PROD_AMERISTAR_A2065) { /* Commodore */
707710
dev->dev_addr[1] = 0x80;
@@ -710,9 +713,9 @@ static int a2065_init_one(struct zorro_dev *z,
710713
dev->dev_addr[1] = 0x00;
711714
dev->dev_addr[2] = 0x9f;
712715
}
713-
dev->dev_addr[3] = (z->rom.er_SerialNumber >> 16) & 0xff;
714-
dev->dev_addr[4] = (z->rom.er_SerialNumber >> 8) & 0xff;
715-
dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
716+
dev->dev_addr[3] = (serial >> 16) & 0xff;
717+
dev->dev_addr[4] = (serial >> 8) & 0xff;
718+
dev->dev_addr[5] = serial & 0xff;
716719
dev->base_addr = (unsigned long)ZTWO_VADDR(base_addr);
717720
dev->mem_start = (unsigned long)ZTWO_VADDR(mem_start);
718721
dev->mem_end = dev->mem_start + A2065_RAM_SIZE;

‎drivers/net/ethernet/amd/ariadne.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <linux/zorro.h>
5252
#include <linux/bitops.h>
5353

54+
#include <asm/byteorder.h>
5455
#include <asm/amigaints.h>
5556
#include <asm/amigahw.h>
5657
#include <asm/irq.h>
@@ -718,6 +719,7 @@ static int ariadne_init_one(struct zorro_dev *z,
718719
struct resource *r1, *r2;
719720
struct net_device *dev;
720721
struct ariadne_private *priv;
722+
u32 serial;
721723
int err;
722724

723725
r1 = request_mem_region(base_addr, sizeof(struct Am79C960), "Am79C960");
@@ -741,12 +743,13 @@ static int ariadne_init_one(struct zorro_dev *z,
741743
r1->name = dev->name;
742744
r2->name = dev->name;
743745

746+
serial = be32_to_cpu(z->rom.er_SerialNumber);
744747
dev->dev_addr[0] = 0x00;
745748
dev->dev_addr[1] = 0x60;
746749
dev->dev_addr[2] = 0x30;
747-
dev->dev_addr[3] = (z->rom.er_SerialNumber >> 16) & 0xff;
748-
dev->dev_addr[4] = (z->rom.er_SerialNumber >> 8) & 0xff;
749-
dev->dev_addr[5] = z->rom.er_SerialNumber & 0xff;
750+
dev->dev_addr[3] = (serial >> 16) & 0xff;
751+
dev->dev_addr[4] = (serial >> 8) & 0xff;
752+
dev->dev_addr[5] = serial & 0xff;
750753
dev->base_addr = (unsigned long)ZTWO_VADDR(base_addr);
751754
dev->mem_start = (unsigned long)ZTWO_VADDR(mem_start);
752755
dev->mem_end = dev->mem_start + ARIADNE_RAM_SIZE;

‎drivers/zorro/proc.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/seq_file.h>
1515
#include <linux/init.h>
1616
#include <linux/export.h>
17+
18+
#include <asm/byteorder.h>
1719
#include <asm/uaccess.h>
1820
#include <asm/amigahw.h>
1921
#include <asm/setup.h>
@@ -41,10 +43,10 @@ proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *
4143
/* Construct a ConfigDev */
4244
memset(&cd, 0, sizeof(cd));
4345
cd.cd_Rom = z->rom;
44-
cd.cd_SlotAddr = z->slotaddr;
45-
cd.cd_SlotSize = z->slotsize;
46-
cd.cd_BoardAddr = (void *)zorro_resource_start(z);
47-
cd.cd_BoardSize = zorro_resource_len(z);
46+
cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
47+
cd.cd_SlotSize = cpu_to_be16(z->slotsize);
48+
cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
49+
cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
4850

4951
if (copy_to_user(buf, (void *)&cd + pos, nbytes))
5052
return -EFAULT;

‎drivers/zorro/zorro-sysfs.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <linux/stat.h>
1717
#include <linux/string.h>
1818

19+
#include <asm/byteorder.h>
20+
1921
#include "zorro.h"
2022

2123

@@ -33,10 +35,20 @@ static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
3335

3436
zorro_config_attr(id, id, "0x%08x\n");
3537
zorro_config_attr(type, rom.er_Type, "0x%02x\n");
36-
zorro_config_attr(serial, rom.er_SerialNumber, "0x%08x\n");
3738
zorro_config_attr(slotaddr, slotaddr, "0x%04x\n");
3839
zorro_config_attr(slotsize, slotsize, "0x%04x\n");
3940

41+
static ssize_t
42+
show_serial(struct device *dev, struct device_attribute *attr, char *buf)
43+
{
44+
struct zorro_dev *z;
45+
46+
z = to_zorro_dev(dev);
47+
return sprintf(buf, "0x%08x\n", be32_to_cpu(z->rom.er_SerialNumber));
48+
}
49+
50+
static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
51+
4052
static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *attr, char *buf)
4153
{
4254
struct zorro_dev *z = to_zorro_dev(dev);
@@ -60,10 +72,10 @@ static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj,
6072
/* Construct a ConfigDev */
6173
memset(&cd, 0, sizeof(cd));
6274
cd.cd_Rom = z->rom;
63-
cd.cd_SlotAddr = z->slotaddr;
64-
cd.cd_SlotSize = z->slotsize;
65-
cd.cd_BoardAddr = (void *)zorro_resource_start(z);
66-
cd.cd_BoardSize = zorro_resource_len(z);
75+
cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
76+
cd.cd_SlotSize = cpu_to_be16(z->slotsize);
77+
cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
78+
cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
6779

6880
return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd));
6981
}

‎drivers/zorro/zorro.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/platform_device.h>
1919
#include <linux/slab.h>
2020

21+
#include <asm/byteorder.h>
2122
#include <asm/setup.h>
2223
#include <asm/amigahw.h>
2324

@@ -161,7 +162,8 @@ static int __init amiga_zorro_probe(struct platform_device *pdev)
161162
z = &zorro_autocon[i];
162163

163164
z->rom = zi->rom;
164-
z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
165+
z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) |
166+
(z->rom.er_Product << 8);
165167
if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
166168
/* GVP quirk */
167169
unsigned long magic = zi->boardaddr + 0x8000;

‎include/uapi/linux/zorro.h‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,26 @@ enum GVP_flags {
6363

6464

6565
struct Node {
66-
struct Node *ln_Succ; /* Pointer to next (successor) */
67-
struct Node *ln_Pred; /* Pointer to previous (predecessor) */
68-
__u8 ln_Type;
69-
__s8 ln_Pri; /* Priority, for sorting */
70-
__s8 *ln_Name; /* ID string, null terminated */
66+
__be32 ln_Succ; /* Pointer to next (successor) */
67+
__be32 ln_Pred; /* Pointer to previous (predecessor) */
68+
__u8 ln_Type;
69+
__s8 ln_Pri; /* Priority, for sorting */
70+
__be32 ln_Name; /* ID string, null terminated */
7171
} __packed;
7272

7373
struct ExpansionRom {
7474
/* -First 16 bytes of the expansion ROM */
75-
__u8 er_Type; /* Board type, size and flags */
76-
__u8 er_Product; /* Product number, assigned by manufacturer */
77-
__u8 er_Flags; /* Flags */
78-
__u8 er_Reserved03; /* Must be zero ($ff inverted) */
79-
__u16 er_Manufacturer; /* Unique ID, ASSIGNED BY COMMODORE-AMIGA! */
80-
__u32 er_SerialNumber; /* Available for use by manufacturer */
81-
__u16 er_InitDiagVec; /* Offset to optional "DiagArea" structure */
82-
__u8 er_Reserved0c;
83-
__u8 er_Reserved0d;
84-
__u8 er_Reserved0e;
85-
__u8 er_Reserved0f;
75+
__u8 er_Type; /* Board type, size and flags */
76+
__u8 er_Product; /* Product number, assigned by manufacturer */
77+
__u8 er_Flags; /* Flags */
78+
__u8 er_Reserved03; /* Must be zero ($ff inverted) */
79+
__be16 er_Manufacturer; /* Unique ID, ASSIGNED BY COMMODORE-AMIGA! */
80+
__be32 er_SerialNumber; /* Available for use by manufacturer */
81+
__be16 er_InitDiagVec; /* Offset to optional "DiagArea" structure */
82+
__u8 er_Reserved0c;
83+
__u8 er_Reserved0d;
84+
__u8 er_Reserved0e;
85+
__u8 er_Reserved0f;
8686
} __packed;
8787

8888
/* er_Type board type bits */
@@ -99,13 +99,13 @@ struct ConfigDev {
9999
__u8 cd_Flags; /* (read/write) */
100100
__u8 cd_Pad; /* reserved */
101101
struct ExpansionRom cd_Rom; /* copy of board's expansion ROM */
102-
void *cd_BoardAddr; /* where in memory the board was placed */
103-
__u32 cd_BoardSize; /* size of board in bytes */
104-
__u16 cd_SlotAddr; /* which slot number (PRIVATE) */
105-
__u16 cd_SlotSize; /* number of slots (PRIVATE) */
106-
void *cd_Driver; /* pointer to node of driver */
107-
struct ConfigDev *cd_NextCD; /* linked list of drivers to config */
108-
__u32 cd_Unused[4]; /* for whatever the driver wants */
102+
__be32 cd_BoardAddr; /* where in memory the board was placed */
103+
__be32 cd_BoardSize; /* size of board in bytes */
104+
__be16 cd_SlotAddr; /* which slot number (PRIVATE) */
105+
__be16 cd_SlotSize; /* number of slots (PRIVATE) */
106+
__be32 cd_Driver; /* pointer to node of driver */
107+
__be32 cd_NextCD; /* linked list of drivers to config */
108+
__be32 cd_Unused[4]; /* for whatever the driver wants */
109109
} __packed;
110110

111111
#define ZORRO_NUM_AUTO 16

0 commit comments

Comments
 (0)