Print this page
10567 lofi should support basic EFI ioctl()s

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/lofi.c
          +++ new/usr/src/uts/common/io/lofi.c
↓ open down ↓ 160 lines elided ↑ open up ↑
 161  161  #include <sys/zmod.h>
 162  162  #include <sys/id_space.h>
 163  163  #include <sys/mkdev.h>
 164  164  #include <sys/crypto/common.h>
 165  165  #include <sys/crypto/api.h>
 166  166  #include <sys/rctl.h>
 167  167  #include <sys/vtoc.h>
 168  168  #include <sys/scsi/scsi.h>      /* for DTYPE_DIRECT */
 169  169  #include <sys/scsi/impl/uscsi.h>
 170  170  #include <sys/sysevent/dev.h>
      171 +#include <sys/efi_partition.h>
      172 +#include <sys/note.h>
 171  173  #include <LzmaDec.h>
 172  174  
 173  175  #define NBLOCKS_PROP_NAME       "Nblocks"
 174  176  #define SIZE_PROP_NAME          "Size"
 175  177  #define ZONE_PROP_NAME          "zone"
 176  178  
 177  179  #define SETUP_C_DATA(cd, buf, len)              \
 178  180          (cd).cd_format = CRYPTO_DATA_RAW;       \
 179  181          (cd).cd_offset = 0;                     \
 180  182          (cd).cd_miscdata = NULL;                \
↓ open down ↓ 1553 lines elided ↑ open up ↑
1734 1736          if (lsp->ls_kstat) {
1735 1737                  mutex_enter(lsp->ls_kstat->ks_lock);
1736 1738                  kstat_waitq_enter(KSTAT_IO_PTR(lsp->ls_kstat));
1737 1739                  mutex_exit(lsp->ls_kstat->ks_lock);
1738 1740          }
1739 1741          bp->b_private = (void *)(uintptr_t)p_lba;       /* partition start */
1740 1742          (void) taskq_dispatch(lsp->ls_taskq, lofi_strategy_task, bp, KM_SLEEP);
1741 1743          return (0);
1742 1744  }
1743 1745  
1744      -/*ARGSUSED2*/
1745 1746  static int
1746 1747  lofi_read(dev_t dev, struct uio *uio, struct cred *credp)
1747 1748  {
     1749 +        _NOTE(ARGUNUSED(credp));
     1750 +
1748 1751          if (getminor(dev) == 0)
1749 1752                  return (EINVAL);
1750 1753          UIO_CHECK(uio);
1751 1754          return (physio(lofi_strategy, NULL, dev, B_READ, minphys, uio));
1752 1755  }
1753 1756  
1754      -/*ARGSUSED2*/
1755 1757  static int
1756 1758  lofi_write(dev_t dev, struct uio *uio, struct cred *credp)
1757 1759  {
     1760 +        _NOTE(ARGUNUSED(credp));
     1761 +
1758 1762          if (getminor(dev) == 0)
1759 1763                  return (EINVAL);
1760 1764          UIO_CHECK(uio);
1761 1765          return (physio(lofi_strategy, NULL, dev, B_WRITE, minphys, uio));
1762 1766  }
1763 1767  
     1768 +static int
     1769 +lofi_urw(struct lofi_state *lsp, uint16_t fmode, diskaddr_t off, size_t size,
     1770 +    intptr_t arg, int flag, cred_t *credp)
     1771 +{
     1772 +        struct uio uio;
     1773 +        iovec_t iov;
     1774 +
     1775 +        /*
     1776 +         * 1024 * 1024 apes cmlb_tg_max_efi_xfer as a reasonable max.
     1777 +         */
     1778 +        if (size == 0 || size > 1024 * 1024 ||
     1779 +            (size % (1 << lsp->ls_lbshift)) != 0)
     1780 +                return (EINVAL);
     1781 +
     1782 +        iov.iov_base = (void *)arg;
     1783 +        iov.iov_len = size;
     1784 +        uio.uio_iov = &iov;
     1785 +        uio.uio_iovcnt = 1;
     1786 +        uio.uio_loffset = off;
     1787 +        uio.uio_segflg = (flag & FKIOCTL) ? UIO_SYSSPACE : UIO_USERSPACE;
     1788 +        uio.uio_llimit = MAXOFFSET_T;
     1789 +        uio.uio_resid = size;
     1790 +        uio.uio_fmode = fmode;
     1791 +        uio.uio_extflg = 0;
     1792 +
     1793 +        return (fmode == FREAD ?
     1794 +            lofi_read(lsp->ls_dev, &uio, credp) :
     1795 +            lofi_write(lsp->ls_dev, &uio, credp));
     1796 +}
     1797 +
1764 1798  /*ARGSUSED2*/
1765 1799  static int
1766 1800  lofi_aread(dev_t dev, struct aio_req *aio, struct cred *credp)
1767 1801  {
1768 1802          if (getminor(dev) == 0)
1769 1803                  return (EINVAL);
1770 1804          UIO_CHECK(aio->aio_uio);
1771 1805          return (aphysio(lofi_strategy, anocancel, dev, B_READ, minphys, aio));
1772 1806  }
1773 1807  
↓ open down ↓ 1404 lines elided ↑ open up ↑
3178 3212                  return (0);
3179 3213          }
3180 3214  err:
3181 3215          return (rval);
3182 3216  }
3183 3217  
3184 3218  static int
3185 3219  lofi_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *credp,
3186 3220      int *rvalp)
3187 3221  {
3188      -        int     error;
     3222 +        int error;
3189 3223          enum dkio_state dkstate;
3190 3224          struct lofi_state *lsp;
3191      -        int     id;
     3225 +        dk_efi_t user_efi;
     3226 +        int id;
3192 3227  
3193 3228          id = LOFI_MINOR2ID(getminor(dev));
3194 3229  
3195 3230          /* lofi ioctls only apply to the master device */
3196 3231          if (id == 0) {
3197 3232                  struct lofi_ioctl *lip = (struct lofi_ioctl *)arg;
3198 3233  
3199 3234                  /*
3200 3235                   * the query command only need read-access - i.e., normal
3201 3236                   * users are allowed to do those on the ctl device as
↓ open down ↓ 229 lines elided ↑ open up ↑
3431 3466                          break;
3432 3467                  default:
3433 3468                          return (EFAULT);
3434 3469                  }
3435 3470  #else
3436 3471                  if (ddi_copyout(&uscmd, (void *)arg, sizeof (uscmd), flag) != 0)
3437 3472                          return (EFAULT);
3438 3473  #endif  /* _MULTI_DATAMODEL */
3439 3474                  return (0);
3440 3475          }
     3476 +
     3477 +        case DKIOCGMBOOT:
     3478 +                return (lofi_urw(lsp, FREAD, 0, 1 << lsp->ls_lbshift,
     3479 +                    arg, flag, credp));
     3480 +
     3481 +        case DKIOCSMBOOT:
     3482 +                return (lofi_urw(lsp, FWRITE, 0, 1 << lsp->ls_lbshift,
     3483 +                    arg, flag, credp));
     3484 +
     3485 +        case DKIOCGETEFI:
     3486 +                if (ddi_copyin((void *)arg, &user_efi,
     3487 +                    sizeof (dk_efi_t), flag) != 0)
     3488 +                        return (EFAULT);
     3489 +
     3490 +                return (lofi_urw(lsp, FREAD,
     3491 +                    user_efi.dki_lba * (1 << lsp->ls_lbshift),
     3492 +                    user_efi.dki_length, (intptr_t)user_efi.dki_data,
     3493 +                    flag, credp));
     3494 +
     3495 +        case DKIOCSETEFI:
     3496 +                if (ddi_copyin((void *)arg, &user_efi,
     3497 +                    sizeof (dk_efi_t), flag) != 0)
     3498 +                        return (EFAULT);
     3499 +
     3500 +                return (lofi_urw(lsp, FWRITE,
     3501 +                    user_efi.dki_lba * (1 << lsp->ls_lbshift),
     3502 +                    user_efi.dki_length, (intptr_t)user_efi.dki_data,
     3503 +                    flag, credp));
     3504 +
3441 3505          default:
3442 3506  #ifdef DEBUG
3443 3507                  cmn_err(CE_WARN, "lofi_ioctl: %d is not implemented\n", cmd);
3444 3508  #endif  /* DEBUG */
3445 3509                  return (ENOTTY);
3446 3510          }
3447 3511  }
3448 3512  
3449 3513  static int
3450 3514  lofi_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags,
↓ open down ↓ 143 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX