fwh_lock.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef FWH_LOCK_H
  2. #define FWH_LOCK_H
  3. enum fwh_lock_state {
  4. FWH_UNLOCKED = 0,
  5. FWH_DENY_WRITE = 1,
  6. FWH_IMMUTABLE = 2,
  7. FWH_DENY_READ = 4,
  8. };
  9. struct fwh_xxlock_thunk {
  10. enum fwh_lock_state val;
  11. flstate_t state;
  12. };
  13. #define FWH_XXLOCK_ONEBLOCK_LOCK ((struct fwh_xxlock_thunk){ FWH_DENY_WRITE, FL_LOCKING})
  14. #define FWH_XXLOCK_ONEBLOCK_UNLOCK ((struct fwh_xxlock_thunk){ FWH_UNLOCKED, FL_UNLOCKING})
  15. /*
  16. * This locking/unlock is specific to firmware hub parts. Only one
  17. * is known that supports the Intel command set. Firmware
  18. * hub parts cannot be interleaved as they are on the LPC bus
  19. * so this code has not been tested with interleaved chips,
  20. * and will likely fail in that context.
  21. */
  22. static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
  23. unsigned long adr, int len, void *thunk)
  24. {
  25. struct cfi_private *cfi = map->fldrv_priv;
  26. struct fwh_xxlock_thunk *xxlt = (struct fwh_xxlock_thunk *)thunk;
  27. int ret;
  28. /* Refuse the operation if the we cannot look behind the chip */
  29. if (chip->start < 0x400000) {
  30. pr_debug( "MTD %s(): chip->start: %lx wanted >= 0x400000\n",
  31. __func__, chip->start );
  32. return -EIO;
  33. }
  34. /*
  35. * lock block registers:
  36. * - on 64k boundariesand
  37. * - bit 1 set high
  38. * - block lock registers are 4MiB lower - overflow subtract (danger)
  39. *
  40. * The address manipulation is first done on the logical address
  41. * which is 0 at the start of the chip, and then the offset of
  42. * the individual chip is addted to it. Any other order a weird
  43. * map offset could cause problems.
  44. */
  45. adr = (adr & ~0xffffUL) | 0x2;
  46. adr += chip->start - 0x400000;
  47. /*
  48. * This is easy because these are writes to registers and not writes
  49. * to flash memory - that means that we don't have to check status
  50. * and timeout.
  51. */
  52. mutex_lock(&chip->mutex);
  53. ret = get_chip(map, chip, adr, FL_LOCKING);
  54. if (ret) {
  55. mutex_unlock(&chip->mutex);
  56. return ret;
  57. }
  58. chip->oldstate = chip->state;
  59. chip->state = xxlt->state;
  60. map_write(map, CMD(xxlt->val), adr);
  61. /* Done and happy. */
  62. chip->state = chip->oldstate;
  63. put_chip(map, chip, adr);
  64. mutex_unlock(&chip->mutex);
  65. return 0;
  66. }
  67. static int fwh_lock_varsize(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  68. {
  69. int ret;
  70. ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len,
  71. (void *)&FWH_XXLOCK_ONEBLOCK_LOCK);
  72. return ret;
  73. }
  74. static int fwh_unlock_varsize(struct mtd_info *mtd, loff_t ofs, uint64_t len)
  75. {
  76. int ret;
  77. ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len,
  78. (void *)&FWH_XXLOCK_ONEBLOCK_UNLOCK);
  79. return ret;
  80. }
  81. static void fixup_use_fwh_lock(struct mtd_info *mtd)
  82. {
  83. printk(KERN_NOTICE "using fwh lock/unlock method\n");
  84. /* Setup for the chips with the fwh lock method */
  85. mtd->_lock = fwh_lock_varsize;
  86. mtd->_unlock = fwh_unlock_varsize;
  87. }
  88. #endif /* FWH_LOCK_H */