1#ifndef FWH_LOCK_H
2#define FWH_LOCK_H
3
4
5enum fwh_lock_state {
6 FWH_UNLOCKED = 0,
7 FWH_DENY_WRITE = 1,
8 FWH_IMMUTABLE = 2,
9 FWH_DENY_READ = 4,
10};
11
12struct fwh_xxlock_thunk {
13 enum fwh_lock_state val;
14 flstate_t state;
15};
16
17
18#define FWH_XXLOCK_ONEBLOCK_LOCK ((struct fwh_xxlock_thunk){ FWH_DENY_WRITE, FL_LOCKING})
19#define FWH_XXLOCK_ONEBLOCK_UNLOCK ((struct fwh_xxlock_thunk){ FWH_UNLOCKED, FL_UNLOCKING})
20
21
22
23
24
25
26
27
28static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
29 unsigned long adr, int len, void *thunk)
30{
31 struct cfi_private *cfi = map->fldrv_priv;
32 struct fwh_xxlock_thunk *xxlt = (struct fwh_xxlock_thunk *)thunk;
33 int ret;
34
35
36 if (chip->start < 0x400000) {
37 DEBUG( MTD_DEBUG_LEVEL3,
38 "MTD %s(): chip->start: %lx wanted >= 0x400000\n",
39 __func__, chip->start );
40 return -EIO;
41 }
42
43
44
45
46
47
48
49
50
51
52
53 adr = (adr & ~0xffffUL) | 0x2;
54 adr += chip->start - 0x400000;
55
56
57
58
59
60
61 spin_lock(chip->mutex);
62 ret = get_chip(map, chip, adr, FL_LOCKING);
63 if (ret) {
64 spin_unlock(chip->mutex);
65 return ret;
66 }
67
68 chip->oldstate = chip->state;
69 chip->state = xxlt->state;
70 map_write(map, CMD(xxlt->val), adr);
71
72
73 chip->state = chip->oldstate;
74 put_chip(map, chip, adr);
75 spin_unlock(chip->mutex);
76 return 0;
77}
78
79
80static int fwh_lock_varsize(struct mtd_info *mtd, loff_t ofs, uint64_t len)
81{
82 int ret;
83
84 ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len,
85 (void *)&FWH_XXLOCK_ONEBLOCK_LOCK);
86
87 return ret;
88}
89
90
91static int fwh_unlock_varsize(struct mtd_info *mtd, loff_t ofs, uint64_t len)
92{
93 int ret;
94
95 ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len,
96 (void *)&FWH_XXLOCK_ONEBLOCK_UNLOCK);
97
98 return ret;
99}
100
101static void fixup_use_fwh_lock(struct mtd_info *mtd, void *param)
102{
103 printk(KERN_NOTICE "using fwh lock/unlock method\n");
104
105 mtd->lock = fwh_lock_varsize;
106 mtd->unlock = fwh_unlock_varsize;
107}
108#endif
109