Commit Graph

123 Commits

Author SHA1 Message Date
Viresh Kumar
fbab2abc79 [i2c] Allow zero-length requests
Commands like SMBUS Quick don't require a buffer for the request and are
called as zero-length requests. The specification allows such requests
under the VIRTIO_I2C_F_ZERO_LENGTH_REQUEST feature, which is mandatory
to be implemented by the devices now.

Add support for zero-length requests.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-22 09:55:37 +05:30
Viresh Kumar
3f53229bbb
Merge pull request #62 from vireshk/i2c/add-tests
I2c/add tests
2021-11-18 05:44:20 +05:30
Viresh Kumar
5af15e89bf [i2c] Add tests to validate data
Add tests to validate the data processed by rdwr() and smbus(). The
coverage score went up significantly as a result of all recent tests.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-17 08:57:28 +05:30
Viresh Kumar
97e58e8201 [i2c] Add more failure tests
Add more failure tests and check that the return error matches the
expected error value.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-17 08:57:28 +05:30
Viresh Kumar
426050a877 [i2c] Use I2C_M_RD instead of magic number 1
Use I2C_M_RD for flags instead of open coding it with magic number.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-17 08:57:28 +05:30
Viresh Kumar
85b5fe3185
Merge pull request #41 from vireshk/unsafe-block
i2c: Unsafe block
2021-11-17 05:45:09 +05:30
Viresh Kumar
d986c472e4
Merge branch 'main' into unsafe-block 2021-11-16 20:16:29 +05:30
Viresh Kumar
18bca898b7
Merge pull request #50 from rust-vmm/dependabot/cargo/vm-memory-0.7.0
build(deps): bump vm-memory from 0.6.0 to 0.7.0
2021-11-16 20:13:59 +05:30
Viresh Kumar
dcf62eb897
Merge branch 'main' into dependabot/cargo/vm-memory-0.7.0 2021-11-16 19:46:12 +05:30
Alex Bennée
ec488bd497
Merge pull request #61 from rust-vmm/dependabot/cargo/proc-macro2-1.0.32
build(deps): bump proc-macro2 from 1.0.30 to 1.0.32
2021-11-16 14:16:04 +00:00
Viresh Kumar
b4e47f4994 [i2c] Send data for I2C_SMBUS_BYTE command
The data needs to be sent for I2C_SMBUS_BYTE command and we need to make
sure we don't access the same for I2C_SMBUS_QUICK command after the
command is processed.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-16 16:49:17 +05:30
Viresh Kumar
473e45ee0f [i2c] Reorganize SmbusMsg::new()
Reorganize SmbusMsg::new() to return Result<> from the match block
itself.

Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-16 15:44:02 +05:30
Viresh Kumar
00bb1ebdfa [i2c] Improve unsafe blocks
Pointer access is inherently unsafe in Rust, change the layout of
structures to avoid using that.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-16 15:44:02 +05:30
Viresh Kumar
faa240df95
Merge branch 'main' into dependabot/cargo/proc-macro2-1.0.32 2021-11-15 20:42:48 +05:30
dependabot[bot]
bcde6e7c4d
build(deps): bump proc-macro2 from 1.0.30 to 1.0.32
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.30 to 1.0.32.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.30...1.0.32)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: indirect
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-15 12:27:47 +00:00
Viresh Kumar
3f1440a060
Merge branch 'main' into dependabot/cargo/vm-memory-0.7.0 2021-11-15 17:57:06 +05:30
Viresh Kumar
4553e265b6
Merge pull request #59 from rust-vmm/dependabot/cargo/libc-0.2.107
build(deps): bump libc from 0.2.105 to 0.2.107
2021-11-15 17:56:50 +05:30
Viresh Kumar
bc90ff2b08 [i2c] Fix build issues with bump vm-memory 0.7.0
Build was failing with update to 0.7.0 for vm-memory, fix them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-15 16:48:59 +05:30
dependabot[bot]
fab448bc99 build(deps): bump vm-memory from 0.6.0 to 0.7.0
Bumps [vm-memory](https://github.com/rust-vmm/vm-memory) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/rust-vmm/vm-memory/releases)
- [Changelog](https://github.com/rust-vmm/vm-memory/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-vmm/vm-memory/compare/v0.6.0...v0.7.0)

---
updated-dependencies:
- dependency-name: vm-memory
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-15 16:36:09 +05:30
Viresh Kumar
1d9e6c3602
Merge branch 'main' into dependabot/cargo/libc-0.2.107 2021-11-15 16:32:05 +05:30
Viresh Kumar
078f2f0bde
Merge pull request #58 from rust-vmm/dependabot/submodules/rust-vmm-ci-aee82cf
build(deps): bump rust-vmm-ci from `b037be3` to `aee82cf`
2021-11-15 16:31:53 +05:30
Viresh Kumar
638f25d7d1
Merge branch 'main' into dependabot/cargo/libc-0.2.107 2021-11-15 15:58:28 +05:30
Viresh Kumar
5ea0aa732f
Merge branch 'main' into dependabot/submodules/rust-vmm-ci-aee82cf 2021-11-15 15:58:24 +05:30
Viresh Kumar
3b1faa7275
Merge pull request #47 from vireshk/i2c/hashmap
[i2c] Use hashmap for device_map
2021-11-15 15:50:42 +05:30
Viresh Kumar
ad48329bc2
Merge branch 'main' into i2c/hashmap 2021-11-11 06:57:15 +05:30
Alex Bennée
ab810f51c0
Merge pull request #60 from vireshk/i2c/unused-mem
i2c: Remove unused `mem` field
2021-11-10 10:22:59 +00:00
Viresh Kumar
aa6a2450d5
Merge branch 'main' into i2c/unused-mem 2021-11-09 13:34:38 +05:30
Alex Bennée
31ec556560 README.md: document aim for separating concerns
While there may be some work to do on the testing framework to make
proper use of vm-virtio we should at least document the desire for
modularity.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2021-11-09 10:02:30 +02:00
Alex Bennée
cf18bc7409 CODEOWNERS: add myself an Mathieu to aid review
This will help with review of incoming stuff although we may need to
lean on the wider community when it comes to more in depth Rust stuff.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
2021-11-09 10:02:30 +02:00
dependabot[bot]
b0e52d56e6
build(deps): bump libc from 0.2.105 to 0.2.107
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.105 to 0.2.107.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.105...0.2.107)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-08 04:09:12 +00:00
dependabot[bot]
5402b6d5e5
build(deps): bump rust-vmm-ci from b037be3 to aee82cf
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `b037be3` to `aee82cf`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](b037be3396...aee82cf0a4)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-08 04:08:17 +00:00
Viresh Kumar
91778ed009 i2c: Remove unused mem field
Removed the unused `mem` field.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-08 09:30:22 +05:30
Viresh Kumar
bd84352b36
Merge branch 'main' into i2c/hashmap 2021-11-02 16:30:30 +05:30
Jiang Liu
f7c632020b
Merge pull request #53 from vireshk/i2c/fix-funcs-helper
I2c/fix funcs helper
2021-11-02 18:46:17 +08:00
Viresh Kumar
f1672f2016
Merge branch 'main' into i2c/hashmap 2021-11-02 10:22:06 +05:30
Viresh Kumar
53283d78d7
Merge branch 'main' into i2c/fix-funcs-helper 2021-11-02 10:21:26 +05:30
dependabot[bot]
9cb776f199 build(deps): bump rust-vmm-ci from 7931077 to b037be3
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `7931077` to `b037be3`.
- [Release notes](https://github.com/rust-vmm/rust-vmm-ci/releases)
- [Commits](7931077cdc...b037be3396)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-01 10:45:12 +02:00
Viresh Kumar
ef52e69bff [i2c] Remove the "func" argument from funcs()
The funcs() implementation is buggy as it doesn't take "func" by
reference and it only defaults to SMBUS and hence the I2C protocol is
never chosen as a function.

Since the value of "func" is never required to be set by the caller, it
shouldn't be passed as argument in the first place. Make the function
return Result<u64> instead.

The test test_funcs() was failing before this change and passes after
it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-28 11:32:17 +05:30
Viresh Kumar
e28f3af61b [i2c] Add a test to check the working of funcs()
The funcs() implementation is buggy as it doesn't take "func" by
reference and it only defaults to SMBUS and hence the I2C protocol is
never chosen as a function.

This test fails currently.

Suggested-by: Andreea Florescu <fandree@amazon.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-27 14:18:14 +05:30
Viresh Kumar
fedfb0b82e [i2c] Use hashmap for device_map
Use hashmap instead of an array of size 1 << 7, as only a few entries of
the array are used here.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-27 14:14:27 +05:30
Jiang Liu
91d84b481e
Merge pull request #48 from vireshk/i2c/errors
I2c/errors
2021-10-27 16:03:39 +08:00
Viresh Kumar
79a84972f5 [i2c] Update coverage score and Cargo.lock
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-27 12:38:09 +05:30
Viresh Kumar
16a028f35d [i2c] Avoid using expect()
Be consistent with the use of expect() and unwrap() and use only one of
them, if required. Also add a comment on why usage of unwrap() is safe
in main().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-27 12:36:57 +05:30
Viresh Kumar
d021564ba3 [i2c] Improve tests by matching error number
Improve tests by matching the expected error number.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-26 16:28:38 +05:30
Viresh Kumar
ca5e7e02dd [i2c] Unify Error types
The crate uses lots of ways to report errors, unify them and use a
separate Error enum type for each file. This will also help us improve
the test code later on.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-26 16:28:38 +05:30
Viresh Kumar
e62e27aead [i2c] Use log crate helpers instead of println!()
Use info! and warn! instead of println!.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-26 15:07:17 +05:30
Viresh Kumar
60d29f98f4
Merge pull request #52 from andreeaflorescu/testing_i2c
update I2cAdapter to allow setting a mock device
2021-10-26 13:07:01 +05:30
Andreea Florescu
57b96aa3a3 update I2cAdapter to allow setting a mock device
Before the constructor of this function was opening the device
corresponding to the passed path. This did not allow for properly
mocking the device functionality. Now the device is passed as a
parameter instead, which allows us to tweak what the device returns for
ioctl calls, and we can thus test multiple scenarios.

Signed-off-by: Andreea Florescu <fandree@amazon.com>
2021-10-26 10:27:58 +03:00
Vincent Whitchurch
27a19cfe67 [i2c] Copy from correct result buffer
Copy the read data from the correct result buffer, otherwise
this results in incorrect data and/or memory overwrites in the
guest memory.

Signed-off-by: Vincent Whitchurch <vincent@whitchurch.se>
2021-10-26 08:54:58 +03:00
Viresh Kumar
6e585e9192
Merge pull request #46 from rust-vmm/dependabot/cargo/proc-macro2-1.0.30
build(deps): bump proc-macro2 from 1.0.29 to 1.0.30
2021-10-18 12:32:30 +05:30